Limitations to a Command.
#1

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.
Reply
#2

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
Reply
#3

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;
}
Reply
#4

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.
Reply
#5

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.
Reply
#6

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?
Reply
#7

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

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.
Reply
#9

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
Reply
#10

Works, thankyou!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)