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?
Max+ Posted June 22, 2014 Posted June 22, 2014 (edited) - Edited June 23, 2014 by Guest - New , Kill System - New, GameMode Intro - Leve / Exp System - New nametag showing style - New , Hud For Players - Skin Selection from SA-MP - Money System / Buy Weapons - Drop Weapons - New, Flood System - New , Group Assign - Gun license For Weapons - Random Rule System For Money
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. My Skype: scriptmtasupport My Resources: http://www.scriptmta.co.nr - Cheap high-quality MTA resources by me and Kevin (ScriptMTA.co.nr)
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 My Skype: scriptmtasupport My Resources: http://www.scriptmta.co.nr - Cheap high-quality MTA resources by me and Kevin (ScriptMTA.co.nr)
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 My Skype: scriptmtasupport My Resources: http://www.scriptmta.co.nr - Cheap high-quality MTA resources by me and Kevin (ScriptMTA.co.nr)
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}) ~Scripts~ Clan War System V1.2.0 ~Maps~ [DM]Et-win - The Run [FUN]Et-win - Drift Rocket [FUN]Et-win - Drift Rocket // [DD]Et-win - Cross 3xC
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" } ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the 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] My Skype: scriptmtasupport My Resources: http://www.scriptmta.co.nr - Cheap high-quality MTA resources by me and Kevin (ScriptMTA.co.nr)
ixjf Posted June 24, 2014 Posted June 24, 2014 Overcomplicating simple stuff. myTable[ thePlayer ][1] -- "Hello" myTable[ thePlayer ][2] -- "World" I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
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? I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
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 I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
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