Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Lua - add cargo?

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Air / Naval Operations >> Mods and Scenarios >> Lua Legion >> Lua - add cargo? Page: [1]
Login
Message << Older Topic   Newer Topic >>
Lua - add cargo? - 4/5/2018 12:24:45 AM   
Gunner98

 

Posts: 3552
Joined: 4/29/2005
From: The Great White North!
Status: online
Am playing around with the cargo function a bit and am wondering if Lua can help.

Situation: various bases have small land elements that are meant to be transported to a central hub, from there some transport Helicopters will do the tactical air assault.

Some remote bases have C-130 or C-160 tactical transports available and this is fine: I put the cargo components on those bases, player decides what bits to transport and all is good.

For the locations that don't have a tactical transport, I'm using civilian charter - and they don't have the ability to use the COMANO cargo function: So I would like to set up a Lua event for when the civilian charter arrives at the assembly base, certain cargo elements get added to the base.

Can that be done? I don't see a Lua function for it but have been away a lot so may have missed it.

Alternatively, I suppose I should ask for the aircraft in question to have the cargo function added.

Thanks guys.
Post #: 1
RE: Lua - add cargo? - 4/5/2018 6:30:30 AM   
michaelm75au


Posts: 12060
Joined: 5/5/2001
From: Sydney, Australia
Status: offline
You should be able to. I added some functions to support cargo when it came out. I'll just have to refresh my memory, and added some code on how it should work

_____________________________

Michael

(in reply to Gunner98)
Post #: 2
RE: Lua - add cargo? - 4/5/2018 6:46:36 AM   
michaelm75au


Posts: 12060
Joined: 5/5/2001
From: Sydney, Australia
Status: offline
You can transfer cargo from one unit to another; you supply a table of {guids from the unit components}, or { {DBID, number}} of the cargo to move
local u = ScenEdit_GetUnit({name='Uji', guid='7078b0f2-5dca-4930-a45d-5abe2d86a429'}) -- unit with the cargo
local c = u:filterOnComponent('cargo') -- the cargo contents
local ok = ScenEdit_TransferCargo(u.guid, 'galco #1', {{2,2918},{5,132}}) -- transfer items from 'Uji' to 'galco #1'

--
To just add the cargo to a unit, I'm not sure about. Will need to look at my notes. I would suggest SE_UpdateUnit() should do it but I 'cargo' isn't one of the items that can be added.
I suppose you could hide a base somewhere and transfer items from it. But that seems messy.


_____________________________

Michael

(in reply to michaelm75au)
Post #: 3
RE: Lua - add cargo? - 4/6/2018 12:37:14 PM   
Gunner98

 

Posts: 3552
Joined: 4/29/2005
From: The Great White North!
Status: online
Or I could use the base of origin for the flight. That would work. I'll give it a try this weekend.

Thanks

B

(in reply to michaelm75au)
Post #: 4
RE: Lua - add cargo? - 4/6/2018 1:59:01 PM   
michaelm75au


Posts: 12060
Joined: 5/5/2001
From: Sydney, Australia
Status: offline
Yea, putting the initial cargo into the starting base would make sense. That way, you could see the cargo disappear and know how much was left.
quote:

ORIGINAL: Gunner98

Or I could use the base of origin for the flight. That would work. I'll give it a try this weekend.

Thanks

B



_____________________________

Michael

(in reply to Gunner98)
Post #: 5
RE: Lua - add cargo? - 4/7/2018 4:22:50 PM   
Gunner98

 

Posts: 3552
Joined: 4/29/2005
From: The Great White North!
Status: online
Thank you once again Michael

Worked like a charm. I simplified the command to:

ScenEdit_TransferCargo('Moroni Airport', 'Camp Lemonier Barracks 10', {{2,2884},{1,2513}}) -- transfer items from 'Moroni' to 'Djibouti Airport'

Some pondering:

I think I understand the reason for using GUID vice the name, have never done that but probably should.
What is the reason for going with 'local' commands? Is there a guide to using them?

Thanks

Cheers

B

(in reply to michaelm75au)
Post #: 6
RE: Lua - add cargo? - 4/7/2018 6:05:33 PM   
TitaniumTrout

 

Posts: 106
Joined: 10/20/2014
From: Michigan
Status: offline
Using local keeps the variable just for that usage. So you could define
local unit = ScenEdit_GetUnit
and then call it out in a different function a minute later and use the exact same variable. Local is just thta, for a local function.

I believe you can store a variable globally but it is not persistent. So you could define
unit = ScenEdit_GetUnit
and call it in a different function, but the moment you save and reload that variable is cleared and any reference to it would return null. You can save variables using the ScenEdit_GetKeyValue and ScenEdit_SetKeyValue.

http://commandlua.github.io/index.html#ScenEdit_SetKeyValue

Be aware that it saves the data as a string. So if you define a key as "7", it is as a string and not an integer. So any operations you perform thinking it's an integer will not work. First you need to define it using the
tonumber
function. http://www.lua.org/manual/5.1/manual.html#pdf-tonumber

_____________________________


(in reply to Gunner98)
Post #: 7
RE: Lua - add cargo? - 4/7/2018 9:51:50 PM   
michaelm75au


Posts: 12060
Joined: 5/5/2001
From: Sydney, Australia
Status: offline

quote:

ORIGINAL: Gunner98

Thank you once again Michael

Worked like a charm. I simplified the command to:

ScenEdit_TransferCargo('Moroni Airport', 'Camp Lemonier Barracks 10', {{2,2884},{1,2513}}) -- transfer items from 'Moroni' to 'Djibouti Airport'

Some pondering:

I think I understand the reason for using GUID vice the name, have never done that but probably should.
What is the reason for going with 'local' commands? Is there a guide to using them?

Thanks

Cheers

B


1. Use of GUID: I have tended to go with this for several reasons over the years, mainly because it is more specific to the actual item I want to affect. Using the 'name' is fine in most cases, but as the name can be changed by the player, this can break Lua scripts which rely on the original name only. As you get deeper into some items (like unit components), names no longer are unique so you need to rely on GUIDs.
2. Local variables: By default Lua treats all variables as 'global'. This means that they stay around (and use up memory) for the entire session. It also means that they can be used anywhere in your scripts.
Which is fine, but the risk is that you accidentally use the same variable in more than one location and the value gets changed from what you expected.
By making them 'local', they only exist while running the script/function that they are in. This also helps in you don't pickup 'old' global values that may have carried over from some other script.



_____________________________

Michael

(in reply to Gunner98)
Post #: 8
RE: Lua - add cargo? - 4/8/2018 10:27:22 AM   
Gunner98

 

Posts: 3552
Joined: 4/29/2005
From: The Great White North!
Status: online
Thank you both. Will try and expand my limited scripting skill to include these two bits.


B

(in reply to michaelm75au)
Post #: 9
RE: Lua - add cargo? - 4/8/2018 12:43:15 PM   
Gunner98

 

Posts: 3552
Joined: 4/29/2005
From: The Great White North!
Status: online
OK, playing around with this an must be doing something wrong:

2018-04-08 8:34:22 AM -- B998.7 --
Console:
local o = ScenEdit_GetUnit ({name='Moroni Airport', guid='0d199a59-5c5c-4f50-ba71-78d88c261454'})
local d = ScenEdit_GetUnit ({name='Camp Lemonier Barracks 12', guid='13256382-bdc9-4a52-8543-4ddfd54a4bf8'})
local ScenEdit_TransferCargo({o.guid, d.guid, {8,2884},{1,2916},{4,357},{4,1973},{1,2590},{4, 851}}) -- transfer items from 'Moroni' to 'Djibouti Airport'
ERROR: [string "Console"]:3: syntax error near <eof>

Remembering that I'm an old dog and this is a new trick - its probably something very basic that is messing up.

Thanks

B

(in reply to Gunner98)
Post #: 10
RE: Lua - add cargo? - 4/8/2018 7:42:46 PM   
michaelm75au


Posts: 12060
Joined: 5/5/2001
From: Sydney, Australia
Status: offline
local ScenEdit_TransferCargo( o.guid, d.guid, { {8,2884},{1,2916},{4,357},{4,1973},{1,2590},{4, 851} } )

_____________________________

Michael

(in reply to Gunner98)
Post #: 11
RE: Lua - add cargo? - 4/15/2018 5:30:27 PM   
Gunner98

 

Posts: 3552
Joined: 4/29/2005
From: The Great White North!
Status: online
Thanks Michael - working like a charm.

Cheers once again.

B

(in reply to michaelm75au)
Post #: 12
RE: Lua - add cargo? - 4/16/2018 11:00:49 AM   
michaelm75au


Posts: 12060
Joined: 5/5/2001
From: Sydney, Australia
Status: offline
I am adding a SE_UpdateUnitCargo() function that will act like the SE_UpdateUnit() but allow cargo only. Cargo behaves differently to the sensor/mount/etc components so made sense to isolate it.

_____________________________

Michael

(in reply to Gunner98)
Post #: 13
RE: Lua - add cargo? - 4/16/2018 2:15:45 PM   
Gunner98

 

Posts: 3552
Joined: 4/29/2005
From: The Great White North!
Status: online
That's a good idea.

Another thought - the documentation at http://commandlua.github.io/ is excellent, not sure if you're managing that. I find the organization of the page very helpful but there are getting to be a lot of functions. It would be helpful I think for some definition, guidelines on the difference and usage between 'Set', 'Get', 'update' etc.

Perhaps its just an issue of not understanding the fundamentals of scripting, and I can work through it. Just thought with more and more functions becoming available with each update that a tweak to the organization might be helpful.

Thanks again for all your help. I did a bunch of scripting this weekend without a single plea for help - success... if it all works that is.

B

(in reply to michaelm75au)
Post #: 14
RE: Lua - add cargo? - 4/17/2018 10:29:04 AM   
michaelm75au


Posts: 12060
Joined: 5/5/2001
From: Sydney, Australia
Status: offline
I am intending to start creating example files to attach to the wiki page ( eg http://commandlua.github.io/beta/index.html ).
Just trying to determine how deep to get in to it. There are other locations that show how to do Lua Command stuff, this is more to show the commands are used and how with simple examples.

_____________________________

Michael

(in reply to Gunner98)
Post #: 15
RE: Lua - add cargo? - 4/17/2018 12:46:56 PM   
Gunner98

 

Posts: 3552
Joined: 4/29/2005
From: The Great White North!
Status: online
Right.

I was thinking one liners such as:

SE_getxxx: used to ...
SE_updatexx: used to ...

No problem. Thanks

B

(in reply to michaelm75au)
Post #: 16
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Air / Naval Operations >> Mods and Scenarios >> Lua Legion >> Lua - add cargo? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.129