Originally Posted by Aly
Ok I will try to explain you:
First of all you have to put this somewhere in your script:
pawn Код:
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; }
ReturnUser(text[], playerid = INVALID_PLAYER_ID) { new pos = 0; while (text[pos] < 0x21) { if (text[pos] == 0) return INVALID_PLAYER_ID; pos++; }
new userid = INVALID_PLAYER_ID; if (IsNumeric(text[pos])) { userid = strval(text[pos]); if (userid >=0 && userid < MAX_PLAYERS) { if(!IsPlayerConnected(userid)) userid = INVALID_PLAYER_ID; else return userid; } }
new len = strlen(text[pos]); new count = 0; new pname[MAX_PLAYER_NAME];
for (new i = 0; i < MAX_PLAYERS; i++) { if (IsPlayerConnected(i)) { GetPlayerName(i, pname, sizeof (pname)); if (strcmp(pname, text[pos], true, len) == 0) { if (len == strlen(pname)) return i; else { count++; userid = i; } } } } if (count != 1) { if (playerid != INVALID_PLAYER_ID) { if (count) SendClientMessage(playerid, COLOR_WHITE, "Enter the full name of the user."); else SendClientMessage(playerid, COLOR_GREY, "No results found for the specified phrase."); } userid = INVALID_PLAYER_ID; } return userid; }
Now go on to OnPlayerCommandText(playerid,cmdtext[]) and add this:
pawn Код:
new cmd[256],idx,tmp[256]; cmd = strtok(cmdtext,idx);
And now to transform the command:
pawn Код:
if(strcmp(cmd,"/tempban",true) == 0) { if(!TempAdmin(playerid)) return SendClientMessage(playerid,COLOR_RED,"You must be admin to use this command."); new days,id,name[24]; if(GetCurrentTempBanCount() == 24) return SendClientMessage(playerid,COLOR_RED,"Temp Ban Limit Reached."); tmp = strtok(cmdtext,idx); if(!strlen(tmp)) return SendClientMessage(playerid,COLOR_RED,"Usage: /tempban <PlayerID/Name> <Amount Of Days> <Reason>"); id = ReturnUser(tmp); tmp = strtok(cmdtext,idx); if(!strlen(tmp)) return SendClientMessage(playerid,COLOR_RED,"Usage: /tempban <PlayerID/Name> <Amount Of Days> <Reason>"); days = strval(tmp); new length = strlen(cmdtext); while ((idx < length) && (cmdtext[idx] <= ' ')) { idx++; } new offset = idx; new result[128]; while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))) { result[idx - offset] = cmdtext[idx]; idx++; } result[idx - offset] = EOS; if(!strlen(result)) return SendClientMessage(playerid,COLOR_RED,"Usage: /tempban <PlayerID/Name> <Amount Of Days> <Reason>"); if(IsPlayerConnected(id)) { new year,mon,d; getdate(year,mon,d); new i = GetTempBanSlot(); new aname[24]; GetPlayerName(playerid,aname,sizeof aname); GetPlayerName(id,name,sizeof name); format(TempBans[i][BannedName],sizeof name,"%s",name); TempBans[i][BannedName] = name; TempBans[i][UnbanDate] = d+days; new str[128]; GetPlayerName(id,name,sizeof name); format(str,sizeof str,"%s (ID%d) has been temporary banned by Admin %s (ID:%d) (%s)",aname,playerid,name,id,result); SendClientMessage(playerid,COLOR_RED,str); Kick(id); } return 1; }
Something like that , Something probably be wrong. I made it in hurry.
Just tell me if something's wrong.
|