SA-MP Forums Archive
Help with changegravity cmd. - 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: Help with changegravity cmd. (/showthread.php?tid=291162)



Help with changegravity cmd. - Azzeto - 18.10.2011

PHP код:
CMD:changegravity(playerid,params[]){
    new 
gravity SetGravity(gravity), string[128];
    if(
PlayerInfo[playerid][pAdminDuty] == 0) return SendClientMessage(playerid,COLOR_GRAY,"Error: You're not on admin duty!");
    else if(
PlayerInfo[playerid][pAdmin] < 4) return AdminRefuse(playerid);
    else if(
sscanf(params,"d",gravity)) return SendClientMessage(playerid,COLOR_GRAY,"Syntax: /changegravity [gravity]");
    else
    {
        
format(string,sizeof(string),"Admin %s has set the gravity to %d",GetName(playerid),gravity);
        
SendClientMessageToAll(COLOR_YELLOW,string);
    }
    return 
1;

Thats my command, but I cant put numbers like 000.8 because it gives me the error, /changegravity [gravity]
But if I do /changegravity 1 it works fine..


Re: Help with changegravity cmd. - Wesley221 - 18.10.2011

Thats because '0.008' is a float, and not an integer.
Change the 'else if(sscanf(params,"d",gravity))' to 'else if(sscanf(params,"f",gravity))'


Re: Help with changegravity cmd. - Azzeto - 18.10.2011

Ok, now I set it to 0.008 (which is the default gravity) and I jump really high?


Re: Help with changegravity cmd. - Gustavob - 18.10.2011

Quote:
Originally Posted by Wesley221
Посмотреть сообщение
Thats because '0.008' is a float, and not an integer.
Change the 'else if(sscanf(params,"d",gravity))' to 'else if(sscanf(params,"f",gravity))'
Also change "new gravity" into "new Float:gravity", and I don't think you need to add that "= SetGravity(gravity)" after it. Also change the second %d into %f, turning the whole thing into something like the following:

pawn Код:
CMD:changegravity(playerid,params[]){
    new Float:gravity, string[128];
    if(PlayerInfo[playerid][pAdminDuty] == 0) return SendClientMessage(playerid,COLOR_GRAY,"Error: You're not on admin duty!");
    else if(PlayerInfo[playerid][pAdmin] < 4) return AdminRefuse(playerid);
    else if(sscanf(params,"f",gravity)) return SendClientMessage(playerid,COLOR_GRAY,"Syntax: /changegravity [gravity]");
    else
    {
        format(string,sizeof(string),"Admin %s has set the gravity to %f",GetName(playerid),gravity);
        SendClientMessageToAll(COLOR_YELLOW,string);
    }
    return 1;
}



Re: Help with changegravity cmd. - Azzeto - 18.10.2011

Still same issue ^ I set it to default gravity (0.00 and it jumps really high.


Re: Help with changegravity cmd. - Azzeto - 18.10.2011

And it needs SetGravity(gravity); i'm sure because thats what the variable is doing.


Re: Help with changegravity cmd. - Gustavob - 18.10.2011

Silly me.
pawn Код:
CMD:changegravity(playerid,params[]){
    new Float:gravity, string[128];
    if(PlayerInfo[playerid][pAdminDuty] == 0) return SendClientMessage(playerid,COLOR_GRAY,"Error: You're not on admin duty!");
    else if(PlayerInfo[playerid][pAdmin] < 4) return AdminRefuse(playerid);
    else if(sscanf(params,"f",gravity)) return SendClientMessage(playerid,COLOR_GRAY,"Syntax: /changegravity [gravity]");
    else
    {
        format(string,sizeof(string),"Admin %s has set the gravity to %f",GetName(playerid),gravity);
        SendClientMessageToAll(COLOR_YELLOW,string);
        SetGravity(gravity);
    }
    return 1;
}
That should do it. Just added SetGravity(gravity) inside the last else, which was missing for some reason.


Re: Help with changegravity cmd. - Drebin - 18.10.2011

I don't see a
pawn Код:
SetGravity();
anywhere in this code ?

EDIT:
See above ^^


Re: Help with changegravity cmd. - Azzeto - 18.10.2011

Repped. Thanks for the help!