Page 1 of 1

FualState in Lua : how do you use it ?

Posted: Mon Mar 21, 2016 2:28 pm
by iborg
As the title says. I want to set the fuel state of units in scenarios, using Lua, but I can't seem to make it work. I tried to follow the syntax on Baloogan's Lua function documentation, but it's not clear as to how to integrate it in API calls. Anyone could post a working example (in a ScenEdit_AddUnit script), I'd be grateful !

RE: FualState in Lua : how do you use it ?

Posted: Mon Mar 21, 2016 7:24 pm
by ckfinite
See the example here. You'd use it like

local u = ScenEdit_AddUnit(...)
local fuel = u.fuel
fuel[3001].current = 400
u.fuel = fuel

(you'll need to get the fuel code from the list on that page)

RE: FualState in Lua : how do you use it ?

Posted: Tue Mar 22, 2016 12:09 pm
by iborg
Ah, thanks ! I understand better now. I think you should put this example instead of (or in addition to) the one in the link, which is less complete (and which I couldn't understand [;)] ). And thanks for the rest of the Lua documentation by the way, it's immensely helpful [&o]

RE: FualState in Lua : how do you use it ?

Posted: Tue Mar 22, 2016 6:11 pm
by tjhkkr
ORIGINAL: ckfinite

See the example here. You'd use it like

local u = ScenEdit_AddUnit(...)
local fuel = u.fuel
fuel[3001].current = 400
u.fuel = fuel

(you'll need to get the fuel code from the list on that page)

Did you mean ADDUnit or GetUnit?

RE: FualState in Lua : how do you use it ?

Posted: Tue Mar 22, 2016 6:13 pm
by tjhkkr
Do when you do this, the local variable u has all the parameters of that unit, and that unit's parameters/properties could then be modified?
Do I understand this accurately?

RE: FualState in Lua : how do you use it ?

Posted: Wed Mar 23, 2016 5:41 pm
by iborg
ORIGINAL: tjhkkr

Do when you do this, the local variable u has all the parameters of that unit, and that unit's parameters/properties could then be modified?
Do I understand this accurately?
local u = ScenEdit_AddUnit(...)
local fuel = u.fuel
fuel[3001].current = 400
u.fuel = fuel

I just tried it in the Lua console, using it like this :

Code: Select all

local u =  ScenEdit_SetUnit({side="India", guid="0747cd9c-eca2-4a65-b04e-c0d226b0a91d"})
 local fuel = u.fuel 
 fuel[2001].current = 1500 
 u.fuel = fuel 

Of course, you have to change side and guid accordingly, but in this example I changed the fuel state of an airborne plane (therefore the 2001 code for avgas). [:)]

RE: FualState in Lua : how do you use it ?

Posted: Wed Mar 23, 2016 7:47 pm
by ckfinite
Do when you do this, the local variable u has all the parameters of that unit, and that unit's parameters/properties could then be modified?
Do I understand this accurately?

Yes, exactly. See my documentation for what you can do with it.
Did you mean ADDUnit or GetUnit?

AddUnit, since that's what iborg asked about. If you look at the documentation, you can see it returns the unit that was added.

RE: FualState in Lua : how do you use it ?

Posted: Thu Mar 24, 2016 1:36 am
by tjhkkr
ORIGINAL: ckfinite
Do when you do this, the local variable u has all the parameters of that unit, and that unit's parameters/properties could then be modified?
Do I understand this accurately?

Yes, exactly. See my documentation for what you can do with it.
Did you mean ADDUnit or GetUnit?

AddUnit, since that's what iborg asked about. If you look at the documentation, you can see it returns the unit that was added.
Thank you for taking the time to answer. :)

RE: FualState in Lua : how do you use it ?

Posted: Sat Mar 26, 2016 12:52 pm
by Dysta
I tried to modify the unit's maximum fuel for a new scenario, but the Max field doesn't seems working. Something wrong in this script? (Tested Current adjustment is working)

local u = ScenEdit_SetUnit({side="***", guid="***"})
local fuel = u.fuel
fuel[3001].max = 50000
u.fuel = fuel

RE: FualState in Lua : how do you use it ?

Posted: Sat Mar 26, 2016 1:18 pm
by ckfinite
I tried to modify the unit's maximum fuel for a new scenario, but the Max field doesn't seems working. Something wrong in this script? (Tested Current adjustment is working)

I suspect (but don't know for sure) that the max fuel state is read only.

RE: FualState in Lua : how do you use it ?

Posted: Sat Mar 26, 2016 1:32 pm
by Dysta
ORIGINAL: ckfinite

I suspect (but don't know for sure) that the max fuel state is read only.
Ouch. Is there's a workaround like using triggers? If not, seems like the only way is to make a replenishment ship for refueling.

RE: FualState in Lua : how do you use it ?

Posted: Sat Mar 26, 2016 1:50 pm
by ckfinite
Ouch. Is there's a workaround like using triggers? If not, seems like the only way is to make a replenishment ship for refueling.

You can refuel the units like the following:

local u = ScenEdit_SetUnit({side=..., guid=...})
local fuel = u.fuel
fuel[2001].current = fuel[2001].max
u.fuel = fuel

But you can't change the maximum amount of fuel that the unit has, as far as I know.

RE: FualState in Lua : how do you use it ?

Posted: Sat Mar 26, 2016 2:17 pm
by Dysta
ORIGINAL: ckfinite
Ouch. Is there's a workaround like using triggers? If not, seems like the only way is to make a replenishment ship for refueling.

You can refuel the units like the following:

local u = ScenEdit_SetUnit({side=..., guid=...})
local fuel = u.fuel
fuel[2001].current = fuel[2001].max
u.fuel = fuel

But you can't change the maximum amount of fuel that the unit has, as far as I know.
local u = ScenEdit_SetUnit({side=..., guid=...}) local fuel = u.fuel fuel[2001].current = fuel[2001].max u.fuel = fuel

Got it! With Event, Trigger and Action, the ship can now roaming much further as long as it reached the set area.