Replying to this old topic because it popped up while I was browsing and it irked me. Please don’t take offense, I just want to pass on my opinion and advice. I hardly reply or post in these forums and I really should do so more, especially for support to those that are in need, or to those with terrific releases that they share for free. So I am probably a hypocrite, but honestly I just feel compelled to reply in this case because this stuff bugs me a fair bit.
Firstly, this is not really a modding tutorial, so it’s probably in the wrong category. Second, why is this being shared as a resource/script? Why wouldn’t it be a code block? I get that people like to share things that are “plug & play” but that leads to people that can’t code, becoming “developers” and server owners, and we’ve seen the result when that happens… So I feel stuff like this shouldn’t be a release, but just a code block to be added somewhere. Here is said code.
-- Notify Function [DO NOT TOUCH]! --
function notify(string)
SetNotificationTextEntry("STRING")
AddTextComponentString(string)
DrawNotification(true, false)
end
gun = args
RegisterCommand("weapon", function(source, args, rawCommand)
GiveWeaponToPed(PlayerPedId(), "weapon_"..args[1], 250, false, true)
notify("~g~You have been given a ~b~"..rawCommand.."~b~.")
end)
Very basic, includes an unused variable, etc. It also means that anyone can spawn any gun and it doesn’t do any checks for validity. Here is another version that includes valid weapon checks, allows you to enter “weapon_pistol” or just “pistol”, takes an optional second argument for a custom ammo quantity, notifies the player if there are issues & allows you to set it to admins only.
function Notify(msg)
SetNotificationTextEntry("STRING")
AddTextComponentString(msg)
DrawNotification(true, false)
end
local adminsOnly = false -- If true, command is only for admins
RegisterCommand("weapon", function(source, args)
if next(args) then
args[1] = args[1]:lower()
local weaponName = args[1]:sub(1, 7) == "weapon_" and args[1] or "weapon_"..args[1]
local weaponLabel = weaponName:sub(8):upper()
if IsWeaponValid(`weaponName`) then
local ammo = (args[2] ~= nil and tonumber(args[2]) ~= nil) and tonumber(args[2]) or 250
GiveWeaponToPed(PlayerPedId(), `weaponName`, ammo, false, true)
Notify(("~g~You have been given a ~b~%s"):format(weaponLabel))
else
Notify(("~b~%s~r~ is an invalid weapon"):format(weaponLabel))
end
else
Notify("~r~Error!~s~ Usage: /weapon [weapon] [ammo]")
end
end, adminsOnly)
Hopefully it’s useful and my feedback doesn’t offend. I just want to see a better standard for releases. Seen too many bad habits. But again, that’s just my opinion. Hope this helps some people. Peace!
P.S. I touched the notify function 