Can We Mess About With Current NS2 Lua Files?

DY357LXDY357LX Playing since day 1. Still can't Comm.England Join Date: 2002-10-27 Member: 1651Members, Constellation
edited August 2010 in Modding
<div class="IPBDescription">Or Is Everything Protected, Serverside Etc?</div>Let's say I wanted to spit out the current NS2 player name to a text file using LUA.

It'd be something like:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> io.output(io.open("playerName.txt","w"))
io.write(playerName)
io.close()<!--c2--></div><!--ec2-->

If I tried sticking that in Player.lua under the line (296) that sets the player name:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->if Server then
        self:SetName(kDefaultPlayerName)
    end<!--c2--></div><!--ec2-->

Would it indeed spit out a text file with the info I set above or would NS2 recognize this bit of rogue code and ignore/spit out errors?

(I can't test it until I get home.)

Comments

  • 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
    The only 2 things that i know of that will cause a mismatch is adding or removing functions from a class and modifying the declarations of network variables in any way.
    Another thing to note is that the lua IO module is disabled/non loadable by lua code. You can always be sneaky and make a dll lua module that just calls luaopen_io thats still exported from there lua dll
  • DixieWolfDixieWolf Join Date: 2010-02-10 Member: 70508Members
    yea, you can put in code. if you try joining a normal NS2 server, then i'm not sure what that would really do. My guess is it would kick you out with some sort of validation error. I know they have some kind of consistency/version check, so you couldn't hack things too much and still join a pub server, but if you wanted to make that change and start a lan game, or you made changes and distributed to others, they could play with you.

    But if you plan on hacking away at the code, then it's better to copy the code to another folder rather than editing it in place
  • DY357LXDY357LX Playing since day 1. Still can&#39;t Comm. England Join Date: 2002-10-27 Member: 1651Members, Constellation
    @fsfod - I have no idea how to do that with LUA .dll's :-/
    I did try the file io.write stuff about 20 minutes ago (before reading these posts) but it resulted in some bizarre camera angles and console errors when I launched NS2 and created a server.

    I'm basically trying to get access to certain NS2 variables/values so I can display them on the LCD of my G15 keyboard.
    (Playername, mapname, server ip, max players, current weapon that sort of thing.)

    Seeing as I can't (yet - more reading to be done) call the NS2 LUA functions from C++, I wanted to have NS2 spit out this info to a text file and then have a C++ .exe that reads the text file and passes it to the keyboard LCD.

    I've been going <a href="http://www.unknownworlds.com/ns2/forums/index.php?showtopic=110787" target="_blank">around in circles</a> for the past week, hitting various walls and wishing I had more free time to learn C++ properly.
  • McGlaspieMcGlaspie www.team156.com Join Date: 2010-07-26 Member: 73044Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Reinforced - Onos, WC 2013 - Gold, Subnautica Playtester
    I don't believe using Lua Modules is going to be possible. As I understand UWE's implementation of Lua they have not included the Module behavior. The support for such thing is controlled at the C/C++ level, not Lua level. Otherwise, you would be able to load potentially (very) dangerous code. Last time I did a globals dump there weren't any functions available for File I/O.

    I've tried using <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->file = io.open('test.txt', 'a')<!--c2--></div><!--ec2-->from numerous places but to no avail. It's returning nil, complaining it's not in global scope. Maybe I'm doing something wrong. *shrugs*

    From what I understand of how Lua was plugged into Spark they've done some really unusual things (as far a Lua integrations go). Hell the simple fact that they've added in the 'Class' construct and implemented simple Inheritance is a perfect example for what I'm referring to. Also, it's worth mentioning they've moved it to LuaJIT so, I've got no idea what else that has impacted as far as standard Lua functionality.

    I would really like to know more information about this. I really wanted to be able to write or add-in a MySQL connector (or other SQL server. Not SQLite!) for the server so game statistics could easily be saved to a database and read by another program; otherwise, we're looking at writing all that crap to a flat file and parsing it with something else, which is 10,000 kinds of bad and slow.
  • 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
    <!--quoteo(post=1792251:date=Aug 6 2010, 03:53 AM:name=McGlaspie)--><div class='quotetop'>QUOTE (McGlaspie @ Aug 6 2010, 03:53 AM) <a href="index.php?act=findpost&pid=1792251"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->they've added in the 'Class' construct and implemented simple Inheritance<!--QuoteEnd--></div><!--QuoteEEnd-->

    The class construct and Inheritance are both from <a href="http://www.rasterbar.com/products/luabind/docs.html" target="_blank">Luabind</a> which the engine uses. I've also used it myself to create dll lua module for ns2 .
  • McGlaspieMcGlaspie www.team156.com Join Date: 2010-07-26 Member: 73044Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Reinforced - Onos, WC 2013 - Gold, Subnautica Playtester
    Nice, and thanks for sharing fsfod. Admittedly, I hadn't looked too deeply into this. Oops.

    So, to make this really useful, I'm curious how we could go about getting game data into the custom modules. Is there a bridging mechanism in Luabind, so we could access object data, or is this a one-way street? I'm assuming it would be a one way street.

    Thinking out loud, LuaBind would be a niffty way for UWE to give us access to the rendering pipeline.
  • FireStormFireStorm Join Date: 2002-11-06 Member: 7390Members
    edited August 2010
    <!--quoteo(post=1792765:date=Aug 7 2010, 11:19 PM:name=McGlaspie)--><div class='quotetop'>QUOTE (McGlaspie @ Aug 7 2010, 11:19 PM) <a href="index.php?act=findpost&pid=1792765"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Thinking out loud, LuaBind would be a niffty way for UWE to give us access to the rendering pipeline.<!--QuoteEnd--></div><!--QuoteEEnd-->

    Luabind has its overhead, I don't know how well it could be included in the rendering pipeline, but I suppose it's not the best way to add engine effects performance-wise... (At least if you were thinking about something like the half-life TriAPI)
  • NeroNero Join Date: 2002-12-20 Member: 11236Members
    <!--quoteo(post=1792251:date=Aug 5 2010, 09:53 PM:name=McGlaspie)--><div class='quotetop'>QUOTE (McGlaspie @ Aug 5 2010, 09:53 PM) <a href="index.php?act=findpost&pid=1792251"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I would really like to know more information about this. I really wanted to be able to write or add-in a MySQL connector (or other SQL server. Not SQLite!) for the server so game statistics could easily be saved to a database and read by another program; otherwise, we're looking at writing all that crap to a flat file and parsing it with something else, which is 10,000 kinds of bad and slow.<!--QuoteEnd--></div><!--QuoteEEnd-->

    I hope server-side is unlocked to load modules. It doesn't make sense restrict this for the reasons you already said.
  • DY357LXDY357LX Playing since day 1. Still can&#39;t Comm. England Join Date: 2002-10-27 Member: 1651Members, Constellation
    edited August 2010
    Not strictly LUA but it's a small update on my original goal that prompted this topic...

    I've been messing with some C++ code and managed this:

    <img src="http://lowstress.co.uk/_uploads/g15-preview-01.jpg" border="0" class="linked-image" />

    Tomorrow I'll read up on accessing the NS2 LUA functions from C++ but now I understand why Flayra is in not rush to do the G15 stuff ;-)
  • FehaFeha Join Date: 2006-11-16 Member: 58633Members
    I would prefer g19 support way more than g15.

    Would be epic if I could bind the macro buttons by a simple "bind g# cmd" in console XD. Doubt it though.
  • DY357LXDY357LX Playing since day 1. Still can&#39;t Comm. England Join Date: 2002-10-27 Member: 1651Members, Constellation
    <!--quoteo(post=1793714:date=Aug 12 2010, 04:41 PM:name=Feha)--><div class='quotetop'>QUOTE (Feha @ Aug 12 2010, 04:41 PM) <a href="index.php?act=findpost&pid=1793714"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I would prefer g19 support way more than g15.

    Would be epic if I could bind the macro buttons by a simple "bind g# cmd" in console XD. Doubt it though.<!--QuoteEnd--></div><!--QuoteEEnd-->

    If I had a G19 to test some code on then I'd give it a try. (No promises of success though! I r amateur!)
    If you come across a G19 emulator then feel free to PM me. (I have a friend who wants some TeamSpeak 3 info on his G19 too.)
Sign In or Register to comment.