I need LUA help
plausiblesarge
Join Date: 2012-08-02 Member: 154558Members
in Modding
<div class="IPBDescription">And there are no good tutorials online</div>I have done everything according to this tutorial (<a href="http://www.unknownworlds.com/ns2/wiki/index.php/Modding" target="_blank">Modding - NS2 community wiki</a>). I am using my own MyMod_Client.lua, and in order to actually make the game run more than a blackscreen, I am Script.Loading slient.lua at the top of my MyMod_Client.lua file
so my file looks like this
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Script.Load("lua/Client.lua")
function SendKeyEvent(key, down)
if key == InputKey.Q and down then
Shared.Message('Hello World')
end
end
Event.Hook("SendKeyEvent", OnSendKeyEvent)<!--c2--></div><!--ec2-->
According to Decoda, I am passing the Event.Hook("SendKeyEvent", OnSendKeyEvent) function a string and a nil value, despite doing exactly what the wiki page says
Am I doing it wrong? Maybe I do not fully understand LUA properly.
so my file looks like this
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Script.Load("lua/Client.lua")
function SendKeyEvent(key, down)
if key == InputKey.Q and down then
Shared.Message('Hello World')
end
end
Event.Hook("SendKeyEvent", OnSendKeyEvent)<!--c2--></div><!--ec2-->
According to Decoda, I am passing the Event.Hook("SendKeyEvent", OnSendKeyEvent) function a string and a nil value, despite doing exactly what the wiki page says
Am I doing it wrong? Maybe I do not fully understand LUA properly.
Comments
I have absolutely no experience of LUA prior to NS2, and indeed only edit LUA in NS2. My other programming experience is very limited. My advice, just dig into the code and start modding it, rather than writing non-game related stuff for now. You will figure out all you need when playing with the code.
There are no tutorials, but spread amongst the various threads on this forum are hundreds of code snippets. All sorts of things for you to try and use on your own. As you play with these, you get to understand the code and how it works.
I have no idea how or why that code should not work, but if you check my sig you can see I am a very keen, if not very good modder. Sometimes getting your hands dirty is better than trying to learn before you start :)
You need to copy the whole lua directory into a new directory in the folder Natural Selection 2.
THen you run the game with -game "your folder".
In that folder you can start modifying the lua files to learn how the ns2 lua thing works.
Its very complex so you will not understand everything at the beginning, just keep on working.
There are many golbal functions you could use, just try something easy like "Print("Hello"),
which will print "Hello" to your console (you need to write that in an lua file like server.lua.
Another issues you might run into after fixing that is The games own gui system also hooks SendKeyEvent before your hook and is probably swallowing the events
I put together something slightly more complex but what I think you really wanted it avoids the previous mentioned issue <a href="https://dl.dropbox.com/u/36567916/ExampleMod.zip" target="_blank">https://dl.dropbox.com/u/36567916/ExampleMod.zip</a> the interesting code is in TestFrame.lua I included my smart bat launcher that sets the -game command line arg to the folder the bat is in when launching ns2
Also, menumod is awesome.
I just wish someone would provide some nice NS2 lua documentation
As does every modder and programmer here!