I need LUA help

plausiblesargeplausiblesarge Join Date: 2012-08-02 Member: 154558Members
<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.

Comments

  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    Is that a NS2 code example, or is that just an example of lua code? I've never tried that. All I've learned about LUA programming for my mods, has come by playing with the code and making the mods!

    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 :)
  • JimWestJimWest Join Date: 2010-01-03 Member: 69865Members, Reinforced - Silver
    You can't use the code from the tutorial, it was written long before and much has changed now.
    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.
  • fsfodfsfod uk Join Date: 2004-04-09 Member: 27810Members, NS2 Developer, Constellation, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Subnautica Playtester, NS2 Community Developer, Pistachionauts
    OnSendKeyEvent should be SendKeyEvent I guess it was a copy paste error by SgtBarlow also Shared.Message prints to the console idk if you were expecting it to show a message box and others have said the page is a bit outdated
    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
  • plausiblesargeplausiblesarge Join Date: 2012-08-02 Member: 154558Members
    edited August 2012
    fsfod you are awesome. There is no "example" or "template" mod as far as I can see available online, so you may want to post this somewhere. The only one I was able to find is the one mentioned above.

    Also, menumod is awesome.

    I just wish someone would provide some nice NS2 lua documentation
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    <!--quoteo(post=1957550:date=Aug 5 2012, 12:51 PM:name=plausiblesarge)--><div class='quotetop'>QUOTE (plausiblesarge @ Aug 5 2012, 12:51 PM) <a href="index.php?act=findpost&pid=1957550"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I just wish someone would provide some nice NS2 lua documentation<!--QuoteEnd--></div><!--QuoteEEnd-->

    As does every modder and programmer here!
Sign In or Register to comment.