tommymaster Posted January 6, 2018 Share Posted January 6, 2018 In my server every vehicle, interior entrance, gate has a key. But my item system won't display the key item picture, until localPlayer hasn't got a "key:any number" at slot1. In other programs we can search for file names as picture.***, and the *** could mean any file extension there, in lua is there a way i can do like the same thing, but with numbers? setElementData (localPlayer, "slot1", "key:"..1, true) if getElementData (localPlayer, "slot1") == "key:"..all the int numbers.."" then --draw key image in inventory else --slot 1 is blank end Link to comment
Tails Posted January 6, 2018 Share Posted January 6, 2018 (edited) Not quite sure if I understand but it looks like you're trying to check if "slot1" contains any key and then proceed with some code. There are different ways you can probably approach this. First is a table, which would be smarter because it is faster than element data and element data is not very safe. If this is the server side I think you should be fine but still personally I'd go with an actual table. What you can do is just simply check if any element data exists on "slot1" by just doing if getElementData (localPlayer, "slot1") then --draw key image in inventory else --slot 1 is blank end if you set the "slot1" data to nil or false setElementData("slot1", nil) then it will return false and execute the second part of your code. If this is not what you meant, please try to explain your issue a bit more. Edited January 6, 2018 by Tails 1 Link to comment
tommymaster Posted January 6, 2018 Author Share Posted January 6, 2018 (edited) Hi! Slot1 is a place in inventory. Slot 1 could contain food, drinks, weapons, and keys. So if the player has a "key:"..mysqlID on his slot1 place in inventory, i would like a key icon to be drawn on the screen. if getElementData (localPlayer, "slot1") == "key:"..0 then This would work, but it only draws the key if the slot1 elementdata is 0. I would like to see the key, whatever the number is behind the "key:" string. Edited January 6, 2018 by tommymaster Link to comment
Tails Posted January 6, 2018 Share Posted January 6, 2018 (edited) Pattern matching could be a solution here local slot1 = getElementData(localPlayer, "slot1") if slot1:match("key:%w") then Edited January 6, 2018 by Tails 1 Link to comment
tommymaster Posted January 6, 2018 Author Share Posted January 6, 2018 (edited) Thank you very much!!!!!!!! Edited January 6, 2018 by tommymaster 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