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
Player Weapon Command - GTA Connected

Player Weapon Command

Revision as of 17:44, 3 February 2019 by Mex (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

This code gives a weapon to the player who types the /w weapon ammo active command.
Default weapon id is 21.
Default ammunition is 500.
Default active weapon status is true.

Code

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

addCommandHandler("w", function(cmd,args)
	args = split(args)
	local weapon = tonumber(args[1]) or 21
	local ammo = tonumber(args[2]) or 500
	local active = tonumber(args[3]) ~= 0
	localPlayer:giveWeapon(weapon, ammo, active)
end)

-- https://stackoverflow.com/questions/1426954/split-string-in-lua
function split(inputstr, sep)
	if sep == nil then
		sep = "%s"
	end
	local t={} ; i=1
	for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
		t[i] = str
		i = i + 1
	end
	return t
end