Can We Mess About With Current NS2 Lua Files?
DY357LX
Playing since day 1. Still can't Comm.England Join Date: 2002-10-27 Member: 1651Members, Constellation
<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.)
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
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
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
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.
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.
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 .
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.
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)
I hope server-side is unlocked to load modules. It doesn't make sense restrict this for the reasons you already said.
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 ;-)
Would be epic if I could bind the macro buttons by a simple "bind g# cmd" in console XD. Doubt it though.
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.)