PDA

View Full Version : Help with code


Yahav
30/12/2011, 09:04 PM
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

Mike_Peterson
30/12/2011, 09:07 PM
Try this

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;
}

Cameltoe
30/12/2011, 09:14 PM
I would highly suggest you to change command processor to zcmd, would make the command process faster aswell as being easier to read / understand.

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;
}

Yahav
30/12/2011, 09:16 PM
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 (c) 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));

AustinJ
30/12/2011, 09:38 PM
Not Dini... But here...
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;
}

Jefff
30/12/2011, 09:42 PM
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;
}

Yahav
30/12/2011, 11:27 PM
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

Jefff
30/12/2011, 11:32 PM
try /Users/%s.ini

Yahav
31/12/2011, 12:19 AM
It does not work, because it is not shows me
/DelPlayer [Name]

[ABK]Antonio
31/12/2011, 12:29 AM
if(strcmp(cmd, "/DelPlayer123", true) == 0)
{
new tmp[MAX_PLAYER_NAME],str[35];
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


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


That ofc might not work...Prolly wont

With sscanf2

if(strcmp(cmd, "/DelPlayer", true) == 0)
{
new file[35], thename[24];
if(sscanf(params, "s[24]", thename)) return SendClientMessage(playerid, 0xCC0000AA, "USAGE: /delplayer <name>");

format(file, sizeof(file), "Users/%s.ini",thename);
if(dini_Exists(thename))
{
dini_Remove(file);
SendClientMessage(playerid, COLOR_WHITE, "The user has been deleted succedfully");
}
else return SendClientMessage(playerid, COLOR_RED, "The user is not exists");
return 1;
}


With sscanf2 + ZCMD

CMD:delplayer(playerid, params[])
{
new name[MAX_PLAYER_NAME], file[35], thename[24], str[128];
if(sscanf(params, "s[24]", thename)) return SendClientMessage(playerid, 0xCC0000AA, "USAGE: /delplayer <name>");
format(file, sizeof(file), "Users/%s.ini",thename);
if(dini_Exists(thename))
{
GetPlayerName(playerid, name,sizeof(name));
format(str,sizeof(str), "%s has deleted the savefile %s", name, thename);
dini_Remove(file);
}
if(!dini_Exists(thename))
{
format(str,sizeof(str), "%s doesn't exist!", thename);
}

}

CMD:deleteplayer(playerid, params[]) return cmd_delplayer(playerid, params);
CMD:delpl(playerid, params[]) return cmd_delplayer(playerid, params);



NOTE: GetPlayerName(playerid, tmp, sizeof(tmp)) is getting the playerids name...then storing it into tmp..Should probably not do that lol

EDIT: looking back...

if(strlen(tmp) > 24 || strlen(tmp) < 3) return SendClientMessage(playerid, 0xCC0000AA, "USAGE: /delplayer <name>");

Jefff
31/12/2011, 12:35 AM
It does not work, because it is not shows me
/DelPlayer [Name]

ok xd so without strtok
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;
}