Command not working right
#1

So I tried to create a command of my own to spawn vehicles but for some reason it sets the vehicle model parameter as spawn delay too,instead of the spawn delay that I have set.
This is how it should work-if player is in a vehicle,and doesnt set a vehicle model parameter for the new vehicle,the vehicle model parameter is set to the vehicle model of the player's current vehicle.If player is on foot,and he doesnt set a vehicle model parameter,he gets a message that he has to set it.When a valid vehicle model is set(400-611),then come the vehicle colors.If the player doesnt set them,they are set to random(126),and then if the player doesnt set spawn delay,it should be set to 300,but it seems to not get set to 300.Instead it gets set to the vehicle model parameter.For example if I want to spawn NRG500(521),the spawn delay gets set to 521 too.What could be the problem.Im using ZCMD and SSCANF.Here is the code.
pawn Код:
CMD:vehicle(playerid,params[])
{
    new model,col[2],delay;
    if(PInfo[playerid][Lvl]>=5)
    {
        for(new i=1;i<MAX_VEHICLES;i++)
        {
            if(GetVehicleModel(i)==0)
            {
                if(v[playerid]!=0)
                {
                    if(sscanf(params,"i",model)) model=GetVehicleModel(v[playerid]);
                    GetVehiclePos(v[playerid],x,y,z);
                    GetVehicleZAngle(v[playerid],rot);
                    SetVehicleToRespawn(v[playerid]);
                }
                else
                    if(sscanf(params,"i",model)){SendClientMessage(playerid,-1,"USAGE: /vehicle [model ID(400-611)] (color 1) (color 2) (spawn delay)");return 1;}
                    else
                    {
                        GetPlayerPos(playerid,x,y,z);
                        GetPlayerFacingAngle(playerid,rot);
                    }
                if(400<=model<=611)
                {
                    if(sscanf(params,"ii",col[0],col[1]))
                    {
                        col[0]=random(126);col[1]=random(126);
                    }
                    if(sscanf(params,"i",delay)) delay=300;
                    Vehicle(model,x,y,z,rot,col[0],col[1],delay);
                    PutPlayerInVehicle(playerid,i,0);
                    format(file,100,VEHICLES);
                    if(fexist(file)) File=fopen(file,io_append);
                    else File=fopen(file,io_write);
                    format(Line,200,"%i %.1f %.1f %.1f %.1f %i %i %i\r\n",model,x,y,z,rot,col[0],col[1],delay); fwrite(File,Line);fclose(File);
                    format(Msg,256,"You created new vehicle with ID %i and model %s(%i) and spawn delay %i seconds",i,VModelInfo[model-400][VModelName],model,delay);
                    SendClientMessage(playerid,-1,Msg);
                }
                else SendClientMessage(playerid,-1,"USAGE: /vehicle [model ID(400-611)] (color 1) (color 2) (spawn delay)");
                break;
            }
            else
            {
                if(i==MAX_VEHICLES-1) SendClientMessage(playerid,-1,"ERROR: You cannot create any more vehicles because vehicle limit has been reached.");
                else continue;
            }
        }
    }
    else return 0;
    return 1;
}
Reply
#2

I am unsure what the whole looping construct is for. You should just try to create the vehicle and if that fails because the limit is reached then CreateVehicle will return INVALID_VEHICLE_ID. What you described should be easily achievable with sscanf's optional parameters.

pawn Код:
if(sscanf(params, "D(-1)D(-1)D(-1)D(300)", model, col1, col2, delay))
{
    if(!(400 <= model <= 611))
    {
        // model not valid, do something
    }

    if(col1 == -1)
        col1 = random(126);

    if(col2 == -1)
        col2 = random(126);

    if(!(15 <= delay <= 300))
        return SendClientMessage ... invalid respawn delay must be between 15 and 300

    v[playerid] = CreateVehicle(model, ..., col1, col2, delay);

    if(v[playerid] == INVALID_VEHICLE_ID)
        return SendClientMessage ... failed, vehicle limit reached
   
}
You could even prepare the formatstring by inserting the player's current vehicle model.
Reply
#3

I do that so the command can return proper error message to player who execute it.If model is invalid model id,it should show that he has to use id between 400 and 611,and if vehicle limit is reached it should show a message saying that.
Also I cant use v[playerid]=CreateVehicle(); because v[playerid] is actually this
pawn Код:
#define v[%0] GetPlayerVehicleID[%0]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)