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


Messages In This Thread
Command not working right - by BGTrucker - 12.04.2015, 16:54
Re: Command not working right - by Vince - 12.04.2015, 18:05
Re: Command not working right - by BGTrucker - 13.04.2015, 04:41

Forum Jump:


Users browsing this thread: 1 Guest(s)