Hello all, i'm new in scripting, with some friends we have a public DayZ server and we would like add some commands for admins, i found this script on internet:
but it doesn't woork completly.
we've have notice on testing that in the execution of any command, thake the following as example:
case "spawn": {
if(count != 2) { SendMessageToPlayer(player, "/spawn [object]"); return; }
GetGame().CreateObject(tokens[1], player.GetPosition(), false, true );
SendMessageToPlayer(player, "[ObjectSpawn] Object spawned: " + tokens[1]);
break;
}
the variable player is not set properly, cause is not the player that write the command, but it's always the first player that joined the server
Do you guys think that the problem is the names of players?
Should i change in all this code instead using names should i use IDs?
bool IsPlayer(string name) {
PlayerBase p;
array<Man> players = new array<Man>; GetGame().GetPlayers(players);
for ( int i = 0; i < players.Count(); ++i ) {
p = players.Get(i);
if(p.GetIdentity().GetName() == name) return true;
}
return false;
}
PlayerBase GetPlayer(string name) {
PlayerBase p;
array<Man> players = new array<Man>; GetGame().GetPlayers(players);
for ( int i = 0; i < players.Count(); ++i ) {
p = players.Get(i);
if(p.GetIdentity().GetName() == name) return p;
}
return NULL;
}
override void OnEvent(EventType eventTypeId, Param params) {
super.OnEvent(eventTypeId,params);
int i;
PlayerBase player, temp_player;
array<Man> players = new array<Man>; GetGame().GetPlayers(players);
if(eventTypeId != ChatMessageEventTypeID) return; // Is chat message
ChatMessageEventParams chat_params = ChatMessageEventParams.Cast( params );
if(chat_params.param1 != 0 || chat_params.param2 == "") return;
player = GetPlayer(chat_params.param2);
if(player == NULL) return;
if(verify_admins && !IsPlayerAnAdmin(player)) { GetGame().AdminLog("[ADMCMD] (Unauthorized) " + player.GetIdentity().GetName() +" ("+player.GetIdentity().GetPlainId()+", "+player.GetIdentity().GetId()+") tried to execute "+ chat_params.param3); return; }
string message = chat_params.param3, prefix, param0, command;
TStringArray tokens = new TStringArray;
message.Replace("` ", "&SPCESC!"); //Escape spaces before splitting
message.Split(" ", tokens); int count = tokens.Count();
for ( i = 0; i < count; ++i ) {
message = tokens[i];
message.Replace("&SPCESC!", " "); //.Replace doesn't work directly on TStringArray elements for some reason :(
tokens[i] = message;
}