Script Not updating RTB value when in an event action but will in LUA console?

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
User avatar
KLAB
Posts: 483
Joined: Tue Feb 27, 2007 5:24 pm

Script Not updating RTB value when in an event action but will in LUA console?

Post by KLAB »

The below script works in the LUA console so that when 12 people have been recovered in total the recovery SAR helo is automatically RTB,
but when worked into the event action it repeatedly will not update the unit to RTB?

Baffled and have been trying for some time, latest iteration tried the emulate console but that made no difference?

Tool_EmulateNoConsole(true)
ScenEdit_AddSide({name='test'})

local count = tonumber(ScenEdit_GetKeyValue ("SARCap"))

::WHO::
local ResPax = ScenEdit_UnitX()
local ResU = ScenEdit_UnitY()
print (ResU.unit.name)
ScenEdit_MsgBox(ResPax.crew..' crew saved by '..ResU.unit.name..' ',0)
local ResC = count+ResPax.crew
local newcount = tostring(ScenEdit_SetKeyValue ("SARCap", ResC))
local cupdate = tonumber(ScenEdit_GetKeyValue ("SARCap"))
ScenEdit_MsgBox('A total of '..cupdate..' crew members have been rescued so far.',1)
if ResPax.WasPickedUp then
if ResPax.type ~= 'Facility' and ResPax.crew >= 2 then
print (ResPax.crew)
local NuScore = (10*ResPax.crew)
ScenEdit_MsgBox( NuScore..' Points for rescue of '..ResPax.crew..' crew members.', 0)
local a=ScenEdit_GetScore("A")
ScenEdit_SetScore('A',(a+NuScore),''..NuScore..' Points for rescue of aircrew.')
elseif ResPax.dbid == 2046 or ResPax.crew == 1 then
local NuScore = (10*1)
ScenEdit_MsgBox( NuScore..' Points for rescue of one crew member.', 0)
local a=ScenEdit_GetScore("A")
ScenEdit_SetScore('A',(a+NuScore),''..NuScore..' Points for rescue of one crew member.')
end
local finalcount = tonumber(ScenEdit_GetKeyValue ("SARCap"))
if finalcount >=12 then
ScenEdit_SetUnit({name=ResU.unit.name, guid=ResU.unit.guid, RTB=true})
ScenEdit_MsgBox(ResU.unit.name..' has recovered '..cupdate..' crew and is returning to base', 1)
end
ScenEdit_RemoveSide({name='test'})
Tool_EmulateNoConsole(false)
end
Any ideas what I am missing?

Thanks
K
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Script Not updating RTB value when in an event action but will in LUA console?

Post by KnightHawk75 »

What version (1147.x or betas 12xx+; or pro), and what's the triggering event type\setup just so I know while trying to replicate?
User avatar
KLAB
Posts: 483
Joined: Tue Feb 27, 2007 5:24 pm

Re: Script Not updating RTB value when in an event action but will in LUA console?

Post by KLAB »

KnightHawk75 wrote: Sat Dec 31, 2022 6:50 pm What version (1147.x or betas 12xx+; or pro), and what's the triggering event type\setup just so I know while trying to replicate?
1300.1 Not pro.
Trigger event is the unit destroyed trigger with the .Waspickedup condition.

::SARRECOCHECK:: -- Checks for valid recovery.
local RR=ScenEdit_UnitX()
if RR.WasPickedUp then
return true
else
return false
end

Thank you very much for looking.
K
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Script Not updating RTB value when in an event action but will in LUA console?

Post by KnightHawk75 »

KLAB wrote: Sat Dec 31, 2022 9:26 pm
KnightHawk75 wrote: Sat Dec 31, 2022 6:50 pm What version (1147.x or betas 12xx+; or pro), and what's the triggering event type\setup just so I know while trying to replicate?
1300.1 Not pro.
Trigger event is the unit destroyed trigger with the .Waspickedup condition.

::SARRECOCHECK:: -- Checks for valid recovery.
local RR=ScenEdit_UnitX()
if RR.WasPickedUp then
return true
else
return false
end

Thank you very much for looking.
K
Thanks I'm gonna check it out, spent last server hours finally getting around on Tiny since summer (lots of goodies, lots of annoyances). I'll see what I can find and post back, hopefully later tonight but if not tomorrow NYE and all. ;)
User avatar
KLAB
Posts: 483
Joined: Tue Feb 27, 2007 5:24 pm

Re: Script Not updating RTB value when in an event action but will in LUA console?

Post by KLAB »

KnightHawk75 wrote: Sat Dec 31, 2022 9:43 pm
KLAB wrote: Sat Dec 31, 2022 9:26 pm
KnightHawk75 wrote: Sat Dec 31, 2022 6:50 pm What version (1147.x or betas 12xx+; or pro), and what's the triggering event type\setup just so I know while trying to replicate?
1300.1 Not pro.
Trigger event is the unit destroyed trigger with the .Waspickedup condition.

::SARRECOCHECK:: -- Checks for valid recovery.
local RR=ScenEdit_UnitX()
if RR.WasPickedUp then
return true
else
return false
end

Thank you very much for looking.
K
Thanks I'm gonna check it out, spent last server hours finally getting around on Tiny since summer (lots of goodies, lots of annoyances). I'll see what I can find and post back, hopefully later tonight but if not tomorrow NYE and all. ;)
Happy new year - this version of the 'condition' worked, but I am still intrigued as to why the RTB built into the action script would not work?

local count=tonumber(ScenEdit_GetKeyValue('SARCap'))
local ResU=ScenEdit_UnitY()
if count <= 12 then
return true
elseif count > 12 then
ScenEdit_MsgBox('Recuer has no more capacity and is returning to base',0)
ScenEdit_SetUnit({name=ResU.unit.name, guid=ResU.unit.guid, RTB=true})
return false
end

If there is a more elegant and consistent solution or if its an error I would still be intrigued to know?

Thanks again
K
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Script Not updating RTB value when in an event action but will in LUA console?

Post by KnightHawk75 »

Idk how you even got any of this working\triggered, since unit destroyed doesn't even fire for me when picked up units disappear in 1300 (should they with the new cargos system?), that said even in 1147.52 I can't get the unit destroyed trigger to invoke on a pickup-destruction.

That said if things are otherwise working for you somehow, and the only problem is the rtb when in an event context, you could try:

Code: Select all

ScenEdit_SetUnit({guid=ResU.unit.guid, RTB=true}); 
-- I think if you provide a name it expects a side too, 
--so maybe it's generating an error or silently failing, maybe just use guid. 
--or:
ResU.unit:RTB(true);  --assuming ResU.unit is valid unit wrapper. 
What I did test was that the above two methods do cause an RTB in an event context in a simple test as long as whatever ResU.unit is exists; in my testing technically ResU was UnitX() so the calls were ResU.guid and ResU:RTB(true), it's UnitY where the .unit stuff is needed which is correct for you case from what it looks like.


Do you get the msgbox execution, and just not the next line or does neither happen in the event? You could test this with print statements to the log before and after that section. What's your luahistory log say after the event fires, is an error logged? Honestly this is hard to help troubleshoot reliably without the scene (if you want to pm it to me without sharing it publicly I could maybe better understand situation and where exactly and why the problem is happening). My guess is there is an error happening either on those lines or above such that execution stops or never gets to that portion, or there is a UnitY() context problem to begin with as you're not checking for nil etc.


As for doing this differently... in 1147.x SAR stuff I've done revolved around monitoring a table of individual 1xpersonel units "for pickup" either preexisting or generated say after an aircraft destruction (1 for each crew member) and then generated personnel unit guids and along with refpoints get added to a said monitored table, once said units don't exist anymore, or were no longer in-an-area (created for each unit), I count them as picked up, do what else I want done, and remove their entry from the monitoring table - along with their rp's. Table was checked\run through every 15 seconds, I avoided the use of having to use the event system entirely (including in-area checking) except for the timer. But most of all that was before .waspickedup and lots of other additions existed and got added over the years let alone all new abilities in 1200+, but one thin it did ensure at the expense of writing lots more code was that things kept workiing kinda no matter what changed or got broken in the game or event system over time.

I'm sorry if none of this is helping yet, kinda like I said eyeballing things in action in the actual scene may provide much more insight into what going on.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Script Not updating RTB value when in an event action but will in LUA console?

Post by KnightHawk75 »

Finally got it working in 1147.52, forgot that the picker loadout has to be flagged SAR\CSAR in the database no matter if sar_enabled on the target or not, being able to pickup units anyway (cargo loadout etc, no loadout,etc) will not cause unitdestroyed to fire without the picker loadout apparently being flagged, is what it is, but very limiting. Anyway I was able to rtb a unit during the event, not you exact code but in theory was able to confirm doing that generally doesn't seem to be broke. On 1300 I get exception errors for ondestroyed events, I wonder if you get the same as I reported it here: https://www.matrixgames.com/forums/view ... 0&t=391556, but I think it might be a me\my install thing only.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Script Not updating RTB value when in an event action but will in LUA console?

Post by KnightHawk75 »

KLAB wrote: Sun Jan 01, 2023 9:05 pm Thank you very much for looking.
K
...quoting something just so it notifies you.

So looks like you and I may have both ran into a .wasPickedUp vs .WasPickedUp issue, that was causing the exception (maybe you were getting it too in the log and didn't notice?). I think Michael is updating the docks and changing it back to .wasPickedUp, apparently somewhere along the line in 12xx-130x.x it got changed to start with capital, appears this was not intentional see link above for more info.
User avatar
KLAB
Posts: 483
Joined: Tue Feb 27, 2007 5:24 pm

Re: Script Not updating RTB value when in an event action but will in LUA console?

Post by KLAB »

I thought I had imagined the waspickedup WasPickedUp change and put it down to an error on my part as I had to alter it in several scenarios.

I will keep working on it LUA wise though as its pushing my brain to work harder.

SAR CSAR wise:
In the long term I think it is probably destined to be a feature request for SAR CSAR loadouts to have limits on pick ups, as it stands one Wildcat helo could recover the entire crew of an aircraft carrier.
Thanks again.
K
Post Reply

Return to “Lua Legion”