0 Members and 5 Guests are viewing this topic.
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 doCode: [Select]varslot1team: 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.
varslot1team: 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;
varPlayerteam: array[1..32] of byte; procedure OnJoinTeam(ID, Team: byte);beginPlayerteam[ID] := 'Team';end;
Command('/setteam' + Playerteam[ID] + ' ' + InttoStr(ID));
Use an array.var Player: array[1..32] of byte;
Quote from: Avarax on January 15, 2008, 07:33:27 amUse 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
Can you turn a string into a variable name with this scripting engine?just wondering...btw I like your avatar chris, foxes own all
Quote from: Kavukamari on January 15, 2008, 08:16:03 pmCan you turn a string into a variable name with this scripting engine?just wondering...btw I like your avatar chris, foxes own allNo, although I am working on a sort of system that you can do SetVariable('test', and stuff, wrote it up but havn't found the time to get it working yet (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;
Or, I could just add the SetVar function to the scripting engine, in one line. lolol.