Dzsozi (h03) Posted April 8, 2014 Posted April 8, 2014 Hello! I have a question. How can I set element data for objects which are in a table? So I use this script: https://community.multitheftauto.com/in ... ls&id=4931 and I want to set a message to all the objects which are in the table, but it's not working. What is wrong with my code? local models = {[2175]=true, [2190]=true,[2009]=true,[2008]=true,[11631]=true,[2198]=true,[2172]=true,[2193]=true,[2165]=true,[1998]=true,[1999]=true} function pcText(model) setElementData(models[model], "message", "Computer") end Your signature image is too large. Removed
Ali_Digitali Posted April 8, 2014 Posted April 8, 2014 Why do you need a table for this? When you use models[model] it will return the value you assigned to it. In this case you assigned true to all of the indices in the table. Example: models[2175] = true. This means that when you are using setElementData you are using a boolean as first argument, and this needs to be an element. I aint got no time to think of a witty signature
WASSIm. Posted April 8, 2014 Posted April 8, 2014 local models = {[2175]=true, [2190]=true,[2009]=true,[2008]=true,[11631]=true,[2198]=true,[2172]=true,[2193]=true,[2165]=true,[1998]=true,[1999]=true} function pcText(model) local objects = getElementsByType("object") for _, object in ipairs(objects) do if (models[getElementModel(object)]) then setElementData(object, "message", "Computer") end end end
Dzsozi (h03) Posted April 8, 2014 Author Posted April 8, 2014 local models = {[2175]=true, [2190]=true,[2009]=true,[2008]=true,[11631]=true,[2198]=true,[2172]=true,[2193]=true,[2165]=true,[1998]=true,[1999]=true} function pcText(model) local objects = getElementsByType("object") for _, object in ipairs(objects) do if (models[getElementModel(object)]) then setElementData(object, "message", "Computer") end end end It's not working Your signature image is too large. Removed
Saml1er Posted April 8, 2014 Posted April 8, 2014 Are you calling the function? local models = {[2175]=true, [2190]=true,[2009]=true,[2008]=true,[11631]=true,[2198]=true,[2172]=true,[2193]=true,[2165]=true,[1998]=true,[1999]=true} function pcText(model) -- what does this model do? local objects = getElementsByType("object") for _, object in ipairs(objects) do if (models[getElementModel(object)]) then setElementData(object, "message", "Computer") end end end pcText()
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