• Getting and settings values from entities
    4 replies, posted
What I'm trying to do, is getting and setting values from certain entities, such as thrusters. For example, how can I modify the force of a thruster inside of lua? It's seems a bit strange to me that this hasn't been documented for as far as I can see, so I'm probably missing out something. Anyway, if anyone could tell me how to do it, that would be great :)
I assume you know how to get the entity object. [I]Ent[/I] represents the thruster entity: [lua] if Ent && IsValid(Ent) && Ent:GetClass() == "gmod_thruster" then -- Check if entity is valid and a thruster. Ent:SetForce(5000) -- Sets the force to 5,000. This is a method defined within the entity script. end [/lua]
[QUOTE=thefreeman193;31348468]I assume you know how to get the entity object. [I]Ent[/I] represents the thruster entity: [lua] if Ent && IsValid(Ent) && Ent:GetClass() == "gmod_thruster" then -- Check if entity is valid and a thruster. Ent:SetForce(5000) -- Sets the force to 5,000. This is a method defined within the entity script. end [/lua][/QUOTE] Thansk you for the reply, do you know if there is a way to set such values independent of the entity, so I can get and set the values via a table? It would be great if I could set the value like Ent["force"] = 5000.
You can get the force of a thruster using Ent.force (or Ent["force"]). To store the values independently, just create a table in your script with thruster ents as keys and thrust amounts as values.
[QUOTE=thefreeman193;31350026]You can get the force of a thruster using Ent.force (or Ent["force"]). To store the values independently, just create a table in your script with thruster ents as keys and thrust amounts as values.[/QUOTE] I've tried this, but the thruster force won't change when the value gets changed. I need this for multiple entities and used thrusters as an example, that's the reason why I would like this to be more generic.
Sorry, you need to Log In to post a reply to this thread.