Jump to content

Hello, about automatic respawning.


zONEz

Recommended Posts

function respawnDeadPlayer() 
        setPedAnimation(source, CRACK, crckdeth1, 9000, true) 
        outputChatBox("Yaralandin!!!",source,255,0,0) 
        fadeCamera(source, false, 7) 
        setTimer(respawnPlayerAfterDied, 10000, 1,source) 
end 
addEventHandler("onPlayerWasted", root, respawnDeadPlayer) 

function respawnPlayerAfterDied(p) 
        local x,y,z = getElementPosition(thePlayer)
        spawnPlayer(posX="x" posY="y" posZ="z") 
        fadeCamera(p, true, 5) 
        outputChatBox("Tedavi oldun, hadi yine iyisin.",p,255,0,0) 
end

I've took this code from the one of the topic from the this forum. I've made, few kind of changes in it. (Pls let me know or debug the code if i have a problem in the code) On the "Play" gamemode when the play dies, this code works and timing is works but when spawning section comes, player spawns on LS hospital and warps to another location. I think, play spawning 2 times. I want the when player dies, player re spawns on his death location. How can i, disable the "Play" gamemode respawning function?

Link to comment

Hello and welcome to the Forums!

To disable the respawn function in "play" gamemode ( resources/[gamemodes]/play ) you will have to edit the broph.lua file.
You can simply comment/remove the 5 lines where the even handler is added.

addEventHandler("onPlayerWasted", root,
	function()
		--setTimer(spawn, 1800, 1, source) -- you can comment it like this to prevent it from running
	end
)

 

Also in your function respawnPlayerAfterDied the arguments in the spawnPlayer function are wrong. Please check the wiki documentation.

It should be something like this:

function respawnPlayerAfterDied(p) 
        local x,y,z = getElementPosition(p) -- changed from "thePlayer" to "p"
        spawnPlayer(p, x, y, z) -- corrected the arguments
        fadeCamera(p, true, 5) 
        outputChatBox("Tedavi oldun, hadi yine iyisin.",p,255,0,0) 
end

 

  • Sad 1
Link to comment

@SpecTThank you so much ❤️

local vehiclesToSpawn =
{
	
}

local spawnpoints =
{
	{-11.054133415222,2329.2023925781,24.303375244141,90},
	{-18.531280517578,2323.3835449219,24.303373336792,270},
	{-27.869777679443,2321.8896484375,24.303373336792,0},
	{-10.329539299011,2336.9331054688,24.303375244141,128},
}

local vehicleDestroyTimers = {}
local validSkins = {60}
local playerVehicles = {}

local function spawn(player)

	if player and isElement(player) then
		local x,y,z,r = unpack(spawnpoints[math.random(1,#spawnpoints)])
		spawnPlayer(player,x+math.random(-3,3),y+math.random(-3,3),z,r,validSkins[math.random(1,#validSkins)],0,0)
		fadeCamera(player, true)
		setCameraTarget(player, player)
	end
end

local function onJoin()

	spawn(source)

end

local function destroyPlayerVehicles()

	local vehicles = playerVehicles[source]

	for _,vehicle in ipairs(vehicles) do
		if isElement(vehicle) then
			destroyElement(vehicle)
		end
	end

	playerVehicles[source] = nil

end

local function onEnter(player)

	local t = tonumber(get("vehicleRespawnTime")) or 60000
	source.damageProof = false
	source.frozen = false
	local vehicledata = vehiclesToSpawn[source]
	setTimer(createNewVehicle,(t > 50 and t or 50),1,vehicledata)
	vehiclesToSpawn[source] = nil
	if not playerVehicles[player] then
		playerVehicles[player] = {}
		addEventHandler("onPlayerQuit",player,destroyPlayerVehicles)
	end
	table.insert(playerVehicles[player],source)
	removeEventHandler("onVehicleEnter",source,onEnter)

end

local function destroyVehicle(vehicle)

	if vehicle and isElement(vehicle) and getElementType(vehicle) == "vehicle" then
		destroyElement(vehicle)
	end
end

local function destroyTimer()

	if vehicleDestroyTimers[source] and isTimer(vehicleDestroyTimers[source]) then killTimer(vehicleDestroyTimers[source]) end
	removeEventHandler("onVehicleEnter",source,destroyTimer)

end

local function onExit()

	local t = tonumber(get("vehicleExpireTime")) or 600000
	vehicleDestroyTimers[source] = setTimer(destroyVehicle,(t > 50 and t or 50),1,source)
	addEventHandler("onVehicleEnter",source,destroyTimer)

end

function createNewVehicle(vehicledata)

	local m,x,y,z,r = unpack(vehicledata)
	local vehicle = Vehicle(m,x,y,z,0,0,r)
	vehicle.damageProof = true
	vehicle.frozen = true
	vehiclesToSpawn[vehicle] = vehicledata
	addEventHandler("onVehicleEnter",vehicle,onEnter)
	addEventHandler("onVehicleExit",vehicle,onExit)

end

local function initScript()

	resetMapInfo()
	local players = getElementsByType("player")

	for _,player in ipairs(players) do spawn(player) end
	for _,vehicledata in ipairs(vehiclesToSpawn) do createNewVehicle(vehicledata) end

	addEventHandler("onPlayerJoin",root,onJoin)
	addEventHandler("onPlayerWasted",root,onWasted)

end

addEventHandler("onResourceStart",resourceRoot,initScript)

My broph.lua's original codes are like this. When i edit it as you say, it becomes like this;

local vehiclesToSpawn =
{
	
}

local spawnpoints =
{
	{-11.054133415222,2329.2023925781,24.303375244141,90},
	{-18.531280517578,2323.3835449219,24.303373336792,270},
	{-27.869777679443,2321.8896484375,24.303373336792,0},
	{-10.329539299011,2336.9331054688,24.303375244141,128},
}

local vehicleDestroyTimers = {}
local validSkins = {60}
local playerVehicles = {}

local function spawn(player)

	if player and isElement(player) then
		local x,y,z,r = unpack(spawnpoints[math.random(1,#spawnpoints)])
		spawnPlayer(player,x+math.random(-3,3),y+math.random(-3,3),z,r,validSkins[math.random(1,#validSkins)],0,0)
		fadeCamera(player, true)
		setCameraTarget(player, player)
	end
end

local function onJoin()

	spawn(source)

end

local function destroyPlayerVehicles()

	local vehicles = playerVehicles[source]

	for _,vehicle in ipairs(vehicles) do
		if isElement(vehicle) then
			destroyElement(vehicle)
		end
	end

	playerVehicles[source] = nil

end

local function onEnter(player)

	local t = tonumber(get("vehicleRespawnTime")) or 60000
	source.damageProof = false
	source.frozen = false
	local vehicledata = vehiclesToSpawn[source]
	setTimer(createNewVehicle,(t > 50 and t or 50),1,vehicledata)
	vehiclesToSpawn[source] = nil
	if not playerVehicles[player] then
		playerVehicles[player] = {}
		addEventHandler("onPlayerQuit",player,destroyPlayerVehicles)
	end
	table.insert(playerVehicles[player],source)
	removeEventHandler("onVehicleEnter",source,onEnter)

end

local function destroyVehicle(vehicle)

	if vehicle and isElement(vehicle) and getElementType(vehicle) == "vehicle" then
		destroyElement(vehicle)
	end
end

local function destroyTimer()

	if vehicleDestroyTimers[source] and isTimer(vehicleDestroyTimers[source]) then killTimer(vehicleDestroyTimers[source]) end
	removeEventHandler("onVehicleEnter",source,destroyTimer)

end

local function onExit()

	local t = tonumber(get("vehicleExpireTime")) or 600000
	vehicleDestroyTimers[source] = setTimer(destroyVehicle,(t > 50 and t or 50),1,source)
	addEventHandler("onVehicleEnter",source,destroyTimer)

end

function createNewVehicle(vehicledata)

	local m,x,y,z,r = unpack(vehicledata)
	local vehicle = Vehicle(m,x,y,z,0,0,r)
	vehicle.damageProof = true
	vehicle.frozen = true
	vehiclesToSpawn[vehicle] = vehicledata
	addEventHandler("onVehicleEnter",vehicle,onEnter)
	addEventHandler("onVehicleExit",vehicle,onExit)

end

local function initScript()

	resetMapInfo()
	local players = getElementsByType("player")

	for _,player in ipairs(players) do spawn(player) end
	for _,vehicledata in ipairs(vehiclesToSpawn) do createNewVehicle(vehicledata) end

	addEventHandler("onPlayerJoin",root,onJoin)
	addEventHandler("onPlayerWasted", root,
	function()
		--setTimer(spawn, 1800, 1, source) -- you can comment it like this to prevent it from running
	end
)

end

addEventHandler("onResourceStart",resourceRoot,initScript)

But my player is still respwaning on the LS hospital.

function respawnPlayerAfterDied(p) 
        local x,y,z = getElementPosition(p) -- changed from "thePlayer" to "p"
        spawnPlayer(p, x, y, z) -- corrected the arguments
        fadeCamera(p, true, 5) 
        outputChatBox("Tedavi oldun, hadi yine iyisin.",p,255,0,0) 
end

I've add this script though.

Link to comment

Hey,

Sorry about the incorrect info about the broph.lua file. I had an older version of the play resource.

This should be the code of broph.lua :

local vehiclesToSpawn =
{
	
}

local spawnpoints =
{
	{-11.054133415222,2329.2023925781,24.303375244141,90},
	{-18.531280517578,2323.3835449219,24.303373336792,270},
	{-27.869777679443,2321.8896484375,24.303373336792,0},
	{-10.329539299011,2336.9331054688,24.303375244141,128},
}

local vehicleDestroyTimers = {}
local validSkins = {60}
local playerVehicles = {}

local function spawn(player)

	if player and isElement(player) then
		local x,y,z,r = unpack(spawnpoints[math.random(1,#spawnpoints)])
		spawnPlayer(player,x+math.random(-3,3),y+math.random(-3,3),z,r,validSkins[math.random(1,#validSkins)],0,0)
		fadeCamera(player, true)
		setCameraTarget(player, player)
	end
end

local function onJoin()

	spawn(source)

end

local function onWasted()

	local t = tonumber(get("playerRespawnTime")) or 5000
	setTimer(spawn,(t > 50 and t or 50),1,source)

end

local function destroyPlayerVehicles()

	local vehicles = playerVehicles[source]

	for _,vehicle in ipairs(vehicles) do
		if isElement(vehicle) then
			destroyElement(vehicle)
		end
	end

	playerVehicles[source] = nil

end

local function onEnter(player)

	local t = tonumber(get("vehicleRespawnTime")) or 60000
	source.damageProof = false
	source.frozen = false
	local vehicledata = vehiclesToSpawn[source]
	setTimer(createNewVehicle,(t > 50 and t or 50),1,vehicledata)
	vehiclesToSpawn[source] = nil
	if not playerVehicles[player] then
		playerVehicles[player] = {}
		addEventHandler("onPlayerQuit",player,destroyPlayerVehicles)
	end
	table.insert(playerVehicles[player],source)
	removeEventHandler("onVehicleEnter",source,onEnter)

end

local function destroyVehicle(vehicle)

	if vehicle and isElement(vehicle) and getElementType(vehicle) == "vehicle" then
		destroyElement(vehicle)
	end
end

local function destroyTimer()

	if vehicleDestroyTimers[source] and isTimer(vehicleDestroyTimers[source]) then killTimer(vehicleDestroyTimers[source]) end
	removeEventHandler("onVehicleEnter",source,destroyTimer)

end

local function onExit()

	local t = tonumber(get("vehicleExpireTime")) or 600000
	vehicleDestroyTimers[source] = setTimer(destroyVehicle,(t > 50 and t or 50),1,source)
	addEventHandler("onVehicleEnter",source,destroyTimer)

end

function createNewVehicle(vehicledata)

	local m,x,y,z,r = unpack(vehicledata)
	local vehicle = Vehicle(m,x,y,z,0,0,r)
	vehicle.damageProof = true
	vehicle.frozen = true
	vehiclesToSpawn[vehicle] = vehicledata
	addEventHandler("onVehicleEnter",vehicle,onEnter)
	addEventHandler("onVehicleExit",vehicle,onExit)

end

local function initScript()

	resetMapInfo()
	local players = getElementsByType("player")

	for _,player in ipairs(players) do spawn(player) end
	for _,vehicledata in ipairs(vehiclesToSpawn) do createNewVehicle(vehicledata) end

	addEventHandler("onPlayerJoin",root,onJoin)
	-- addEventHandler("onPlayerWasted",root,onWasted) -- commenting this will stop respawning the player

end

addEventHandler("onResourceStart",resourceRoot,initScript)

 

It should work just fine now.

Edited by SpecT
Link to comment

Player is still spawning on LS hospital.

function respawnDeadPlayer() 
        setPedAnimation(source, CRACK, crckdeth1, 9000, true) 
        outputChatBox("Yaralandin!!!",source,255,0,0) 
        fadeCamera(source, false, 7) 
        setTimer(respawnPlayerAfterDied, 10000, 1,source) 
end 
addEventHandler("onPlayerWasted", root, respawnDeadPlayer) 

function respawnPlayerAfterDied(p) 
        local x,y,z = getElementPosition(p) -- changed from "thePlayer" to "p"
        spawnPlayer(p, x, y, z) -- corrected the arguments
        fadeCamera(p, true, 5) 
        outputChatBox("Tedavi oldun, hadi yine iyisin.",p,255,0,0) 
end

That's my .lua code for respawning side. broph.lua file is same as your file. What is wrong?

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