Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

cmano_helpers.lua - a "library" of lua functions to help with scenarios

 
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 Operations series >> Mods and Scenarios >> Lua Legion >> cmano_helpers.lua - a "library" of lua functions to help with scenarios Page: [1]
Login
Message << Older Topic   Newer Topic >>
cmano_helpers.lua - a "library" of lua functi... - 6/3/2018 8:50:48 AM   
NimrodX


Posts: 82
Joined: 5/12/2018
Status: offline
I'm actually still working on this and I think I'll put it on GitHub or something for better modification tracking and the ability to accept modifications, but here's something that people may find useful:

https://www.dropbox.com/s/o5sdisywxi53i8w/cmano_helpers.lua?dl=0

(I'm still editing it so it may change depending on when you download it. I'm pretty sure this link will link to whatever version I most recently copied to Dropbox.)

Instructions on how to use it are in the comment at the top of the file.

I'm basically collecting all of the functions and bits of code that people have posted that I've found somewhere and started adding them to this file.
Post #: 1
RE: cmano_helpers.lua - a "library" of lua fu... - 6/3/2018 1:52:32 PM   
kevinkins


Posts: 2250
Joined: 3/8/2006
Status: online
I think stilesw has been collecting lua code examples over the past year or so. He has been collecting other material as well. Perhaps you guys can combine efforts. I believe his collection is in dropbox too. But you will have to PM him to get access. Codes examples are very useful for those who don't use the language that often. Thanks for your dropbox link.

Kevin

(in reply to NimrodX)
Post #: 2
RE: cmano_helpers.lua - a "library" of lua fu... - 6/4/2018 12:20:17 AM   
NimrodX


Posts: 82
Joined: 5/12/2018
Status: offline
Yes, already done. Over half the code in the file at this point is from the snippets he has collected. That's what I started with and I'm searching out more. Will probably end up loading lots of scenarios that people have created in search of more stuff that people need convenience functions for. This should help keep people from having to "reinvent the wheel" as often.

My main goal right now is to create convenience functions that people can just import and use without necessarily having to understand exactly how they work, but of course they can also be used as examples or a starting point for modifications.

(in reply to kevinkins)
Post #: 3
RE: cmano_helpers.lua - a "library" of lua fu... - 6/4/2018 1:49:11 PM   
kevinkins


Posts: 2250
Joined: 3/8/2006
Status: online
Ok, great. I have my own file with code snippets and can send it to you to see if there is anything that you don't already have. I should take a minute and clean up my file anyway. At one point I found a freeware program made to house code snippets. But in the end I just used a text file. But if the collection gets really large the program like that might be useful.

Kevin

(in reply to NimrodX)
Post #: 4
RE: cmano_helpers.lua - a "library" of lua fu... - 6/4/2018 5:16:06 PM   
Gunner98

 

Posts: 5434
Joined: 4/29/2005
From: The Great White North!
Status: offline
Once I get a chance I'll do the same. Its all on my home puter though so will be a few weeks yet.

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/

(in reply to kevinkins)
Post #: 5
RE: cmano_helpers.lua - a "library" of lua fu... - 6/7/2018 8:14:30 PM   
NimrodX


Posts: 82
Joined: 5/12/2018
Status: offline
Ok great! This will speed up my plan to put this on GitHub so people can just submit additions as push requests on there.

BTW, I originally thought it would make sense to attach the code as a lua scenario attachment but it seems like that either doesn't work properly or isn't worth the effort even if it does.

My current recommendation on how to add a function library to a scenario is this:

quote:



--[[ ---------------------------------------------------------------------------------------------------------------------------

How to use this file:

There are two ways to use this.

#1 - If you only need one or two functions in only one script chunk then you could simply copy the
function from here and paste it into the script. But unless it is ONLY used in that ONE place, this will quickly
become unmanagable! This is strongly discouraged.

#2 - The best thing to do is copy and paste this entire file into an Lua Script "Action". That way it can easily
be evaluated on scenario load, making the functions available everywhere. Here's a quick way to do that.

1) Load up the Lua console and execute this code snippet in it ONCE to create the initialization event:

local event = ScenEdit_SetEvent('Lua Helper Init', {mode='add', IsRepeatable=true})
ScenEdit_SetTrigger({mode='add',type='ScenLoaded',name='Scenario Loaded'})
ScenEdit_SetEventTrigger(event.guid, {mode='add', name='Scenario Loaded'})
ScenEdit_SetAction({mode='add',type='LuaScript',name='Load Lua Helpers',
ScriptText='-- REPLACE THIS with the contents of cmano_helpers.lua'})
ScenEdit_SetEventAction(event.guid, {mode='add', name='Load Lua Helpers'})

2) Now, open up Editor->Event Editor->Actions, edit the "Load Lua Helpers" action, copy the whole
contents of this file to the clipboard (load in notepad.exe or a better text editor, Ctrl-A, Ctrl-C),
and paste it into the "Load Lua Helpers" script editor (click text area, right-click Select All, Ctrl-V).

3) Save the scenario, then reload the scenario from the file.

4) After you do this, every Lua script that runs in the scenario should be able to use every function
in this file.

You only need to do this process once for every new scenario. If you need to update the library of functions
for your scenario, just edit the "Load Lua Helpers" Action and copy/paste the new file, make one-off edits,
or whatever you need to do. Then save the scenario and load it from the file again.

Tips:

If you are working on your own "library" and aren't quite done yet, there's a temporary way to load these
functons from a file on disk. Consider this "developer mode" because you can edit the file with a text
editor and still use it in scripts and the Lua console during testing.

Place the file in the [CMANO Game Folder]/Lua directory (* see note) and you will be able to load it in
the Lua console or the "Load Lua Helpers" Action like this:

ScenEdit_RunScript ("cmano_helpers.lua") -- or whatever the filename is

Once your code is finalized, just copy/paste the whole contents of your lua file into the "Load Lua Helpers"
Action (replacing the above line) so you don't have to worry about bundling an external file.

* Warning: in Build 998.9 and probably before, if you are using the Steam version of the game launched
from Steam, or you've launched it from autorun.exe, then Lua scripts run from ScenEdit_RunScript() must
go in the [CMANO Game Folder]/GameMenu_CMANO/Lua directory instead.

--------------------------------------------------------------------------------------------------------------------------- ]]--


(in reply to Gunner98)
Post #: 6
RE: cmano_helpers.lua - a "library" of lua fu... - 6/8/2018 10:43:36 AM   
NimrodX


Posts: 82
Joined: 5/12/2018
Status: offline
I couldn't sleep so here you go:

https://github.com/rjstone/cmano-lua-helpers

PM me your GitHub username and I'll make you a Collaborator so you can update the file. (Yes, you too can be an evil Collaborator.)

< Message edited by NimrodX -- 6/8/2018 11:12:11 PM >

(in reply to NimrodX)
Post #: 7
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> cmano_helpers.lua - a "library" of lua functions to help with scenarios 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.288