Wei Posted August 1, 2013 Share Posted August 1, 2013 local storWeapon = fromJSON(getElementData(housePickup[houseID], "IGChousing.storedweapons")) if (type(storWeapon) == "table") then local tableWeapon = storWeapon if tableWeapon[getSlotFromWeapon(weapon)] then tableWeapon[getSlotFromWeapon(weapon)] = weapon..","..tableWeapon[getSlotFromWeapon(weapon)]+ammo setElementData(housePickup[houseID], "IGChousing.storedweapons", toJSON(tableWeapon)) outputChatBox("In") else table.insert(tableWeapon, getSlotFromWeapon(weapon), weapon..","..ammo) setElementData(housePickup[houseID], "IGChousing.storedweapons", toJSON(tableWeapon)) outputChatBox("NotIn") end Chatbox allways outputs NotIn. No debug! Link to comment
Castillo Posted August 1, 2013 Share Posted August 1, 2013 And is the weapon in the table...? Link to comment
Castillo Posted August 1, 2013 Share Posted August 1, 2013 You are checking the slot, do you know that? Link to comment
Wei Posted August 1, 2013 Author Share Posted August 1, 2013 Yes, that I will override it later Link to comment
Castillo Posted August 1, 2013 Share Posted August 1, 2013 local storWeapon = fromJSON ( getElementData ( housePickup [ houseID ], "IGChousing.storedweapons" ) ) if ( type ( storWeapon ) == "table" ) then local tableWeapon = storWeapon if tableWeapon [ getSlotFromWeapon ( weapon ) ) ] then tableWeapon [ getSlotFromWeapon ( weapon ) ] = weapon ..",".. tableWeapon [ getSlotFromWeapon ( weapon ) ] + ammo setElementData ( housePickup [ houseID ], "IGChousing.storedweapons", toJSON ( tableWeapon ) ) outputChatBox ( "In" ) else tableWeapon [ getSlotFromWeapon ( weapon ) ] = weapon ..",".. ammo setElementData ( housePickup [ houseID ], "IGChousing.storedweapons", toJSON ( tableWeapon ) ) outputChatBox ( "NotIn" ) end This won't work btw: weapon ..",".. tableWeapon [ getSlotFromWeapon ( weapon ) ] + ammo You are trying to increase a string... Link to comment
Wei Posted August 1, 2013 Author Share Posted August 1, 2013 Still same, yeah I will fix that later... Link to comment
Castillo Posted August 1, 2013 Share Posted August 1, 2013 Mind posting the "storWeapon" result? Link to comment
Wei Posted August 1, 2013 Author Share Posted August 1, 2013 ([ { "5": "30,1" } ] notIn Link to comment
Castillo Posted August 1, 2013 Share Posted August 1, 2013 Got it, you must convert your number to a string. local storWeapon = fromJSON ( getElementData ( housePickup [ houseID ], "IGChousing.storedweapons" ) ) if ( type ( storWeapon ) == "table" ) then local tableWeapon = storWeapon local slot = tostring ( getSlotFromWeapon ( weapon ) ) if tableWeapon [ slot ] then tableWeapon [ slot ] = weapon ..",".. tableWeapon [ slot ] + ammo setElementData ( housePickup [ houseID ], "IGChousing.storedweapons", toJSON ( tableWeapon ) ) outputChatBox ( "In" ) else tableWeapon [ slot ] = weapon ..",".. ammo setElementData ( housePickup [ houseID ], "IGChousing.storedweapons", toJSON ( tableWeapon ) ) outputChatBox ( "NotIn" ) end Link to comment
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