joao2235 Posted September 4, 2019 Share Posted September 4, 2019 Sorry by my english. I need to get a value with the whole number of weapons the player has. (Whole Number from player's weapon). I'm trying to do this, but with no sucess: function getPedWeapons(ped) local playerWeapons = {} if ped and isElement(ped) and getElementType(ped) == "ped" or getElementType(ped) == "player" then for i=2,9 do local wep = getPedWeapon(ped,i) if wep and wep ~= 0 then table.insert(playerWeapons,wep) end end else return false end return playerWeapons end function SaberArmas (player) outputChatBox("Armas (Caso tenha armas elas serão listadas abaixo!)",player,255,0,0) for i,wep in ipairs(getPedWeapons(player)) do outputChatBox("Você tem: " .. getWeaponNameFromID(wep),player,0,255,0) end end addEventHandler("onMarkerHit", MarkerInfo, SaberArmas) The script is making a list not a Whole Number. Someone can help me ? Link to comment
WorthlessCynomys Posted September 4, 2019 Share Posted September 4, 2019 Hy. Try: #getPedWeapons On number indexed tables/arrays # returns the count of values in an array. Link to comment
joao2235 Posted September 4, 2019 Author Share Posted September 4, 2019 I did it: function getPedWeapons(ped) local playerWeapons = {} if ped and isElement(ped) and getElementType(ped) == "ped" or getElementType(ped) == "player" then for i=2,9 do local wep = getPedWeapon(ped,i) if wep and wep ~= 0 then table.insert(playerWeapons,wep) end end else return false end return playerWeapons end function SaberArmas (player) qtdArmas = 0 for i,wep in ipairs(getPedWeapons(player)) do qtdArmas = i end if qtdArmas > 0 then outputChatBox("Você tem: " ..qtdArmas.. " armas") else outputChatBox("Você não tem nenhum armamento!") end end addEventHandler("onMarkerHit", MarkerInfo, SaberArmas) 100% Working. 15 hours ago, WorthlessCynomys said: Hy. Try: #getPedWeapons On number indexed tables/arrays # returns the count of values in an array. I did not tested it, but thanks!^^ 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