What am I doing Wrong? (Vehicle params)
#1

Ok, so heres what I wanted to do, I wanted to create a command where when i type /onlights, a timer is run that loops the lights so they turn on and off continuously, but that failed, and i'm not so sure why.

Here's the code:

pawn Код:
//this is what I use to set the lights on and off (flashing)
forward SetVehicleFlashingLights(playerid, vehicleid);
public SetVehicleFlashingLights(playerid, vehicleid)
{
    new
        engine,
        lights,
        alarm,
        doors,
        bonnet,
        boot,
        objective;

    if(IsPlayerInAnyVehicle(playerid))
    {
        if(engine != VEHICLE_PARAMS_ON)
            {
                SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_ON, lights, alarm, doors, bonnet, boot, objective);
            }
            else
                {
                    SetVehicleParamsEx(vehicleid, engine, VEHICLE_PARAMS_OFF, alarm, doors, bonnet, boot, objective);
                    SetVehicleParamsEx(vehicleid, engine, VEHICLE_PARAMS_ON, alarm, doors, bonnet, boot, objective);
                }
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid, engine, VEHICLE_PARAMS_OFF, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid, engine, VEHICLE_PARAMS_ON, alarm, doors, bonnet, boot, objective);
            }
}
pawn Код:
//this turns off the flashing lights, by running itself once, you'll see in the command, what I did.

forward TurnOffFlashingLights(playerid, vehicleid);
public TurnOffFlashingLights(playerid, vehicleid)
{
    new
        engine,
        lights,
        alarm,
        doors,
        bonnet,
        boot,
        objective;

    while(IsPlayerInAnyVehicle(playerid))
    {
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid, engine, VEHICLE_PARAMS_OFF, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid, engine, VEHICLE_PARAMS_ON, alarm, doors, bonnet, boot, objective);
    }
}

COMMANDS

pawn Код:
new kmiTimer; //for timer, outside (global var)

//this is supposed to start the timer
dcmd_OnLights(playerid, params[])
{
    #pragma unused params
    new
        vehID;
       
    vehID = GetPlayerVehicleID(playerid);
   
    if(IsPlayerInAnyVehicle(playerid))
    {
        kmiTimer = SetTimerEx("SetVehicleFlashingLights", 30000, true, "d", vehID);
        SendClientMessage(playerid, 0xFFFFFFFF, "[ ! ] Vehicle Lights turned on. If nothing happens, there is something wrong with your code.");
    }
    else
    {
        SendClientMessage(playerid, 0xFF0000FF, "[ ! ] You aren't in a vehicle!");
    }
    return true;
}


//this is supposed to turn them off.
dcmd_OffLights(playerid, params[])
{
    #pragma unused params
    new
        vehID;
       
    vehID = GetPlayerVehicleID(playerid);
   
    if(IsPlayerInAnyVehicle(playerid))
    {
        KillTimer(kmiTimer);
        SendClientMessage(playerid, 0xFF0000FF, "[ ! ] Lights killed successfully.");
        SetTimerEx("TurnOffFlashingLights", 1, true, "d", vehID);
    }
    else
    {
        SendClientMessage(playerid, 0xFF0000FF, "[ ! ] You aren't in a vehicle!");
    }
    return true;
}
Reply


Messages In This Thread
What am I doing Wrong? (Vehicle params) - by Hiitch - 30.11.2010, 22:12
Re: What am I doing Wrong? (Vehicle params) - by Grim_ - 30.11.2010, 22:13
Re: What am I doing Wrong? (Vehicle params) - by Hiitch - 30.11.2010, 22:15
Re: What am I doing Wrong? (Vehicle params) - by Grim_ - 30.11.2010, 22:21
Re: What am I doing Wrong? (Vehicle params) - by Hiitch - 30.11.2010, 22:22
Re: What am I doing Wrong? (Vehicle params) - by bn102 - 01.12.2010, 06:29

Forum Jump:


Users browsing this thread: 1 Guest(s)