Jump to content

getElementData


Drakath

Recommended Posts

Posted
if getElementType(getElementData (source, "car")) == "vehicle" then 

WARNING: script\server.lua:47: Bad argument @ 'getElementType' [Expected element at argument 1]

car=getElementData(source, "car") 
destroyElement(car) 

WARNING: script\server.lua:141: Bad argument @ 'destroyElement' [Expected element at argument 1]

Why can't I use getElementData as an element? With what should I replace it in order for the script to output no errors or warnings?

s.epicrow.com:22003.png

  • Moderators
Posted

You can, unless it is destroyed.

local car=getElementData(source, "car") 
if isElement(car) then -- check if it still does exist. 
    destroyElement(car) 
end 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted
element data is a very bad way for such thing as vehicle elements. You should use tables for that. Otherwise a hacker could create a custom vehicle and set it as the element data. Or set any existing one to its element data and own it.

True, but for him it isn't important at the moment.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
element data is a very bad way for such thing as vehicle elements. You should use tables for that. Otherwise a hacker could create a custom vehicle and set it as the element data. Or set any existing one to its element data and own it.

True, but for him it isn't important at the moment.

It's more important than you think it is. Scripting *badly-designed* codes might become a habit and one might use this all the time. It's very easy to get a bad habit and pretty much difficult to get rid of it. So studying should go on properly, without *easier* workarounds.

  • Moderators
Posted

It's more important than you think it is. Scripting *badly-designed* codes might become a habit and one might use this all the time. It's very easy to get a bad habit and pretty much difficult to get rid of it. So studying should go on properly, without *easier* workarounds.

It is important, but not everybody wants to learn lua else he would ask for the tables.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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