Lua - add cargo?
Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command
Lua - add cargo?
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.
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.
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
- michaelm75au
- Posts: 12455
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Lua - add cargo?
You should be able to. I added some functions to support cargo when it came out. I'll just have to refresh my memory[:D], and added some code on how it should work
Michael
- michaelm75au
- Posts: 12455
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Lua - add cargo?
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.
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
RE: Lua - add cargo?
Or I could use the base of origin for the flight. That would work. I'll give it a try this weekend.
Thanks
B
Thanks
B
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
- michaelm75au
- Posts: 12455
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Lua - add cargo?
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.
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
RE: Lua - add cargo?
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
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
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
- TitaniumTrout
- Posts: 472
- Joined: Mon Oct 20, 2014 9:06 am
- Location: Michigan
RE: Lua - add cargo?
Using local keeps the variable just for that usage. So you could define 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 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# ... etKeyValue
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 function. http://www.lua.org/manual/5.1/manual.html#pdf-tonumber
Code: Select all
local unit = ScenEdit_GetUnit
I believe you can store a variable globally but it is not persistent. So you could define
Code: Select all
unit = ScenEdit_GetUnit
http://commandlua.github.io/index.html# ... etKeyValue
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
Code: Select all
tonumber
CMO WIKI - https://wiki.weaponsrelease.com
- michaelm75au
- Posts: 12455
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Lua - add cargo?
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.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
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
RE: Lua - add cargo?
Thank you both. Will try and expand my limited scripting skill to include these two bits.
B
B
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
RE: Lua - add cargo?
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
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
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
- michaelm75au
- Posts: 12455
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Lua - add cargo?
local ScenEdit_TransferCargo( o.guid, d.guid, { {8,2884},{1,2916},{4,357},{4,1973},{1,2590},{4, 851} } )
Michael
RE: Lua - add cargo?
Thanks Michael - working like a charm.
Cheers once again.
B
Cheers once again.
B
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
- michaelm75au
- Posts: 12455
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Lua - add cargo?
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
RE: Lua - add cargo?
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. [8|]
B
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. [8|]
B
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
- michaelm75au
- Posts: 12455
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Lua - add cargo?
I am intending to start creating example files to attach to the wiki page ( eg http://commandlua.github.io/beta/index.html ).[:D]
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.
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
RE: Lua - add cargo?
Right.
I was thinking one liners such as:
SE_getxxx: used to ...
SE_updatexx: used to ...
No problem. Thanks
B
I was thinking one liners such as:
SE_getxxx: used to ...
SE_updatexx: used to ...
No problem. Thanks
B
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/