Notice: Failed to invoke Pygments: [Called from MediaWiki\SyntaxHighlight\SyntaxHighlight::highlightInner in /home/pi/www/gtac/wiki/wiki/extensions/SyntaxHighlight_GeSHi/includes/SyntaxHighlight.php at line 334] in /home/pi/www/gtac/wiki/wiki/includes/debug/MWDebug.php on line 507
Custom Cheats without a Time Restriction - GTA Connected

Custom Cheats without a Time Restriction

Description

This code allows scripters to easily add custom cheat phrases, without a required delay between key presses.

Code

Lua, Client-Side:

-- initialization
cheats = {}
cheats.maxBufferLength = 100
cheats.buffer = ''
cheats.hits = {}

-- events
addEventHandler('onCharacter', function(event,text)
	cheats.addToBuffer(text)
	cheats.checkToTriggerCheat()
end)

-- api
function cheats.addToBuffer(text)
	cheats.buffer = (cheats.buffer:len() == cheats.maxBufferLength and cheats.buffer:sub(2) or cheats.buffer) .. text:lower()
end

function cheats.checkToTriggerCheat()
	for i=1,cheats.buffer:len() do
		local text = cheats.buffer:sub(i)
		if cheats.hits[text] then
			cheats.hits[text]()
			cheats.buffer = ''
			break
		end
	end
end

-- cheats
function cheats.hits.maxhp()
	localPlayer.health = 100.0
end

function cheats.hits.die()
	localPlayer.health = 0.0
end