Jump to content

Vehicle Respawn


xbenny2506x

Recommended Posts

HI!

I have a problem with the vehicle respawn.

When the player use /kill in the vehicle and when the player leave the server in the vehicle the respawn vehicle not work :(

I have all my vehicles in a .map file.

Here is the script:

xmlRoot = xmlLoadFile("settings.xml");
 
explRespawn = tonumber( xmlNodeGetAttribute( xmlFindChild(xmlRoot,"explrespawn",0) ,"value") );
idleRespawn = tonumber( xmlNodeGetAttribute( xmlFindChild(xmlRoot,"idlerespawn",0) ,"value") );
 
idleTimers = {}
 
--
 
 
 
function respawnVehicle(vehicle)
 
if vehicle == nil then return; end;
if getElementType(vehicle) ~= "vehicle" then return; end;
 
sx = getElementData(vehicle,"posX");
sy = getElementData(vehicle,"posY");
sz = getElementData(vehicle,"posZ");
rx = getElementData(vehicle,"rotX");
ry = getElementData(vehicle,"rotY");
rz = getElementData(vehicle,"rotZ");
 
spawnVehicle ( vehicle,sx, sy, sz, rx, ry, rz )
 
end
 
function ehVehicleEnter()
 
local tmr = idleTimers[source];
if  tmr ~= nil and tmr ~= false then
 
killTimer( tmr );
	idleTimers[source] = nil;
end
 
end; addEventHandler ( "onVehicleEnter", getRootElement(), ehVehicleEnter );
 
 
function ehVehicleExit()
 
idleTimers[source] = setTimer ( respawnVehicle, idleRespawn * 1000, 1, source );
 
end; addEventHandler ( "onVehicleExit", getRootElement(), ehVehicleExit );
 
 
function ehVehicleExplode()
 
setTimer ( respawnVehicle, explRespawn * 1000, 1, source )
 
end;
 
addEventHandler ( "onVehicleExplode", getRootElement(), ehVehicleExplode );
 
 
function ehResStart()
 
vehs = getElementsByType ( "vehicle" )
for key,veh in ipairs(vehs) do
	ProcessVehicle(veh);
end
 
end
 
 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), ehResStart )

I hope someone can help me with that 2 problems! THX :D

Link to comment

ok i have test now that

function vehiclekill ( player ) 
if getElementType ( player ) == "player" then
if getPedOccupiedVehicle ( player ) then
local vehicle = getPedOccupiedVehicle ( player )
blowVehicle ( vehicle )
end
end
end
addCommandHandler ( "kill", vehiclekill )

but nothing the vehicle dont explode when the player use /kill

Link to comment

I have make this now :)

function vehiclekillboom ( thePlayer )
if (getElementType(thePlayer) == "player") then
local vehicle = getPedOccupiedVehicle ( thePlayer )
if getPedOccupiedVehicle ( thePlayer ) then
if getVehicleOccupant ( vehicle ) then
blowVehicle ( vehicle )
else
killPed(thePlayer, thePlayer)
end
else
killPed(thePlayer, thePlayer)
end
end
end
addCommandHandler ( "kill", vehiclekillboom )

When someone copy this, and the freeroam gui is on this server make the "kill" command in the freeroam gui off!

When the player leave the server the vehicle explode: (serverside!)

function quitPlayer ()
local vehiclequite = getPedOccupiedVehicle ( source )
if getPedOccupiedVehicle ( source ) then
if getVehicleOccupant ( vehiclequite ) then
blowVehicle ( vehiclequite )
end
end
end
addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer )

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...