Drakath Posted June 22, 2014 Posted June 22, 2014 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?
Drakath Posted June 22, 2014 Author Posted June 22, 2014 Did you even read my question? This has nothing to do with my script.
ADCX Posted June 22, 2014 Posted June 22, 2014 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.
Drakath Posted June 23, 2014 Author Posted June 23, 2014 Thanks. One more question, how can I create a table in server-side that is only available for a specific player?
ADCX Posted June 23, 2014 Posted June 23, 2014 TableOfTables= {} function CreatePlayerTable(Player) TableOfTables[Player] = {} end
Drakath Posted June 23, 2014 Author Posted June 23, 2014 And what if I need to make even more tables for one player? Would this work: table[player][id] ?
ADCX Posted June 23, 2014 Posted June 23, 2014 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
Et-win Posted June 23, 2014 Posted June 23, 2014 table = {{anothertable}} Example: table1 = { {"NamePlayer1", "Weapon", ammo}, {"NamePlayer2", "Weapon", ammo}, } EDIT: To insert that, use: table.insert(table1, {"MyName", "AK-47", 11})
Drakath Posted June 23, 2014 Author Posted June 23, 2014 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.
Castillo Posted June 24, 2014 Posted June 24, 2014 local myTable = { } -- Define the table myTable [ thePlayer ] = { } -- Use the player userdata as index Insert: table.insert ( myTable [ thePlayer ], { "Hello", "World" } )
ADCX Posted June 24, 2014 Posted June 24, 2014 Table = {"something" = {"something else" = {1 = "hello", 2 = "goodbye"}}} local Something = Table["something"] local SomethingElse = Something["something else"] Hello = SomethingElse[1]
ixjf Posted June 24, 2014 Posted June 24, 2014 Overcomplicating simple stuff. myTable[ thePlayer ][1] -- "Hello" myTable[ thePlayer ][2] -- "World"
Drakath Posted June 24, 2014 Author Posted June 24, 2014 (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 June 24, 2014 by Guest
ixjf Posted June 24, 2014 Posted June 24, 2014 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?
Drakath Posted June 24, 2014 Author Posted June 24, 2014 No, I'm asking if I can accomplish my needs with one table.
ixjf Posted June 24, 2014 Posted June 24, 2014 (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 June 24, 2014 by Guest
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