I have a problem with a command "/vehicle"
#1

Hello. I have a problem with my command "/vehicle".
In the past it was a command like this: /veh
And now when I try to type: /vehicle 411 3 3 it says this: "Invalid vehicle ID specified !(411 - 611)"
I really don't know what to do. So I hope you can help me
Here is the command:
PHP код:
    if(strcmp(cmd"/vehicle"true) == 0)
    {
        if(
IsPlayerConnected(playerid))
        {
            new 
car,color,color2;
            if(
PlayerInfo[playerid][pAdmin] == 10)
            {
                new 
length strlen(cmdtext);
                while ((
idx length) && (cmdtext[idx] <= ' '))
                {
                    
idx++;
                }
                new 
offset idx;
                new 
result[64];
                while ((
idx length) && ((idx offset) < (sizeof(result) - 1)))
                {
                    
result[idx offset] = cmdtext[idx];
                    
idx++;
                }
                
result[idx offset] = EOS;
                if(!
strlen(result))
                {
                    
SendClientMessage(playeridCOLOR_GRAD2"USAGE: /vehicul [model] [culoare1] [culoare2]");
                    return 
1;
                }
                if(
car 400 || car 611) return SendClientMessage(playerid,COLOR_GRAD2"Invalid vehicle ID specified !(411 - 611)");
                if(
color255 || color0) return SendClientMessage(playeridCOLOR_GRAD2"Car color ID's: 0-255");
                if(
color2255 || color20) return SendClientMessage(playeridCOLOR_GRAD2"Car color ID's: 0-255");
                if(
IsPlayerInAnyVehicle(playerid)) return RemovePlayerFromVehicle(playerid);
                new    
Float:XFloat:YFloat:ZFloat:A;
                
GetPlayerPos(playeridX,Y,Z);
                
GetPlayerFacingAngle(playerid,A);
                new 
carid CreateVehicle(carX,Y,Z,Acolorcolor2, -1);
                
PutPlayerInVehicle(playerid,carid0);
                
LinkVehicleToInterior(carid,GetPlayerInterior(playerid));
            }
            else return 
SendClientMessage(playeridCOLOR_GRAD2NOTADMIN);
        }
        return 
1;
    } 
Reply
#2

bump
Reply
#3

Alright, I have converted your command to ZCMD and used sscanf.
At the top of your gamemode include ZCMD and sscanf2.

pawn Код:
CMD:vehicle(playerid, params[]) {
{
    new car,color,color2;
    if(PlayerInfo[playerid][pAdmin] == 10)
    {
        if(sscanf(params,"iii", car, color, color2))
        {
            SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /vehicul [model] [culoare1] [culoare2]");
            return 1;
        }
        if(car < 400 || car > 611) return SendClientMessage(playerid,COLOR_GRAD2, "Invalid vehicle ID specified !(411 - 611)");
        if(color> 255 || color< 0) return SendClientMessage(playerid, COLOR_GRAD2, "Car color ID's: 0-255");
        if(color2> 255 || color2< 0) return SendClientMessage(playerid, COLOR_GRAD2, "Car color ID's: 0-255");
        if(IsPlayerInAnyVehicle(playerid)) return RemovePlayerFromVehicle(playerid);
        new Float:X, Float:Y, Float:Z, Float:A;
        GetPlayerPos(playerid, X,Y,Z);
        GetPlayerFacingAngle(playerid,A);
        new carid = CreateVehicle(car, X,Y,Z,A, color, color2, -1);
        PutPlayerInVehicle(playerid,carid, 0);
        LinkVehicleToInterior(carid,GetPlayerInterior(playerid));
    }
    else return SendClientMessage(playerid, COLOR_GRAD2, NOTADMIN);
    return 1;
}
* I also removed the if(IsPlayerConnected(playerid)) condition I mean how if the player is not even connected he could use the command?

->Any feedback would be appreciated!
Reply
#4

I am an old scripter , from the time when the basic platform was strcmp. And now i'm confused of something. Why did you use "iii" in the command ? Can you explain me that? I would appreciated a lot
If I wrote something wrong, please excuse my bad english.
Reply
#5

You need use strtok if you are oldschool scripter ;p
Reply
#6

I am already using ;p
Reply
#7

sscanf is better as you can see, it's more code with strtok vs sscanf

this should work
pawn Код:
if(strcmp(cmd, "/vehicle", true) == 0)
{
    if(PlayerInfo[playerid][pAdmin] != 10) SendClientMessage(playerid, COLOR_GRAD2, NOTADMIN);
    else
    {
        new Model[4];
        strcat(Model,strtok(cmdtext, idx));
        if(!Model[0]) SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /vehicul [model] [culoare1] [culoare2]");
        else if(!(400 <= (Model[0] = strval(Model)) <= 611)) SendClientMessage(playerid,COLOR_GRAD2, "Invalid vehicle ID specified !(411 - 611)");
        else
        {
            new color_1[4];
            strcat(color_1,strtok(cmdtext, idx));
            if(!color_1[0]) SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /vehicul [model] [culoare1] [culoare2]");
            else if(!(0 <= (color_1[0] = strval(color_1)) <= 255)) SendClientMessage(playerid, COLOR_GRAD2, "Car color ID's: 0-255");
            else
            {
                new color_2[4];
                strcat(color_2,strtok(cmdtext, idx));
                if(!color_2[0]) SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /vehicul [model] [culoare1] [culoare2]");
                else if(!(0 <= (color_2[0] = strval(color_2)) <= 255)) SendClientMessage(playerid, COLOR_GRAD2, "Car color ID's: 0-255");
                else
                {
                    new Float:X, Float:Y, Float:Z, Float:A;
                    GetPlayerPos(playerid, X,Y,Z);
                    GetPlayerFacingAngle(playerid,A);
                    new carid = CreateVehicle(Model[0], X, Y, Z, A, color_1[0], color_2[0], -1);
                    LinkVehicleToInterior(carid,GetPlayerInterior(playerid));
                    PutPlayerInVehicle(playerid,carid,0);
                }
            }
        }
    }
    return 1;
}
Reply
#8

Quote:
Originally Posted by Jefff
Посмотреть сообщение
sscanf is better as you can see, it's more code with strtok vs sscanf

this should work
pawn Код:
if(strcmp(cmd, "/vehicle", true) == 0)
{
    if(PlayerInfo[playerid][pAdmin] != 10) SendClientMessage(playerid, COLOR_GRAD2, NOTADMIN);
    else
    {
        new Model[4];
        strcat(Model,strtok(cmdtext, idx));
        if(!Model[0]) SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /vehicul [model] [culoare1] [culoare2]");
        else if(!(400 <= (Model[0] = strval(Model)) <= 611)) SendClientMessage(playerid,COLOR_GRAD2, "Invalid vehicle ID specified !(411 - 611)");
        else
        {
            new color_1[4];
            strcat(color_1,strtok(cmdtext, idx));
            if(!color_1[0]) SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /vehicul [model] [culoare1] [culoare2]");
            else if(!(0 <= (color_1[0] = strval(color_1)) <= 255)) SendClientMessage(playerid, COLOR_GRAD2, "Car color ID's: 0-255");
            else
            {
                new color_2[4];
                strcat(color_2,strtok(cmdtext, idx));
                if(!color_2[0]) SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /vehicul [model] [culoare1] [culoare2]");
                else if(!(0 <= (color_2[0] = strval(color_2)) <= 255)) SendClientMessage(playerid, COLOR_GRAD2, "Car color ID's: 0-255");
                else
                {
                    new Float:X, Float:Y, Float:Z, Float:A;
                    GetPlayerPos(playerid, X,Y,Z);
                    GetPlayerFacingAngle(playerid,A);
                    new carid = CreateVehicle(Model[0], X, Y, Z, A, color_1[0], color_2[0], -1);
                    LinkVehicleToInterior(carid,GetPlayerInterior(playerid));
                    PutPlayerInVehicle(playerid,carid,0);
                }
            }
        }
    }
    return 1;
}
Thx a lot :d it works
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)