Szerző Téma: ZCMD-t STRCMP-be  (Megtekintve 518 alkalommal)

dexi

  • Vendég
ZCMD-t STRCMP-be
« Dátum: 2011. november 15. - 23:36:44 »
0 Show voters
[pawn]#include a_samp
#include zcmd
#include sscanf2
#define TEAM_ADMIN 2
new pAdmin[MAX_PLAYERS];
CMD:adadmin(playerid, params[]) {
    new id;
    if(sscanf(params, \"u\", id))SendClientMessage(playerid, -1, \"Használat: /parancs [iD]\");
    if(IsPlayerAdmin(playerid))SendClientMessage(playerid, -1, \"Hiba: Nem vagy rcon admin\");
    else if (id==INVALID_PLAYER_ID)SendClientMessage(playerid, -1,\"Hiba: Nem online játékos!\");
    else {
        pAdmin[id] = 2;
        SendClientMessage(id, -1, \"Valaki adminná tett!\");
    }
    return 1;
}[/pawn]
Ezt a kódot valaki légyszi átírná strcmp-be?(tudom hogy jobb a zcmd de légyszi.)

double out

  • Vendég
ZCMD-t STRCMP-be
« Válasz #1 Dátum: 2011. november 16. - 14:36:07 »
+1 Show voters

public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[128], idx, tmp[128], string[128];
cmd = strtok(cmdtext, idx);
    if(strcmp(cmd, \"/adadmin\", true) == 0)
    {
if(IsPlayerConnected(playerid) && IsPlayerAdmin(playerid))
    {
   tmp = strtok(cmdtext, idx);
   if(!strlen(tmp)) return SendClientMessage(playerid, -1, \"Használat: /adadmin [iD]\");
   new para1;
   para1 = ReturnUser(tmp);
   pAdmin[para1] = 2;
           SendClientMessage(para1, -1, \"Valaki adminná tett!\");
}
else
{
    SendClientMessage(playerid, -1, \"Hiba: Nem vagy rcon admin\");
}
return 1;
}
    return 0;
}
 
//----------------------------------------------------------------------------------------//
 
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
    new pos = 0;
    while (text[pos] < 0x21) // Strip out leading spaces
    {
        if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
        pos++;
    }
    new userid = INVALID_PLAYER_ID;
    if (IsNumeric(text[pos])) // Check whole passed string
    {
        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 name[MAX_PLAYER_NAME];
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            GetPlayerName(i, name, sizeof (name));
            if (strcmp(name, text[pos], true, len) == 0)
            {
         if (len == strlen(name))
         {
            return i;
             }
         else
         {
               count++;
               userid = i;
         }
      }
   }
}
if (count != 1)
{
   if (playerid != INVALID_PLAYER_ID)
    {
       if (count)
      {
         SendClientMessage(playerid, 0xFF0000AA, \"Multiple users found, please narrow earch\");
      }
      else
      {
         SendClientMessage(playerid, 0xFF0000AA, \"No matching user found\");
      }
     }
    userid = INVALID_PLAYER_ID;
}
return userid;
}
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;
}

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal