DarkByte Posted October 20, 2015 Share Posted October 20, 2015 Hi, i made this script to get weapons from tables but its not working. othertable = { [24] = "Deagle", [26] = "Model 1887", [31] = "M4A1" } function giveWeaponCommand(cmd, weapon, amount) weapon = tonumber(weapon) or othertable[getWeaponNameFromID(weapon)] if not weapon then return end amount = amount and tonumber(amount) or 500 server.giveMeWeapon(math.floor(weapon), amount) end addCommandHandler('give', giveWeaponCommand) addCommandHandler('wp', giveWeaponCommand) Link to comment
AMARANT Posted October 20, 2015 Share Posted October 20, 2015 Your table indexes are numbers. How are you going to retrieve the data if you set function getWeaponNameFromId as a key of your table othertable (line 8 )? And you missed the argument 'player' in your function giveWeaponCommand. Link to comment
Fist Posted October 20, 2015 Share Posted October 20, 2015 here is my example. weaponTable = { -- {weaponid,"weaponname"} {24,"Deagle"}, {26,"Model 1887"}, {31,"M4A1"}, } function giveWeaponCommand(source, cmd, weapon, amount) for _,value in ipairs(weaponTable) do if weapon ~= nil then if value[1] == tonumber(weapon) and amount ~= nil then outputChatBox("Your weapon is '"..value[2].."' and amount is '"..amount.."'",source) end end end end addCommandHandler('give', giveWeaponCommand) Link to comment
HUNGRY:3 Posted October 21, 2015 Share Posted October 21, 2015 Not working I bet you used it in client side Link to comment
HUNGRY:3 Posted October 21, 2015 Share Posted October 21, 2015 Yes What are you waiting for? just put it in server side Link to comment
DBY Posted October 21, 2015 Share Posted October 21, 2015 Try this: table = { [24] = "Deagle", [26] = "Model 1887", [31] = "M4A1" } function giveWeaponCommand(p, c, w, a) if tonumber(w) then if table[tonumber(w)] ~= nil then local ammo = tonumber(a) or 500 if giveWeapon(p, w, ammo) then outputChatBox("¡New weapon!, is '" .. table[tonumber(w)] .. "' with '" .. ammo .. "' of ammo.", p, 255, 255, 0) end else outputChatBox("The inserted ID is invalid, try again.", p, 255, 0, 0) end else outputChatBox("Syntax: /" .. c .. " [weapon] [amount]", p, 255, 255, 255) end end addCommandHandler("wp", giveWeaponCommand) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now