25.01.2011, 18:17
use strtok
Put it near the end of file
This at the start of OnPlayerCommandText
Put it near the end of file
Код:
stock strtok(const string[], &index) { new length = strlen(string); while ((index < length) && (string[index] <= ' ')) { index++; } new offset = index; new result[20]; while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) { result[index - offset] = string[index]; index++; } result[index - offset] = EOS; return result; }
Код:
public OnPlayerCommandText(playerid, cmdtext[]) { new cmd[256]; new tmp[256]; new idx; cmd = strtok(cmdtext,idx); if(strcmp(cmd, "/pvp", true) == 0) { if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "");//If the playerid isn't admin (put the message) tmp = strtok(cmdtext, idx); if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_YELLOW, "USO: /givegun [playerid] [weapon]."); new playerid2; playerid2 = strval(tmp); new tmp2[256]; tmp2 = strtok(cmdtext, idx); new weapid= strval(tmp2); new string[256]; new name[MAX_PLAYER_NAME]; new name2[MAX_PLAYER_NAME]; new name3[MAX_PLAYER_NAME]; GetPlayerName(playerid,name,sizeof(name)); GetPlayerName(playerid2,name2,sizeof(name2)); GetWeaponName(armaid,name3,sizeof(name3)); format(string,sizeof(string),"Admin %s(%d) gave the weapon %s(%d) to player %s(%d).",name,playerid,name3,weapid,name2,playerid2); print(string);//Print to server_log format(string,sizeof(string),"Admin %s(%d) gave you the weapon %s(%d).",name,playerid,name3,weapid); SendClientMessage(playerid2,COLOR_RED,string); format(string,sizeof(string),"You gave %s(%d) the weapon %s(%d).",name2,playerid2,name3,weapid); SendClientMessage(playerid,COLOR_RED,string); GivePlayerWeapon(playerid2,weapid,50000);//Unlimited ammo.(if u dont want it change 50000). return 1; } }