Jump to content

Getting weapon name


DarkByte

Recommended Posts

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

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

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

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...