Jump to content

Custom Weapon Name


itHyperoX

Recommended Posts

Posted

Hi, i making a custom weapon name script, but i got some errors. I tried 4 hours to fix, but i dont know whats wrong.

 

local WeaponNames =
{
    [16] = "Nade",
    [24] = "One Deag"
}
function getWeaponRealName(weapon)
    if weapon then
        local weaponmodel = getWeaponNameFromID(weapon)
        if WeaponNames[weaponmodel] then
            return WeaponNames[weaponmodel]
        else
            return getWeaponIDFromName(weaponmodel)
        end
    end
end

Export:

outputChatBox("#FFFFFF You picked up the ammo. #6F9F86(".. theAmmo ..") #ffffffCustomWeaponName: #6F9F86("..exports.serverFiles:getWeaponRealName(weaponID)..")",player,255,255,255,true)

Pics

 

And i'm gettint this on chat: You picked up the ammo. (20) CustomWeaponName: (0)

 

Thanks any help

 

Posted

So your table keys are the weapon ID's, so what is this for?

local weaponmodel = getWeaponNameFromID(weapon)

Shouldn't it be

if WeaponNames[weapon] then 
  return WeaponNames[weapon]

 

Posted
local WeaponNames =
{
    [16] = "Nade",
    [24] = "One Deag"
}
function getWeaponRealName(weapon)
    if weapon then
if WeaponNames[weapon] then 
  return WeaponNames[weapon]
        else
            return getWeaponIDFromName(weaponmodel)
        end
    end
end

 

208. line is the "else"

Posted (edited)
return getWeaponIDFromName(weaponmodel) 

Where is weaponmodel defined? Looks like you misunderstand that function. It gets the weaponID from the name, not the name from the ID. Use

return getWeaponNameFromID(weapon)

instead

Edited by pa3ck
  • MTA Team
Posted (edited)
local WeaponNames =
{
    [16] = "Nade",
    [24] = "One Deag"
}
function getWeaponRealName(weapon)
    if weapon then
        if WeaponNames[weapon] then
            return WeaponNames[weapon]
        else
            return getWeaponNameFromID(weapon)
        end
    end
end

 

Edited by LopSided_

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