if (strcmp(cmd, "/god", true)==0)
{
new tmp[256], string[256];
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
if(gGod[playerid] == 1){
format(string, sizeof(string), "Godmode of %s is now turned OFF", gName[playerid]);
SendClientMessage(playerid, COLOR_SYSTEM, string);
gGod[playerid] = 0;
SetPlayerHealth(playerid, 100);
} else {
format(string, sizeof(string), "Godmode of %s is now turned ON", gName[playerid]);
SendClientMessage(playerid, COLOR_SYSTEM, string);
gGod[playerid] = 1;
SetPlayerHealth(playerid, 9999999999);
}
return 1;
} else {
if(FindUser(tmp)){
new id = GiveID(tmp);
if(gGod[id] == 1){
format(string, sizeof(string), "Godmode of %s is now turned OFF", gName[id]);
SendClientMessage(playerid, COLOR_SYSTEM, string);
gGod[id] = 0;
SetPlayerHealth(id, 100);
} else {
format(string, sizeof(string), "Godmode of %s is now turned ON", gName[id]);
SendClientMessage(playerid, COLOR_SYSTEM, string);
gGod[id] = 1;
SetPlayerHealth(id, 9999999999);
}
} else {
format(string, sizeof(string), "Godmode target not found or multiple targets found (%s)", tmp);
SendClientMessage(playerid, COLOR_SYSTEM, string);
}
}
return 1;
}
stock FindUser(pname[])
{
for(new s=0; s<strlen(pname); s++) // loop through the length of pname
if(pname[s] > '9' && pname[s] < '0') return strval(pname); // he gave us an id, return him the id
new name[24],counts; // create variables to store data in
for(new i=0; i<MAX_PLAYERS; i++) if(IsPlayerConnected(i)) // loop through all players and then check if they connected.
{
GetPlayerName(i,name,24); // get the player's name
if(strfind(name, pname, true) == 0) return i; // set the var to record number of hits we get
}
return -1; // if it gets too here, we have no match.
}