ScriptingExamples/PlayerDelayedHeal: Difference between revisions

From GTA Connected
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:Player Delayed Heal and Fix Command}} == Description == This code sets the player's health and armour to 100, and their vehicle health to 1000 and components fi...")
 
(No difference)

Latest revision as of 21:04, 14 August 2018

Description

This code sets the player's health and armour to 100, and their vehicle health to 1000 and components fixed, 1.5 seconds after the player types /heal2.

Code

Lua, Client-Side, GTAC versions 1.0.72 and newer:

addCommandHandler('heal2', function(cmd, args)
	if heal2Timer then return end
	local heal2Timer
	local function clearHeal2Timer(event, reason)
		if not heal2Timer then return end
		clearTimeout(heal2Timer)
		heal2Timer = nil
	end
	heal2Timer = setTimeout(function()
		if not heal2Timer then return end
		removeEventHandler('onDisconnect', clearHeal2Timer)
		heal2Timer = nil
		if localPlayer.vehicle then
			localPlayer.vehicle.health = 1000
			localPlayer.vehicle:fix()
		end
		localPlayer.health = 100
		localPlayer.armour = 100
	end, 1500)
	addEventHandler('onDisconnect', clearHeal2Timer)
end)