Jump to content

checkWeapon


Recommended Posts

Posted

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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

It's a server-side script.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Why do you ask? the problem is on the code i posted.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Do you think i'm a newbie scripter? i have about 1,5 - 2 years scripting in MTA, is that a joke?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

What...?

I use this function on my script like this: if checkWeapon(source,cat,model,slot) then

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

function checkWeapon(player, cat) = checkWeapon(source, "Melee")

function checkWeapon(player, cat, cat2) = checkWeapon(source, "Melee", "Primary")

etc

Ingame nick: Cadu12

Posted

This function checks for what category i want to check, then it checks if i have the weapons and returns true or false.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

That won't work, outputs an error: "attempt to compare number with boolean".

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

This thing is still bugged :roll: , 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 :)

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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