Help with changegravity cmd.
#1

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

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

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

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

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

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

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

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

EDIT:
See above ^^
Reply
#9

Repped. Thanks for the help!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)