ScriptingExamples/PlayerWeapon: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(No difference)
|
Latest revision as of 17:44, 3 February 2019
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