SA-MP Forums Archive
/mygravity - 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: /mygravity (/showthread.php?tid=77314)



/mygravity - mini-d - 10.05.2009

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


Re: /mygravity - Djiango - 10.05.2009

What is your problem?


Re: /mygravity - mini-d - 10.05.2009

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


Re: /mygravity - Weirdosport - 10.05.2009

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


Re: /mygravity - Djiango - 10.05.2009

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




Re: /mygravity - Weirdosport - 10.05.2009

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.


Re: /mygravity - Backwardsman97 - 10.05.2009

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


Re: /mygravity - Weirdosport - 10.05.2009

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..