/mygravity
#1

ive been trying to do this using YSF's plugin but i suck with strings and stuff can anyone help me?
Reply
#2

What is your problem?
Reply
#3

i want players to be able to do /mygravity gravityammount using YSF plugin and i cant use strings and want to know where to start
Reply
#4

You could use SSCANF, or look at the debugger script, and possibly salvage the /g command from that.
Reply
#5

strtok:
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[256], tmp[256], idx;
cmd = strtok(cmdtext, idx);

if(strcmp(cmd, "/mygravity", true) ==0)
{
    tmp = strtok(cmdtext, idx);
    new Float:Gravity = floatstr(tmp);
    if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_BRIGHTRED, "USAGE: /gravity [number]");
    if(Gravity < 0.001 || Gravity > 0.900) return SendClientMessage(playerid, COLOR_RED, "Gravity has to be within 0.001 and 0.900");
    new string[128];
    format(string, sizeof(string), "You have changed your own gravity to: %0.3f", Gravity);
    SendClientMessage(playerid, COLOR_YELLOW, string);
    SetPlayerGravity(playerid, Gravity);
    return 1;
}

//other commands
return 0;
dcmd with sscanf:
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(mygravity, 9, cmdtext);
    //other stuff
    return 0;
}
Outside any callbacks.
pawn Code:
dcmd_mygravity(playerid, params[])
{
    new Float:Gravity = floatstr(params);
    if(sscanf(params, "f", Gravity)) return SendClientMessage(playerid, COLOR_RED, "SYNTAX ERROR: Usage: /setgravity <gravity>");
    if(Gravity < 0.001 || Gravity > 0.900) return SendClientMessage(playerid, COLOR_RED, "Gravity has to be within 0.001 and 0.900");
    new string[128];
    format(string, sizeof(string), "You have changed your own gravity to: %0.3f", Gravity);
    SendClientMessage(playerid, COLOR_YELLOW, string);
    SetPlayerGravity(playerid, Gravity);
    return 1;
}

Reply
#6

Quote:
Originally Posted by |∞|-Рцппσĵσ-|∞|
dcmd with sscanf:
[/pawn]
I can't find a single fault, nicely done. You've taken everything into account, not using 256 strings, using %0.3f. Very nice.
Reply
#7

You don't need sscanf if there's only one parameter.
Reply
#8

Sscanf doesn't only seperate the params, it also checks that they're the right type..

If somebody typed "/mygravity high" it might screw up somehow whereas sscanf prevents it..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)