Castillo Posted May 5, 2011 Posted May 5, 2011 Hey there, i don't use to ask for help, but right now i'm a bit confused, this function keeps returning wrong, function checkWeapon(player,cat) melee = {1,10} primary = {3,5,6} secondary = {2,4} projectiles = {7,8} if cat == "Melee" then for i,v in pairs(melee) do if getPedTotalAmmo ( player, v ) == 0 then return true else outputChatBox("You already have a weapon of this category!",player,255,0,0) return false end end elseif cat == "Primary" then for i,v in pairs(primary) do if getPedTotalAmmo ( player, v ) == 0 then return true else outputChatBox("You already have a weapon of this category!",player,255,0,0) return false end end elseif cat == "Secondary" then for i,v in pairs(secondary) do if getPedTotalAmmo ( player, v ) == 0 then return true else outputChatBox("You already have a weapon of this category!",player,255,0,0) return false end end elseif cat == "Projectiles" then for i,v in pairs(projectiles) do if getPedTotalAmmo ( player, v ) == 0 then return true else outputChatBox("You already have a weapon of this category!",player,255,0,0) return false end end end end It's used to check if i have a weapon in the desired category or not, but somehow it keeps returning that i don't have, any help is appreciated. Thanks in advance.
Castillo Posted May 5, 2011 Author Posted May 5, 2011 Why do you ask? the problem is on the code i posted.
Castillo Posted May 5, 2011 Author Posted May 5, 2011 Do you think i'm a newbie scripter? i have about 1,5 - 2 years scripting in MTA, is that a joke?
Castillo Posted May 5, 2011 Author Posted May 5, 2011 What...? I use this function on my script like this: if checkWeapon(source,cat,model,slot) then
Cadu12 Posted May 5, 2011 Posted May 5, 2011 function checkWeapon(player, cat) = checkWeapon(source, "Melee") function checkWeapon(player, cat, cat2) = checkWeapon(source, "Melee", "Primary") etc
Castillo Posted May 5, 2011 Author Posted May 5, 2011 This function checks for what category i want to check, then it checks if i have the weapons and returns true or false.
Cadu12 Posted May 5, 2011 Posted May 5, 2011 Change to "if not getPedTotalAmmo ( player, v ) >= 1 then" in your function.
Castillo Posted May 5, 2011 Author Posted May 5, 2011 That won't work, outputs an error: "attempt to compare number with boolean".
Cadu12 Posted May 5, 2011 Posted May 5, 2011 Try "if not tonumber(getPedTotalAmmo ( player, v )) >= 1 then"
Castillo Posted May 5, 2011 Author Posted May 5, 2011 lol, i tryied that already, now i'm using this: if getPedTotalAmmo ( player, v ) == 0 or not getPedTotalAmmo(player) or not getPedWeapon(player,v) then, for now seems to work, but it may get buggy after a while.
Castillo Posted May 5, 2011 Author Posted May 5, 2011 Uhm, no.. i've closed my RPG server long time ago, remade some stuff from it some weeks ago, but nothing else, still thinking if i will re-open it or not, but this script isn't for me really, just for my client (working for a guy for $$).
Castillo Posted May 6, 2011 Author Posted May 6, 2011 This thing is still bugged , i'm out of ideas, i don't know why it won't work, here's the new code. Edit: Remp helped me in the IRC channel, and seems to work fine his code, thanks to everyone, specially to Remp
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