Author Topic: Weapon save script  (Read 1560 times)

0 Members and 1 Guest are viewing this topic.

Offline Zabijaka

  • Soldier
  • **
  • Posts: 201
  • Soldat Fan, Hitman Fan
Weapon save script
« on: August 13, 2009, 04:09:07 pm »
I have problem with weapon save script on My RS server.
This is the script:
Code: [Select]
type
wep=record
Primary,Secondary:byte;
end;

var
weps: array [1..12] of Wep;

Function AlphaAPlayers:Byte;
var
i:byte;
begin
Result:=0;
For i:=1 to 12 do
begin
if GetPlayerStat(i, 'Active') then if GetPlayerStat(i, 'Alive') then if GetPlayerStat(i, 'Team') = 1 then Result:=Result+1;
end;
end;

Function BravoAPlayers:byte;
var
i:byte;
begin
Result:=0;
For i:=1 to 12 do
begin
if GetPlayerStat(i, 'Active') then if GetPlayerStat(i, 'Alive') then if GetPlayerStat(i, 'Team') = 2 then Result:=Result+1;
end;
end;

Function OneTeamAlive:Boolean;
begin
If (BravoAPlayers>0) and (AlphaAPlayers=0) or (BravoAPlayers=0) and (AlphaAPlayers>0) then result:=True
else
Result:=False;
end;

function players:boolean;
var
i,p:byte;
begin
P:=0;
for i:=1 to 12 do
begin
if (GetPlayerStat(i,'Active')= True) and (GetPlayerStat(i,'Team')<>5) then begin
if Not GetPlayerStat(i,'Alive') then p:=p+1;
end;
end;
if AlphaPlayers+BravoPlayers=P then Result:=True else Result:=False;
end;

procedure OnJoinGame(Id:Byte;Team:Byte);
begin
Weps[id].Primary:=66;
Weps[id].Secondary:=66;
end;

procedure OnPlayerRespawn(ID: Byte);
begin
If not Weps[ID].Primary=66 then ForceWeapon(ID, Weps[ID].Primary, Weps[Id].Secondary, 0);
end;

Procedure Destroyall;
var
i:byte;
begin
for i:=1 to 128 do
If GetObjectStat(i, 'Active') then if GetObjectStat(i,'Style')<>27 then KillObject(i);
end;

Procedure SaveWeps;
var
i:byte;
begin
for i:=1 to 12 do
If GetplayerStat(i, 'Active') then If GetPlayerStat(i,'Alive') then begin
Weps[i].Primary:=GetPlayerStat(i,'Primary');
Weps[i].Secondary:=GetPlayerStat(i,'Secondary');
end else begin
Weps[i].Primary:=66;
Weps[i].Secondary:=66;
end;
end;



procedure OnPlayerKill(Killer, Victim: byte;Weapon: string);
begin
If OneTeamAlive then SaveWeps;
end;

procedure AppOnIdle(Ticks: integer);
begin
If Players then Destroyall;
end;

Why script dosen't work ?
« Last Edit: August 13, 2009, 04:21:36 pm by Zabijaka »

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: Weapon save script
« Reply #1 on: August 13, 2009, 04:15:32 pm »
Weps array is not declared, unknown procedure OneTeamAlive
« Last Edit: August 13, 2009, 04:17:04 pm by tk »

Offline Zabijaka

  • Soldier
  • **
  • Posts: 201
  • Soldat Fan, Hitman Fan
Re: Weapon save script
« Reply #2 on: August 13, 2009, 04:22:14 pm »
sorry i paste incomplite code, now is full.

Offline ~Niko~

  • Rainbow Warrior
  • *****
  • Posts: 2410
Re: Weapon save script
« Reply #3 on: August 13, 2009, 04:33:55 pm »
You should definitively use tabulations... and a cleaner way to write everything.

What should the script do anyways?

Offline Zabijaka

  • Soldier
  • **
  • Posts: 201
  • Soldat Fan, Hitman Fan
Re: Weapon save script
« Reply #4 on: August 13, 2009, 04:37:24 pm »
Script should save player weapon (if player survive) and give this weapon after respawn in next round (forceweapon)

Offline ~Niko~

  • Rainbow Warrior
  • *****
  • Posts: 2410
Re: Weapon save script
« Reply #5 on: August 13, 2009, 04:55:45 pm »
then why make it so hard? ill find an easier way.

Offline Zabijaka

  • Soldier
  • **
  • Posts: 201
  • Soldat Fan, Hitman Fan
Re: Weapon save script
« Reply #6 on: August 13, 2009, 05:03:28 pm »
So?

Offline ~Niko~

  • Rainbow Warrior
  • *****
  • Posts: 2410
Re: Weapon save script
« Reply #7 on: August 13, 2009, 05:36:32 pm »
get in #soldat.devs and we'll try to do this.

Offline Zabijaka

  • Soldier
  • **
  • Posts: 201
  • Soldat Fan, Hitman Fan
Re: Weapon save script
« Reply #8 on: August 14, 2009, 01:16:48 am »
I post script here and maybe here somebody help me?

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Weapon save script
« Reply #9 on: August 14, 2009, 04:20:26 am »
I post script here and maybe here somebody help me?
Niko is offering to rewrite the script for you.
If I were you I'd be really happy, because if we'd really help you the first advice would probably be to 'start over' (at least that'll be my advice). I don't want to be offensive in any way, but imho you're not ready for scripting on this level yet, zabij.

So if you want this to work, let that nice guy Niko do it. If you want to learn how to script, start with something less complicated (something that doesn't involve the end of around in survival for example).
Come join: EliteCTF
Listen to: My Music

Offline ~Niko~

  • Rainbow Warrior
  • *****
  • Posts: 2410
Re: Weapon save script
« Reply #10 on: August 14, 2009, 08:46:40 am »
I post script here and maybe here somebody help me?
Niko is offering to rewrite the script for you.
What? No, I am not, but I tried it, failed. I wanted him to get in IRC to try to make this script work doing a few tests.

What I did was to make his script readable, because he didn't use tabulations/space things a bit more. He was using a good method to do it:

Code: [Select]
type
wep = Record
Primary, Secondary: Byte;
end;

var
weps: array [1..16] of Wep;

function AlphaAPlayers: Byte;
var i: Byte;
begin
Result := 0;
For i := 1 to 16 do begin
if GetPlayerStat(i, 'Active') then if GetPlayerStat(i, 'Alive') then if GetPlayerStat(i, 'Team')  =  1 then Result := Result + 1;
end;
end;

function BravoAPlayers:Byte;
var
i:Byte;
begin
Result := 0;
For i := 1 to 12 do
begin
if GetPlayerStat(i, 'Active') then if GetPlayerStat(i, 'Alive') then if GetPlayerStat(i, 'Team')  =  2 then Result := Result+1;
end;
end;

Function OneTeamAlive:Boolean;
begin
if (BravoAPlayers>0) and (AlphaAPlayers = 0) or (BravoAPlayers = 0) and (AlphaAPlayers>0) then result := True
else
Result := False;
end;

function players: Boolean;
var i, p: Byte;
begin
p := 0;
for i := 1 to 12 do begin
if (GetPlayerStat(i, 'Active') =  True) and (GetPlayerStat(i, 'Team') <> 5) then begin
if not GetPlayerStat(i, 'Alive') then p := p + 1;
end;
end;
if AlphaPlayers + BravoPlayers = p then Result := True else Result := False;
end;

procedure OnJoinTeam(ID, Team: Byte);
begin
Weps[id].Primary := 66;
Weps[id].Secondary := 66;
end;

procedure OnPlayerRespawn(ID: Byte);
begin
if Weps[ID].Primary <> 66 then begin
ForceWeapon(ID, Weps[ID].Primary, Weps[ID].Secondary, 0);
end;
end;

procedure Destroyall;
var i: Byte;
begin
for i := 1 to 128 do
if GetObjectStat(i, 'Active') then if GetObjectStat(i, 'Style') <> 27 then KillObject(i);
end;

procedure SaveWeps;
var i: Byte;
begin
for i := 1 to 12 do if GetplayerStat(i, 'Active') then if GetPlayerStat(i, 'Alive') then begin
Weps[i].Primary := GetPlayerStat(i, 'Primary');
Weps[i].Secondary := GetPlayerStat(i, 'Secondary');
end else begin
Weps[i].Primary := 66;
Weps[i].Secondary := 66;
end;
end;

procedure OnPlayerKill(Killer, Victim: Byte; Weapon: string);
begin
if OneTeamAlive then SaveWeps;
end;

procedure AppOnIdle(Ticks: integer);
begin
if Players then Destroyall;
end;

I edited the code a bit, but nothing major.
« Last Edit: August 14, 2009, 08:49:56 am by ~Niko~ »

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: Weapon save script
« Reply #11 on: August 14, 2009, 09:09:05 am »
GetPlayerStat(i, 'Active') = True

GetPlayerStat()'s Result is variant, not boolean, so it's better if you add it, forgot why but it was i think that it sometimes work not if you dont add it.. , good english^^

Offline Serial K!ller

  • Camper
  • ***
  • Posts: 408
    • Soldat Mods Archive
Re: Weapon save script
« Reply #12 on: August 14, 2009, 09:40:17 am »
I think using ForceWeapon() in OnPlayerRespawn() is a no go

Offline ~Niko~

  • Rainbow Warrior
  • *****
  • Posts: 2410
Re: Weapon save script
« Reply #13 on: August 14, 2009, 10:03:25 am »
I think using ForceWeapon() in OnPlayerRespawn() is a no go
Yeah, you should enable an AppOnIdle that checks if the OnPlayerRespawn[id] has been done, and then set the timer to 1 sec, then force it. Plus a checker to know if you already have a primary when you respawn, because if you had an HK, and now you can choose a Barrett, the hk would replace the barrett, right?

Offline -Bendarr-

  • Soldier
  • **
  • Posts: 104
Re: Weapon save script
« Reply #14 on: August 15, 2009, 10:16:47 am »
I'd say you could buy new guns by using whatever gun you already had as a "trade-in"

For example, someone picks an HK which I believe costs 400 on his server, he dies and the enemy takes his gun.

The following round, the enemy could /barrett and because he already had a primary, it would deduct maybe 300 from the cost of the ret. Or if they pick up a ret which costs 800 (if I recall correctly) and you want deagles, it gives you like 300-400 extra cash.

That's what I'd do at least, rather than allowing for people to have a personal arsenal of weapons (owning every gun in the game). For one it wouldn't even make sense, they can't possibly hold that many guns at once.

Or maybe allow for each person to own 2 guns? If you type /barrett and you already bought it and didn't die and lose it (if you bought an aug while holding ret) then it switches to your ret rather than buying one.

Possibilities can go on and on...

Offline ~Niko~

  • Rainbow Warrior
  • *****
  • Posts: 2410
Re: Weapon save script
« Reply #15 on: August 15, 2009, 10:22:00 am »
nah, just give back the cost of the gun to the guy who had the gun at the end of the round, it'd check both primaries and secondaries (because you can have p.e a barrett and an hk) and it'd give back the money that each gun costs, and then, instead of having the same gun, you could buy a different one without having lost the money of your previous buy.

Offline Zabijaka

  • Soldier
  • **
  • Posts: 201
  • Soldat Fan, Hitman Fan
Re: Weapon save script
« Reply #16 on: August 15, 2009, 06:09:47 pm »
nah, just give back the cost of the gun to the guy who had the gun at the end of the round.

Yeah, very nice idea, thx :)