OnVehicleSpawn
#1

I use CreateVehicle after loading vehicles from a MySQL DB. The vehicles get created, but it doesn't seem that OnVehicleSpawn is being called. Is this supposed to happen when using CreateVehicle? The only want OnVehicleSpawn is called is when the vehicle dies and respawns.
Reply
#2

CreateObject has a respawn delay. Call them under OnGameModeInIt. When ever a vehicle will die it will respawn back.

I think you already know that Cop!
Reply
#3

Did I say CreateObject, I meant CreateVehicle.
Reply
#4

OnVehicleSpawn isn't called for vehicles that have just been created. It's only called when the vehicle RE-spawns.

Try
pawn Код:
new vehicleid = CreateVehicle(...);
OnVehicleSpawn(vehicleid);
Reply
#5

I don't know, but specially for my server, I want OnVehicleSpawn to be called with CreateVehicle, so I just do this

pawn Код:
stock CreateVehicleEx(vehicletype, Float:x, Float:y, Float:z, Float:rotation, color1, color2, respawn_delay)
{
    new id = CreateVehicle(vehicletype, Float:x, Float:y, Float:z, Float:rotation, color1, color2, respawn_delay);
    if(!Iter_Contains(Vehicles, id))
    {
        Iter_Add(Vehicles, id);
    }
    CallRemoteFunction("OnVehicleSpawn", "i", id);
    return id;
}
#define CreateVehicle CreateVehicleEx
if you use 0.3c & vehicle params in OnVehicleSpawn do
pawn Код:
SetTimerEx("OnVehicleSpawn", 5, false, "i", id);
Reply
#6

Thanks for the example, Kar! Say I do this:

pawn Код:
vehicleVars[row][vVehicleServerID] = CreateVehicle
Will it still do the same thing with CreateVehicleEx?


EDIT: Just a quick update. I have the following code under OnVehicleSpawn:

pawn Код:
public OnVehicleSpawn(vehicleid)
{
    print("OVS called.");
    printf("%d|%d|%d|%d|%d|%d|%d", vehicleVariables[vehicleid][vVehicleParams][0], vehicleVariables[vehicleid][vVehicleParams][1], vehicleVariables[vehicleid][vVehicleParams][2], vehicleVariables[vehicleid][vVehicleParams][3], vehicleVariables[vehicleid][vVehicleParams][4], vehicleVariables[vehicleid][vVehicleParams][5], vehicleVariables[vehicleid][vVehicleParams][6]);
    SetVehicleParamsEx(vehicleid, vehicleVariables[vehicleid][vVehicleParams][0], vehicleVariables[vehicleid][vVehicleParams][1], vehicleVariables[vehicleid][vVehicleParams][2], vehicleVariables[vehicleid][vVehicleParams][3], vehicleVariables[vehicleid][vVehicleParams][4], vehicleVariables[vehicleid][vVehicleParams][5], vehicleVariables[vehicleid][vVehicleParams][6]);
    return 1;
}
Now, the params are printing what they should so I'm assuming the vehicle params should be getting set. Am I missing something, because the params aren't setting...?
Reply
#7

remember if it's 0.3c you need the timer, because the bug was fixed in 0.3d.

Otherwise, I have no idea why it's not working for you o.0
Reply
#8

I played around with it a little more and got it to work just fine. It seems that the vehicle ID's were a bit messed up, but that was my fault.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)