Problem with a script. - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem with a script. (
/showthread.php?tid=259374)
Problem with a script. -
Jack_Leslie - 04.06.2011
I have this script to set a skin for a player:
Код:
if(strcmp(cmd, "/skin", true) == 0)
{
if(IsAtClothShop(playerid))
tmp = strtok(cmdtext, idx);
new chosenskin = strval(tmp);
SetPlayerSkin(playerid, chosenskin);
return 1;
}
So it works like /skin 152
The problem is if the players not at a clothes shop, instead of doing nothing, it sets skin to 0, even if I type /skin 123 it sets to 0, but I just want it to do nothing, but if player is inside a clothes shop it works 100%.
Re: Problem with a script. -
Swiftz - 04.06.2011
use else
Re: Problem with a script. -
Jack_Leslie - 04.06.2011
Thanks for the great explanation Swiftz.
Re: Problem with a script. -
Jay. - 04.06.2011
pawn Код:
if(strcmp(cmd, "/skin", true) == 0)
{
if(IsAtClothShop(playerid))
{
tmp = strtok(cmdtext, idx);
new chosenskin = strval(tmp);
SetPlayerSkin(playerid, chosenskin);
}
else
{
//do nothing
}
return 1;
}
Idk if it works
Re: Problem with a script. -
alpha500delta - 04.06.2011
Quote:
Originally Posted by Funtime
pawn Код:
if(strcmp(cmd, "/skin", true) == 0) { if(IsAtClothShop(playerid)) { tmp = strtok(cmdtext, idx); new chosenskin = strval(tmp); SetPlayerSkin(playerid, chosenskin); } else { //do nothing } return 1; }
Idk if it works
|
If you "do nothing" you can just use this:
pawn Код:
if(strcmp(cmd, "/skin", true) == 0)
{
if(IsAtClothShop(playerid))
{
tmp = strtok(cmdtext, idx);
new chosenskin = strval(tmp);
SetPlayerSkin(playerid, chosenskin);
}
else return 1;//Works as a { else } without the brackets
return 1;
}
Or even easyer:
pawn Код:
if(strcmp(cmd, "/skin", true) == 0)
{
if(!IsAtClothShop(playerid)) return 1; //if the player is NOT at a clothing shop (hence the "!")
tmp = strtok(cmdtext, idx);
new chosenskin = strval(tmp);
SetPlayerSkin(playerid, chosenskin);
return 1;
}
If it fails to set the skin, you might considering using sscanf and zcmd, then the code will look like this:
pawn Код:
CMD:setskin(playerid, params[])//ZCMD
{
new chosenskin;
if(!IsAtClothShop(playerid)) return 1; //if the player is NOT at a clothing shop (hence the "!")
if(sscanf(params,"d",chosenskin)) return SendClientMessage(playerid, COLOR, "Usage: /skin [skinid]");//SSCANF; If the player types just /skin or like /skin 0 4
SetPlayerSkin(playerid, chosenskin);
return 1;
}
Re: Problem with a script. -
Jay. - 04.06.2011
Quote:
Originally Posted by alpha500delta
If you "do nothing" you can just use this:
pawn Код:
if(strcmp(cmd, "/skin", true) == 0) { if(IsAtClothShop(playerid)) { tmp = strtok(cmdtext, idx); new chosenskin = strval(tmp); SetPlayerSkin(playerid, chosenskin); } else return 1;//Works as a { else } without the brackets return 1; }
Or even easyer:
pawn Код:
if(strcmp(cmd, "/skin", true) == 0) { if(!IsAtClothShop(playerid)) return 1; //if the player is NOT at a clothing shop (hence the "!") tmp = strtok(cmdtext, idx); new chosenskin = strval(tmp); SetPlayerSkin(playerid, chosenskin); return 1; }
|
I know, I know ^^
Just my way of doing it.