FualState in Lua : how do you use it ?

Take command of air and naval assets from post-WW2 to the near future in tactical and operational scale, complete with historical and hypothetical scenarios and an integrated scenario editor.

Moderator: MOD_Command

Post Reply
iborg
Posts: 23
Joined: Mon Feb 22, 2016 9:07 pm

FualState in Lua : how do you use it ?

Post 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 !
ckfinite
Posts: 208
Joined: Fri Jul 19, 2013 10:33 pm

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

Post 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)
iborg
Posts: 23
Joined: Mon Feb 22, 2016 9:07 pm

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

Post 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]
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

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

Post 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?
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

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

Post 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?
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
iborg
Posts: 23
Joined: Mon Feb 22, 2016 9:07 pm

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

Post 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). [:)]
ckfinite
Posts: 208
Joined: Fri Jul 19, 2013 10:33 pm

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

Post 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.
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

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

Post 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. :)
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
User avatar
Dysta
Posts: 1909
Joined: Fri Aug 07, 2015 9:32 pm

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

Post 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
ckfinite
Posts: 208
Joined: Fri Jul 19, 2013 10:33 pm

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

Post 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.
User avatar
Dysta
Posts: 1909
Joined: Fri Aug 07, 2015 9:32 pm

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

Post 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.
ckfinite
Posts: 208
Joined: Fri Jul 19, 2013 10:33 pm

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

Post 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.
User avatar
Dysta
Posts: 1909
Joined: Fri Aug 07, 2015 9:32 pm

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

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

Return to “Command: Modern Operations series”