Official Soldat Forums

Server Talk => Scripting Discussions and Help => Topic started by: VinceBros on December 08, 2009, 07:45:09 pm

Title: [Solved]Basic problem.
Post by: VinceBros on December 08, 2009, 07:45:09 pm
Hi again guys, lol.

I work badly in a script, and an error has just popped in my face and it seems like i can't fix it.

I'm not so good explaining so i'm just gonna show you the pieces of script.

Huuh... an exemple :

Code: (pascal) [Select]
var
Random : byte;
SomeoneGotId : boolean;
procedure OnPlayerSpeak(ID: Byte; Text: string)
  begin
   if Text = '!getid' then begin
    Random := ID;
    SomeoneGotId := true;
   end;
   if Text = '!giveid' then begin
    Random := 0;
    SomeoneGotId := false;
  end;
 end;

procedure OnLeaveGame(ID, Team: byte;Kicked: boolean);
 begin
  if (SomeoneGotId = true) and (Random = ID) then begin
    Random := 0;
    SomeoneGotId := false;
  end;
 end;

function OnPlayerCommand(ID: Byte; Text: string): boolean;
 begin
  // Test to see who got the Random id
  if Text = '/whogotid' then begin
   WriteConsole(ID, 'Random = ' + IDToName(Random),$FFFF0000);
  end;
end;

Here is the problem. In the other procedures than OnPlayerSpeak, the Random variable is 255 and it displays : Random = Server Admin.

What is the problem ?

Thanks for solving it.

EDIT: FIXED AN ERROR IN THE EXEMPLE
Title: Re: Basic problem.
Post by: Silnikos on December 09, 2009, 01:41:01 am
Here is the problem. In the other procedures than OnPlayerSpeak, the Random variable is 255 and it displays : Random = Server Admin.

What is the problem ?
255 is server admin's ID, if you use this variable for other functions, rename this one so they won't collide?
Title: Re: Basic problem.
Post by: Gizd on December 09, 2009, 09:39:30 am
Try renaming the variable to RandomX(in example..), also you don't need SomeoneGotId, just compare Random with 0.
Title: Re: Basic problem.
Post by: VinceBros on December 09, 2009, 03:13:44 pm
Mmh, you don't see to understand my problem.

The Random Var in OnPlayerSpeak has the value of the ID.
But in the other functions it's the server admin, which should be the ID in OnPlayerSpeak
Title: Re: Basic problem.
Post by: Gizd on December 09, 2009, 11:59:16 pm
Maybe first try and then say I'm wrong?
Title: Re: Basic problem.
Post by: VinceBros on December 10, 2009, 03:48:44 pm
Well my variable name in the script is not Random.
In the exemple, Yes. But i fixed problem :). Thanks anyway.