Official Soldat Forums
Server Talk => Scripting Discussions and Help => Topic started by: -Snowy- on January 15, 2008, 07:22:27 am
-
problem fixed :D
what im trying to do here is store the team that a player is on, so that i can put them back onto that team if they try to change using the team changing menu, which is not allowed in my zombie script (currently they are changed to spectator mode when they do this, i want them to go back to the team they were already on)
this isnt my exact code, but its basically what im trying to do
var
slot1team: integer;
slot2team: integer;
slot3team: integer;
slot4team: integer;
slot5team: integer;
slot6team: integer;
slot7team: integer;
slot8team: integer;
slot9team: integer;
slot10team: integer;
slot11team: integer;
slot12team: integer;
slot13team: integer;
slot14team: integer;
slot15team: integer;
slot16team: integer;
slot17team: integer;
slot18team: integer;
slot19team: integer;
slot20team: integer;
slot21team: integer;
slot22team: integer;
slot23team: integer;
slot24team: integer;
slot25team: integer;
slot26team: integer;
slot27team: integer;
slot28team: integer;
slot29team: integer;
slot30team: integer;
slot31team: integer;
slot32team: integer;
procedure OnJoinTeam(ID, Team: byte);
begin
'slot' + inttostr(ID) + 'team' := Team;
end;
so for example when player 1 joins team 2 then it should make slot1team := 2; or if player 5 joins team 0 then it should make slot5team := 0;. only problem is that the server wont run with the line 'slot' + inttostr(ID) + 'team' := Team; and i dont know the proper way to do it. i know i could go through and say if id = 1 then begin slot1team := Team; for every single player but that would just take up time and space.
so basically i need to know how to make a variable name out of a few strings put together then change the variable to the player's team. or if someone knows a way to tell the team that a player was coming from onjointeam that would be just as helpful.
-
Use an array.
var Player: array[1..32] of byte;
-
i had a look around for how to use arrays and this is what i came up with
var
Playerteam: array[1..32] of byte;
procedure OnJoinTeam(ID, Team: byte);
begin
Playerteam[ID] := 'Team';
end;
too bad i have no idea what im doing, because then id be able to see what ive done wrong here, because its not working for me
edit: dw it was the ''s around Team
edit again: another problem, how would i use the number in the array in a command or something, eg when i put them back to the team they were on. i tried
Command('/setteam' + Playerteam[ID] + ' ' + InttoStr(ID));
but the server crashed, what should i do?
edit: my bad again, another technical error, i forget inttostr
-
Use an array.
var Player: array[1..32] of byte;
I agree with Avarax. Almost any time that a person wants to create variable names from other variables, they should really be using an array. There are very, very few circumstances where dynamically-named variables are actually needed
-
Use an array.
var Player: array[1..32] of byte;
I agree with Avarax. Almost any time that a person wants to create variable names from other variables, they should really be using an array. There are very, very few circumstances where dynamically-named variables are actually needed
And anywhere dynamically-named variables are needed, you can just use an ordered map type of data structure, like a dictionary or other, which is exactly how dynamically-named variables are dealt with internally in the languages which use them in the first place. The only difference is you would need to write your own supporting code instead of it being provided as a convenience.
-
Can you turn a string into a variable name with this scripting engine?
just wondering...
btw I like your avatar chris, foxes own all
-
Can you turn a string into a variable name with this scripting engine?
just wondering...
btw I like your avatar chris, foxes own all
No, although I am working on a sort of system that you can do SetVariable('test', 8) and stuff, wrote it up but havn't found the time to get it working yet :P (can't do test := 8 though... must use the functions to access the variables)
-
Can you turn a string into a variable name with this scripting engine?
just wondering...
btw I like your avatar chris, foxes own all
No you can't, and yes, I <3 my avatar :D.
Can you turn a string into a variable name with this scripting engine?
just wondering...
btw I like your avatar chris, foxes own all
No, although I am working on a sort of system that you can do SetVariable('test', 8) and stuff, wrote it up but havn't found the time to get it working yet :P (can't do test := 8 though... must use the functions to access the variables)
type
TVariable = record
name: string
value: variant
end;
variables: array of TVariable;
function find(name: string): integer;
begin
for result := 0 to arrayhigh(variables) do /
if variables[result].name = name then exit;
result := -1;
end;
procedure set(name: string; value: variant);
var
pos: integer;
begin
pos := find(name);
if pos > -1 then
variables[pos].value := value
else begin
setlength(variables, arrayhigh(variables) + 1);
Variables[arrayhigh(variables)].value := value;
Variables[arrayhigh(variables)].name := name;
end;
end;
function get(name: string): variant;
var
pos: integer;
begin
result := 'Not found';
pos := find(name);
if pos > -1 then
result := variables[pos].value;
end;
More or less in theory how to do it, haven't tried it to see if it even works or not. Probably needs some adjustment to use scripting functions, as I'm used to delphi and not the scripting engine.
-
Pretty much exactly how mine works
-
Or, I could just add the SetVar function to the scripting engine, in one line. lolol.
-
Or, I could just add the SetVar function to the scripting engine, in one line. lolol.
please :) (we need that very much)
-
Or, I could just add the SetVar function to the scripting engine, in one line. lolol.
lol i thought i (and others) already suggested that a while ago ^^
Well ill just list a few suggestions going along with the same function:
function GetVariable(Name: string): variant;
procedure SetVariable(Name: string; Value: variant);
procedure DefVariable(Name: string; Datatype: string);
procedure UndefVariable(Name: string);
function IsDefined(Name: string): boolean;
function GetDatatype(Name: string): string;
Don't know whats possible or what isn't but, might as well list em all..