Jump to content

Weapon tables


Drakath

Recommended Posts

Posted

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?

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

Posted

I'm not sure if that will work, but you can do something like this.

Table = {} 
Table["something"] = {} 
local Table2 = Table["something"] 
Table2["something else"] = 11 
Table["something"] = Table2 

Posted

table = {{anothertable}}

Example:

table1 = { 
{"NamePlayer1", "Weapon", ammo}, 
{"NamePlayer2", "Weapon", ammo}, 
} 

EDIT: To insert that, use:

table.insert(table1, {"MyName", "AK-47", 11}) 

Posted

I need to create a table for every player and that table should have another 10 tables which would be equal to some number my script specifies.

Posted
local myTable = { } -- Define the table 
myTable [ thePlayer ] = { } -- Use the player userdata as index 

Insert:

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

Posted
Table = {"something" = {"something else" = {1 = "hello", 2 = "goodbye"}}} 
local Something = Table["something"] 
local SomethingElse = Something["something else"] 
Hello = SomethingElse[1] 

Posted (edited)

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
Posted
local myTable = {} 
  
myTable[ client ] = {} 
myTable[ client ][1] = weaponSlot1Data 
myTable[ client ][2] = weaponSlot2Data 
  

... where 1 and 2 are the weapon slot IDs. Is this what you wanted?

Posted (edited)

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

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