Jump to content

Weapon tables


Drakath

Recommended Posts

I have a table of weapons.

It is set like this:

local weapon = getPedWeapon(p, slot) 
weapons[weapon] = myStuff 

I have another table retrieved from a useful function: "getPedWeapons". (It can be found on Wiki)

How can I check if every weapon from table: "getPedWeapons" matches weapons from my table: "weapons" and remove every weapon that does not match?

Link to comment
function RemoveUnmatchedWeapon(Player,Table) 
    for Slot = 0,12 do 
        local WeaponID = getPedWeapon(Player,Slot) 
        if not (WeaponID == Table[Slot]) then 
            takeWeapon(Player,WeaponID) 
        end 
    end 
end 
  
function GetWeaponsTable(Player) 
    local Table = {} 
    for Slot = 0,12 do 
        Table[Slot] = getPedWeapon(Player,Slot) 
    end 
    return Table 
end 

To get player's weapons table use GetWeaponsTable, and to remove weapons of other player that don't match use RemoveUnmatchedWeapon.

Link to comment

There still is a problem,

table.insert ( myTable [ thePlayer ], { "Hello", "World" } ) 

will only insert values to one table.

My script should work like this:

--Code removed. 

However, it doesn't. With Solidsnake14 line I could only do this for one weapon slot and there are 12.

Is there a way to do this with one table or should I create 12 tables for every player?

Edited by Guest
Link to comment

What I showed only uses one table per player. Your code doesn't work because you're setting myTable[ client ][ weaponSlot ] to a table whose first index is the element, then you check if myTable[ client ][ weaponSlot ] is an element, which it isn't. You should rather set the value of myTable[ client ][ weaponSlot ] to the element or check if the index 1 in the table myTable[ client ][ weaponSlot ] is an element.

local myTable = {} 
  
myTable[ client ] = {} 
myTable[ client ][ weaponSlot ] = element 

Edited by Guest
Link to comment

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