SA-MP Forums Archive
Help with code - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help with code (/showthread.php?tid=307529)



Help with code - Yahav - 30.12.2011

Код:
if(strcmp(cmd, "/DelPlayer123", true) == 0)
{
new tmp[MAX_PLAYER_NAME],str[256];
GetPlayerName(playerid, tmp, sizeof(tmp));
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) return SendClientMessage(playerid,COLOR_GREY, "USAGE: /DelPlayer [Name]");
format(str, sizeof(str), "Users/%s.ini",tmp);
if(dini_Exists(tmp))
{
SendClientMessage(playerid, COLOR_RED, "The user is not exists");
dini_Remove(tmp);
}
SendClientMessage(playerid, COLOR_WHITE, "The user has been deleted succedfully");
}
}
return 1;
}
It does not work? Help please


Re: Help with code - Mike_Peterson - 30.12.2011

Try this
pawn Код:
if(strcmp(cmd, "/DelPlayer", true) == 0)
{
new tmp[MAX_PLAYER_NAME],str[256];
GetPlayerName(playerid, tmp, sizeof(tmp));
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) return SendClientMessage(playerid,COLOR_GREY, "USAGE: /DelPlayer [Name]");
format(str, sizeof(str), "Users/%s.ini",tmp);
if(dini_Exists(strval(tmp)))
{
SendClientMessage(playerid, COLOR_WHITE, "The user has been deleted succedfully");
dini_Remove(strval(tmp));
} else return SendClientMessage(playerid, COLOR_RED, "The user is not exists");
return 1;
}



Re: Help with code - Cameltoe - 30.12.2011

I would highly suggest you to change command processor to zcmd, would make the command process faster aswell as being easier to read / understand.
pawn Код:
command(deleteplayer, playerid, params[])
{
     new Userfile[40]
     if(strlen(params) < 1) return SendClientMessage(playerid, 0x0, "The player's name does not seem to be valid");
     format(Userfire, sizeof(Userfile), "Users/%s.ini", Params);
     if(dini_Exists(Userfile))
     {
          dini_Remove(Userfile);
          SendClientMessage(playerid, COLOR_WHITE, "The user has been deleted succedfully");
     }
     else
     {
          SendClientMessage(playerid, COLOR_WHITE, "User does not exist");
     }
     return 1;
}



Re: Help with code - Yahav - 30.12.2011

have errors

Код:
C:\Documents and Settings\x\My Documents\samp03\Ultimate.pwn(48195) : warning 219: local variable "tmp" shadows a variable at a preceding level
C:\Documents and Settings\x\My Documents\samp03\Ultimate.pwn(48197) : error 047: array sizes do not match, or destination array is too small
C:\Documents and Settings\x\My Documents\samp03\Ultimate.pwn(48200) : error 035: argument type mismatch (argument 1)
C:\Documents and Settings\x\My Documents\samp03\Ultimate.pwn(48203) : error 035: argument type mismatch (argument 1)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
line 48195
Код:
new tmp[MAX_PLAYER_NAME],str[256];
line 48197
Код:
tmp = strtok(cmdtext, idx);
line 48200
Код:
if(dini_Exists(strval(tmp)))
line 48203
Код:
dini_Remove(strval(tmp));



Re: Help with code - AustinJ - 30.12.2011

Not Dini... But here...
pawn Код:
if(!strcmp(cmd, "/DelPalyer", true))
{
    new params[24], file[34];
    params = strtok(cmdtext, idx);
    if(!strlen(params))
    {
        SendClientMessage(playerid, COLOR_GREY, "USAGE: /DelPlayer [Name]");
    }
    else
    {
        format(file, 256, "Users/%s.ini", params);
        if(!fexist(file))
        {
            SendClientMessage(playerid, COLOR_RED, "That user doesn't exist.");
        }
        else
        {
            fremove(file);
            SendClientMessage(playerid, COLOR_WHITE, "That user has been deleted successfully.");
        }
    }
    return 1;
}



Re: Help with code - Jefff - 30.12.2011

pawn Код:
if(strcmp(cmd, "/DelPlayer123", true) == 0)
{
    new str[35];
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp)) return SendClientMessage(playerid,COLOR_GREY, "USAGE: /DelPlayer [Name]");
    format(str, sizeof(str), "Users/%s.ini",tmp);
    if(fremove(str)) SendClientMessage(playerid, COLOR_WHITE, "The user has been deleted succedfully");
    else SendClientMessage(playerid, COLOR_RED, "The user is not exists");
    return 1;
}



Re: Help with code - Yahav - 30.12.2011

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
if(strcmp(cmd, "/DelPlayer123", true) == 0)
{
    new str[35];
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp)) return SendClientMessage(playerid,COLOR_GREY, "USAGE: /DelPlayer [Name]");
    format(str, sizeof(str), "Users/%s.ini",tmp);
    if(fremove(str)) SendClientMessage(playerid, COLOR_WHITE, "The user has been deleted succedfully");
    else SendClientMessage(playerid, COLOR_RED, "The user is not exists");
    return 1;
}
Thanks man but its dosent work in the game


Re: Help with code - Jefff - 30.12.2011

try /Users/%s.ini


Re: Help with code - Yahav - 31.12.2011

It does not work, because it is not shows me
/DelPlayer [Name]


Re: Help with code - Jefff - 31.12.2011

Quote:
Originally Posted by Yahav
Посмотреть сообщение
It does not work, because it is not shows me
/DelPlayer [Name]
ok xd so without strtok
pawn Код:
if(strcmp(cmdtext, "/DelPlayer123", true, 13) == 0)
{
    new str[35],len;
    len = strlen(cmdtext[14]);
    if(!len) return SendClientMessage(playerid,COLOR_GREY, "USAGE: /DelPlayer [Name]");
    if(!(3 <= len <= 24)) return SendClientMessage(playerid,COLOR_GREY, "Name must be > 3 and < 24 chars");
    format(str, sizeof(str), "/Users/%s.ini",cmdtext[14]);
    if(fremove(str)) SendClientMessage(playerid, COLOR_WHITE, "The user has been deleted succedfully");
    else SendClientMessage(playerid, COLOR_RED, "The user is not exists");
    return 1;
}