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?

s.epicrow.com:22003.png

Posted (edited)

-

Edited 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

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.

My Skype:

scriptmtasupport

My Resources:

http://www.scriptmta.co.nr - Cheap high-quality MTA resources by me and Kevin (ScriptMTA.co.nr)

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 

My Skype:

scriptmtasupport

My Resources:

http://www.scriptmta.co.nr - Cheap high-quality MTA resources by me and Kevin (ScriptMTA.co.nr)

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.

s.epicrow.com:22003.png

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

560x95_FFFFFF_FF9900_000000_000000.png

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

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

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

s.epicrow.com:22003.png

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

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

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