Author Topic: problem increasing variables value  (Read 752 times)

0 Members and 1 Guest are viewing this topic.

Offline Ether22

  • Major(1)
  • Posts: 1
problem increasing variables value
« on: November 11, 2007, 12:48:37 pm »
Hi, i'm very newb at scripting :P but i want to learn.
I have a zombie server and i want to make a script for it where the players (on bravo team) gain experience from killing zombies.
But i'm stucked at this, i want to make a variable that increases when the player kills:

Quote
procedure OnPlayerKill(Killer, Victim: byte; Weapon: string);
var
experience: integer;
begin
if GetPlayerStat(1,'Team') = 2 then begin
inc(experience,1000);
WriteConsole(0,inttostr(experience),$EE81FAA1);
end;
end;

I wrote the WriteConsole part to know if its working, but everytime i kill someone it says "1000", not 1000, 2000, 3000... I thinks it's because the variable resets to 0. How can i make it to not do that? Thanks!
Sorry for my englis :P
« Last Edit: November 11, 2007, 03:19:08 pm by Ether22 »

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: problem increasing variables value
« Reply #1 on: November 11, 2007, 03:03:04 pm »
It's because you declared the variable in the scope of the procedure. You should declare a global variable for that so it's not reinitialized every time the event is called. Something like this:

Code: [Select]
var experience: array[1..32] of integer;

procedure OnPlayerKill(Killer, Victim: byte; Weapon: string);
begin
  if GetPlayerStat(1,'Team') = 2 then begin
    inc(experience[Killer],1000);
    WriteConsole(0,inttostr(experiencie[Killer]),$EE81FAA1);
  end;
end;

You should also reset the experience to zero in OnJoinGame or OnJoinTeam.
urraka

Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
Re: problem increasing variables value
« Reply #2 on: November 13, 2007, 01:01:48 pm »
Code: [Select]
var experience: array[1..32] of integer;

procedure OnPlayerKill(Killer, Victim: byte; Weapon: string);
begin
 if (GetPlayerStat(Killer,'Team') = 2) and (GetPlayerStat(Victim,'Human') = false) then begin
 inc(experience[Killer],1000);
 WriteConsole(Killer,'Your EXP is now '+inttostr(experience[Killer]),$EE81FAA1);
 end;
end;

I fixed it so it checks if killer is on bravo team instead of player 1 :P

it also checks if the victim is a bot

I'm interested in this script, I might make something where you can only get certain weapons if your EXP is at a certain point (like m79 at 3000 or something)
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."

Offline spkka

  • Camper
  • ***
  • Posts: 469
Re: problem increasing variables value
« Reply #3 on: November 13, 2007, 02:03:58 pm »
Maybe this can help you aswell. I wrote it a few days ago. It simply increases players experience. When its above a certain amount the player levels.

http://forums.soldat.pl/index.php?topic=22007.0

Good luck scripting anyways!