SA-MP Forums Archive
OnVehicleSpawn - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnVehicleSpawn (/showthread.php?tid=312331)



OnVehicleSpawn - Scenario - 21.01.2012

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.


Re: OnVehicleSpawn - Ballu Miaa - 21.01.2012

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!


Re: OnVehicleSpawn - Scenario - 21.01.2012

Did I say CreateObject, I meant CreateVehicle.


Re: OnVehicleSpawn - Psymetrix - 21.01.2012

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);



Re: OnVehicleSpawn - Kar - 21.01.2012

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);



Re: OnVehicleSpawn - Scenario - 21.01.2012

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...?


Re: OnVehicleSpawn - Kar - 22.01.2012

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


Re: OnVehicleSpawn - Scenario - 22.01.2012

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.