Jump to content

[HELP] Player and Vehicle Respawn issue


ReZurrecti0n

Recommended Posts

When the player dies in a vehicle from exploding it, the vehicle will respawn and teleport the player along with it. This is because I have the player wait a minute or so before respawning and the vehicle ends up respawning first. So my first attempt was to check if the player who died was in a vehicle, but this check doesn't trigger. Then I thought I would try it the other way around and detect if a player was in the vehicle before it respawned and also failed the check. Although the player is still in the vehicle, after death, it would seem the system considers the player out of any vehicle... I have also tried to freeze the player, but still teleported with the respawning vehicle, it didn't work.

So what I need to do is find a way to respawn the vehicle, but keep the player where he died, any ideas?

function PlayerWasted(ammo,killer,weapon,body,stealth)
	if(isPedInVehicle(source))then
		removePedFromVehicle(source)
	end

Also: When the vehicle does respawn and the player teleports with it, it gives another "Death Sound" as if the player was killed again. In case that info may help any...

Edited by ReZurrecti0n
Addition
Link to comment
  • Moderators
8 hours ago, ReZurrecti0n said:

So what I need to do is find a way to respawn the vehicle, but keep the player where he died, any ideas?

You can also remove the ped from the vehicle even if he is not in a vehicle. The function will simply return false in that case.

Not sure if that solves the whole issue.

You could also re- set the player position with setElementPosition. But remember to disable the warp argument, else they become zombies ?.

https://wiki.multitheftauto.com/wiki/SetElementPosition

 

Edited by IIYAMA
  • Like 1
Link to comment

I'm testing by simply taking a Hydra and blowing itself up. Nothing has worked yet, can't remove the player from the vehicle, nor teleport the player either. I guess because the player is considered dead and not respawned yet. I'm thinking about targeting the vehicle instead, I can use a variable to remember what vehicle the player was in and if that vehicle respawns, cancel the event and respawn it when the player spawns...

Will mess around a bit and try some work arounds, but still open to ideas if anyone has any and will report any results :)

Is anyone familiar with resetVehicleExplosionTime and how it works, exactly? I mean if used to stop the respawn at that point, will it still respawn later?

Edited by ReZurrecti0n
Addition
Link to comment
  • Moderators
1 hour ago, ReZurrecti0n said:

but still open to ideas if anyone

hmmm,

  • Create peds and place them in the vehicle? ?
  • Recreate the vehicle
  • Attach and detach the player on to the vehicle
  • setPedWearingJetpack

  • Respawn the vehicle at the same place where it blew up and move the vehicle to the right position

  • Redirect the player, oh oh this is getting bad... https://wiki.multitheftauto.com/wiki/RedirectPlayer

 

 

  • Thanks 1
Link to comment

that  because  the camera follow the Vehicle

you need unfollow the camera

try the code if this work ...

 

addEventHandler( "onPlayerWasted", getRootElement( ),
	function()
     setCameraMatrix(source,vector3(getElementPosition(source)),vector3(getElementPosition(source)))
	end
  )

 

 

  • Like 1
Link to comment

I had thought of that, but the custom name tag still appears at the new location which led me to believe it wasn't a camera issue, I appreciate the thought though :)

I did resolve my issue with my previous post, now the vehicle doesn't respawn until the player does which I figured was the best fix for it

Edited by ReZurrecti0n
Corrections
  • Like 1
Link to comment
8 minutes ago, ReZurrecti0n said:

I had thought of that, but the custom name tag still appears at the new location which led me to believe it wasn't a camera issue, I appreciate the thought though :)

I did resolve my issue with my previous post, now the vehicle doesn't respawn until the player does which I figured was the best fix for it

what about if you  destroy the player

can you try the code for me,  if  working ?

 

addEventHandler( "onPlayerWasted", getRootElement( ),
    function()
    setCameraMatrix(source,vector3(getElementPosition(source)),vector3(getElementPosition(source)))
    destroyElement(source)
end
)

 

Link to comment

Try this

local respawnTime = 1000*60

addEventHandler("onPlayerWasted", getRootElement(), function()
	local theVehicle = getPedOccupiedVehicle(source)
	if theVehicle then
		removePedFromVehicle(source)
		setTimer(respawnPlayer,respawnTime,1,source,true) -- Here the player will respawn with a vehicle if he was in one
		return --Here we abort the function | The function that comes below won't be executed.
	end
	setTimer(respawnPlayer,respawnTime,1,source,false) -- Here the player will resapwn WITHOUT a vehicle
end)

function respawnPlayer(thePlayer,inVehicle)
	local x,y,z = 0,0,5 -- SET THE CORDINATES YOU WANT
	if inVehicle then
		spawnPlayer(thePlayer, x,y,z+5) -- We move the player a bit up to prevent collision with the vehicle
		local theVehicle = createVehicle(411,x,y,z)
		warpPedIntoVehicle(thePlayer,theVehicle)
		return --Here we abort the function | The function that comes below won't be executed.
	end
	spawnPlayer(thePlayer, x,y,z+3) --Here we don't move the player 5 points up (Just try)
end

Im not sure if this is what you want. As far as I understand, you want that:

When a player dies, if he was in a vehicle then respawn it in a vehicle, otherwise not.

Im using a similar system with it, however, to prevent the creation of a new vehicle im storing them into a table and when the player respawn (In the case that he was a vehicle, restore the vheicle by fixing it ...etc)

Regards.

  • Like 1
Link to comment

I've already resolved the issue...

However, I was unable to detect if a player was in a vehicle from the onwastedplayer event, so I don't think that code would work based on that. My trouble was that the player would teleport with the vehicle the player died in (Blowing up their own vehicle) when the vehicle was respawned. I solved it by simply stopping the vehicle from respawning until the player spawned...

I appreciate your help though, I strive to learn more everyday :)

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