xyz Posted March 11, 2016 Share Posted March 11, 2016 (edited) So I'm making a script but wondering how do I check if someone has a weapon, if he does then do something. For example, if someone does /ak, then if the someone has AK-47, something happens. Thanks in advance Edited March 11, 2016 by Guest Link to comment
xyz Posted March 11, 2016 Author Share Posted March 11, 2016 getPedWeaponGood luck! No I mean like not the current slot, get the AK from all of his weapons that he has. I tried using that but it only worked for the current weapon slot. Link to comment
Captain Cody Posted March 11, 2016 Share Posted March 11, 2016 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 https://wiki.multitheftauto.com/wiki/GetPedWeapons Returns a table From this you have 2 options A: Check if the weapon is in that table B: Simplify the code above and combine it into the code you are working on, and make it return true / false if it finds that weapon. Link to comment
xyz Posted March 11, 2016 Author Share Posted March 11, 2016 function removeak(player) takeWeapon(player, 30) end addCommandHandler("removeak", removeak) Here's the script I want it to check if the player has AK, if he has then remove it. If not, then output to chatbox that he doesn't have an AK. Could you make this into it? I don't really understand tables yet. Link to comment
ozulus Posted March 11, 2016 Share Posted March 11, 2016 I did it on my mobile phone, so i didn't test it. function removeak(player) if hasPedWeapon(player, 30) then takeWeapon(player, 30) end end addCommandHandler("removeak", removeak) function hasPedWeapon(ped, weaponID) if ped and isElement(ped) and getElementType(ped) == "ped" or getElementType(ped) == "player" and weaponID then for i=2,9 do local wep = getPedWeapon(ped,i) if wep and wep == weaponID then return true end end end return false end 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