Jump to content

Getting weapon name


DarkByte

Recommended Posts

Posted

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) 

When I hear someone saying Mac is better than PC.

o0pjNKG.gif w0t?VeJXjxD.gifw0t? evspcFJ.gifw0t?

Great minds discuss ideas, average minds discuss events and small minds discuss people.

Posted

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.

Posted

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) 
  

Posted

Not working

When I hear someone saying Mac is better than PC.

o0pjNKG.gif w0t?VeJXjxD.gifw0t? evspcFJ.gifw0t?

Great minds discuss ideas, average minds discuss events and small minds discuss people.

Posted

Yes

When I hear someone saying Mac is better than PC.

o0pjNKG.gif w0t?VeJXjxD.gifw0t? evspcFJ.gifw0t?

Great minds discuss ideas, average minds discuss events and small minds discuss people.

Posted

Not working ;(

When I hear someone saying Mac is better than PC.

o0pjNKG.gif w0t?VeJXjxD.gifw0t? evspcFJ.gifw0t?

Great minds discuss ideas, average minds discuss events and small minds discuss people.

Posted

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) 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...