OnVehicle
#1

hi

how do i set this OnVehicleSpawn

Every vehicle spawn the vehicle engine is 0

and Every time when player enter a car and if the vehicle engine is 0 it will send a message like this:

"Your vehicle engine is not turned on! type /car engine if you used to turn on"

Код:
else if(strcmp(params, "engine", true) == 0 && IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
	    new vehicle = GetPlayerVehicleID(playerid);
	    new string[126];
      	new engine, lights, alarm, doors, bonnet, boot, objective;
	    GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, bonnet, boot, objective);

	    if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	    {
	        if(Engine[vehicle] == 0)
	        {
	            Engine[vehicle] = 1;
	            SetVehicleParamsEx(vehicle,1,lights,alarm,doors,bonnet,boot,objective);
	            format(string, sizeof(string), "* %s turns the engine of their vehicle engine on.", GetPlayerNameEx(playerid));
	            ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
	            return 1;
	        }
	        else
	        {
	            Engine[vehicle] = 0;
	            SetVehicleParamsEx(vehicle,0,lights,alarm,doors,bonnet,boot,objective);
	            format(string, sizeof(string), "* %s turns the vehicles engine off.", GetPlayerNameEx(playerid));
	            ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
	            return 1;
	        }
	    }
	    return engine;
	}
TY
Reply
#2

GetVehicleParamsEx and SetVehicleParamsEx.

You have also to know about conditions.

I'll be glad to help you in your questions
Reply
#3

Quote:
Originally Posted by arakuta
Посмотреть сообщение
GetVehicleParamsEx and SetVehicleParamsEx.

You have also to know about conditions.

I'll be glad to help you in your questions
I add it, and result: Not worked the vehicle is still running when vehicle spawned. I tried my best but no luck

Код:
    new engine, lights, alarm, doors, bonnet, boot, objective;
	GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
	SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective); // ONLY the engine param was changed (to 1)
Reply
#4

Just a side note: OnVehicleSpawn is called when a vehicle re-spawns not when it's created.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Just a side note: OnVehicleSpawn is called when a vehicle re-spawns not when it's created.
thanks But where do i put it? those codes
Reply
#6

https://sampforum.blast.hk/showthread.php?tid=441293

Hook the functions that create/add vehicles and set the engine to 0.
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
https://sampforum.blast.hk/showthread.php?tid=441293

Hook the functions that create/add vehicles and set the engine to 0.
O_O



I cant understand those. Can you just give me the exact way?
Reply
#8

Or just re-spawn all vehicle after create all of them.
Reply
#9

pawn Код:
stock HF_CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay)
{
    new vehicleid = CreateVehicle(modelid, x, y, z, angle, color1, color2, respawn_delay);
    if (vehicleid != INVALID_VEHICLE_ID) // not invalid modelid or full
    {
        Engine[vehicleid] = 0;
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
    }
    return 1;
}

#if defined _ALS_CreateVehicle
    #undef CreateVehicle
#else
    #define _ALS_CreateVehicle
#endif

#define CreateVehicle HF_CreateVehicle
Although you get the engine parameter so the array for toggling the engine is kind of pointless.
Do the same for AddStaticVehicle and AddStaticVehicleEx functions.
Reply
#10

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
stock HF_CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay)
{
    new vehicleid = CreateVehicle(modelid, x, y, z, angle, color1, color2, respawn_delay);
    if (vehicleid != INVALID_VEHICLE_ID) // not invalid modelid or full
    {
        Engine[vehicleid] = 0;
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
    }
    return 1;
}

#if defined _ALS_CreateVehicle
    #undef CreateVehicle
#else
    #define _ALS_CreateVehicle
#endif

#define CreateVehicle HF_CreateVehicle
Although you get the engine parameter so the array for toggling the engine is kind of pointless.
Do the same for AddStaticVehicle and AddStaticVehicleEx functions.
https://sampwiki.blast.hk/wiki/ManualVehicleEngineAndLights
SA-MP has native function for this.
and I think this should be:
pawn Код:
stock HF_CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay)
{
    new vehicleid = CreateVehicle(modelid, x, y, z, angle, color1, color2, respawn_delay);
    if (vehicleid != INVALID_VEHICLE_ID) // not invalid modelid or full
    {
        Engine[vehicleid] = 0;
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
        return vehicleid;
    }
    return INVALID_VEHICLE_ID;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)