SA-MP Forums Archive
Limitations to a Command. - 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: Limitations to a Command. (/showthread.php?tid=478827)



Limitations to a Command. - NoSoap - 01.12.2013

Afternoon,

I'm using DCMD to make my gamemode, and I've been getting to grips with scripting again (after not scripting for a good few years).

I've started off by making some simple commands to allow players to set their skins;

Код:
CMD:skin(playerid, params[])
{
new skinid, string[128];
if(sscanf(params, "d", skinid))
{
SendClientMessage(playerid, COLOR_RED, "USAGE: /s(kin) [skinID].");
}
else
{
SetPlayerSkin(playerid, skinid);
format(string, sizeof(string), "You have set your skinID to %d.", skinid);
SendClientMessage(playerid, COLOR_GREEN, string);
}
return 1;
}
However, If someone types a skinid above 299, it will crash their game.
How do I stop this? I've seen it before in a script where people have used > and < , but it'd be nice If someone could explain this to me or point me at a decent tutorial.

Cheers.


Re: Limitations to a Command. - SilentSoul - 01.12.2013

Because no skins above skin id 299 avilable on sa-mp , so they set a string variable (strval) to make sure that the player can't use skin above than 299 or less than 0 which in fact they use ">"Right is bigger than "<"Left is biggerthan , Right is smaller than
#Script
pawn Код:
CMD:skin(playerid, params[])
{
new skinid, string[128];
if(sscanf(params, "d", skinid))
{
SendClientMessage(playerid, COLOR_RED, "USAGE: /s(kin) [skinID].");
}
else
{
new tmp[256];//to avoide undefined symbol error.
tmp = strtok(cmdtext,idx);
if(strval(tmp) > 299 || strval(tmp) < 0) return SendClientMessage(playerid, -1,"{FF0000}You can't use skin above 299 or lower than0.");//if the string bigger than 299 "strval(tmp) > 299" the skin won't set and send them error message
SetPlayerSkin(playerid, skinid);
format(string, sizeof(string), "You have set your skinID to %d.", skinid);
SendClientMessage(playerid, COLOR_GREEN, string);
}
return 1;
}
Original links : https://sampwiki.blast.hk/wiki/Strval
https://sampwiki.blast.hk/wiki/Strtok


Re: Limitations to a Command. - Patrick - 01.12.2013

Quote:
Originally Posted by SilentSoul
Посмотреть сообщение
Because no skins above skin id 299 avilable on sa-mp , so they set a string variable (strval) to make sure that the player can't use skin above than 299 or less than 0 which in fact they use ">"Right is bigger than "<"Left is biggerthan , Right is smaller than
#Script
pawn Код:
CMD:skin(playerid, params[])
{
new skinid, string[128];
if(sscanf(params, "d", skinid))
{
SendClientMessage(playerid, COLOR_RED, "USAGE: /s(kin) [skinID].");
}
else
{
new tmp[256];//to avoide undefined symbol error.
tmp = strtok(cmdtext,idx);
if(strval(tmp) > 299 || strval(tmp) < 0) return SendClientMessage(playerid, -1,"{FF0000}You can't use skin above 299 or lower than0.");//if the string bigger than 299 "strval(tmp) > 299" the skin won't set and send them error message
SetPlayerSkin(playerid, skinid);
format(string, sizeof(string), "You have set your skinID to %d.", skinid);
SendClientMessage(playerid, COLOR_GREEN, string);
}
return 1;
}
No idea why you needed strtok in there when you could simply use this code *command below*
pawn Код:
CMD:skin(playerid, params[])
{
    new skinid, string[128];
    if(sscanf(params, "d", skinid))
        return SendClientMessage(playerid, COLOR_RED, "USAGE: /s(kin) [skinID].");

    if(0 >= skinid >= 300)
        return SendClientMessage(playerid, -1,"{FF0000}You can't use skin above 299 or lower than0.");//if the string bigger than 299 "strval(tmp) > 299" the skin won't set and send them error message

    SetPlayerSkin(playerid, skinid);
    format(string, sizeof(string), "You have set your skinID to %d.", skinid);
    SendClientMessage(playerid, COLOR_GREEN, string);
    return true;
}



Re: Limitations to a Command. - NoSoap - 01.12.2013

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
No idea why you needed strtok in there when you could simply use this code *command below*
pawn Код:
CMD:skin(playerid, params[])
{
    new skinid, string[128];
    if(sscanf(params, "d", skinid))
        return SendClientMessage(playerid, COLOR_RED, "USAGE: /s(kin) [skinID].");

    if(0 >= skinid >= 300)
        return SendClientMessage(playerid, -1,"{FF0000}You can't use skin above 299 or lower than0.");//if the string bigger than 299 "strval(tmp) > 299" the skin won't set and send them error message

    SetPlayerSkin(playerid, skinid);
    format(string, sizeof(string), "You have set your skinID to %d.", skinid);
    SendClientMessage(playerid, COLOR_GREEN, string);
    return true;
}
That's exactly what I thought it should have been.
I'll try this now.

Edit: Works, +Rep'd you both for your effort, thanks lads.


Re: Limitations to a Command. - NoSoap - 01.12.2013

Still isn't working, people crash when entering it still, still seems to be entering the skin.
I can't personally see what's wrong with it.


Re: Limitations to a Command. - SilentSoul - 01.12.2013

How people crash ? while they can't use skins above 299 or lower than 0 , maybe they have just edited there orginal gta by installing new skins?


Re: Limitations to a Command. - Audi_Quattrix - 01.12.2013

https://sampforum.blast.hk/showthread.php?tid=364043
Just take a look in my skin filterscript


Re: Limitations to a Command. - NoSoap - 01.12.2013

No, it's the fact that people can still select above 300, the warning message doesn't appear at all, as if it isn't working.


Re: Limitations to a Command. - SilentSoul - 01.12.2013

pawn Код:
CMD:skin(playerid, params[])
{
    new skinid, string[128];
    if(sscanf(params, "d", skinid))
        return SendClientMessage(playerid, COLOR_RED, "USAGE: /s(kin) [skinID].");
    else if(skinid < 0 || skinid > 299) return SendClientMessage(playerid, 0xFF000000, "You can't use skin above 299 or lower than 0.");
    SetPlayerSkin(playerid, skinid);
    format(string, sizeof(string), "You have set your skinID to %d.", skinid);
    SendClientMessage(playerid, COLOR_GREEN, string);
    return true;
}
That should work , pds2k12 has made an error sorry i didn't notice that


Re: Limitations to a Command. - NoSoap - 01.12.2013

Works, thankyou!