leiizko

Lua Plugin

Recommended Posts

This plugin will allow you to write plugin in Lua, no compiling needed. Just drop into server directory and load the script file and you're done. Most suited for implementation of heavier functions that run slow in gsc script (A star for example). It is up to 10 times faster in my tests.

 

Still early version so there may be bugs and not all functions are implemented. Should be enough to satisfy most needs, but if needed you can use lua ffi api to access structs and other functions.

 

GitHub page

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Looks just right to perhaps fix my Rotu !! Thanks

Error: script runtime error: potential infinite loop in script - killing thread.
(file 'scripts/include/waypoints.gsc', line 177)
 for( i=0; i<level.waypoints[n.wpIdx].childCount; i++ )
 

 

 

 

Edited by =[JFF]=UDieToday-Vince
Asked for something already answered :(

Share this post


Link to post
Share on other sites

Seem to be having some trouble getting this plugin to load.... I have compiled as instructed and end up with 629,472 bytes.. running on ubuntu 18.04... no indication of plugin loading... Error: Unknown function in waypoints.gsc... 

Setup a special VM to try and get this working, same result as my production server.. If anyone has any tips please share.

/serverfiles/plugins

lua.so

serverfiles/lua:

astar.lua

rotu.lua

 

LinuxGSM: relevant parts pasted

fn_parms(){
parms="+set r_xassetnum xmodel=1200 +set rcon_password xxx +set fs_game mods/rotu-r-alpha +set sv_authtoken xxxx +set net_port ${port} +set net_ip ${ip} +set ui_maxclients 64 +set sv_maxclients ${maxplayers} +set sv_punkbuster 0 +set fs_basepath ${serverfiles} +set fs_homepath ${serverfiles} +exec server.cfg +map ${defaultmap}"
}

Server.cfg: contains

loadplugin lua
lua_loadscript "lua/rotu.lua" // script is located in fs_homepath/lua -- homepath verified as accurate.

 

Thanks

Vince
 


 

 

 

Share this post


Link to post
Share on other sites

Try using already compiled plugin from here.

If it still isn't working check if the plugin is loading first, then check for any lua errors (search for "Lua Error:" )

Share this post


Link to post
Share on other sites

Does the plugin work with the latest server version?
I get an error

unknown function
   print( "Square root of " + num + " is " + mysqrt( num ) + "\n" );

plugin was loaded fine

Plugin lua loaded successfully. Server is currently running 1 plugins.


 

Share this post


Link to post
Share on other sites
On 7/23/2020 at 1:10 AM, world said:

Does the plugin work with the latest server version?
I get an error


unknown function
   print( "Square root of " + num + " is " + mysqrt( num ) + "\n" );

plugin was loaded fine


Plugin lua loaded successfully. Server is currently running 1 plugins.


 

Not an expert on the lua implementation but I think the readme.md has a problem 

I found this, https://github.com/leiizko/cod4x_lua_plugin/search?q=mysqrt&type=Code

to me, it's likely something funny in the repository because this code looks like it would work:

https://github.com/leiizko/cod4x_lua_plugin/blob/2f63101c82a752d6831d45744949b421e20421c4/README.md

 

Plugin_ScrAddFunction( "mysqrt" )
31  
32 function mysqrt ()
33 local n = Plugin_Scr_GetFloat( 0 ) --get number (float) from gsc
 
53 num = 123;
54 print( "Square root of " + num + " is " + mysqrt( num ) + "\n" );
55 }

Share this post


Link to post
Share on other sites

Plugin is working with latest server version. Just search your logfile for "Lua Error:" 

 

As for the broken readme, that is just search cutting out lines inbetween. Funnily it looks like a different function.

Share this post


Link to post
Share on other sites
Posted (edited)

Everything I found about lua in logfile. 

Checking if the plugin is not already loaded...
Checking if the plugin file exists and is of correct format...
Parsing plugin function names...
Done parsing plugin function names.
Loading the plugin .so...
Plugin OK! Loading...
Fetching plugin information...
Executing plugin's OnInit...
Adding a plugin command for plugin 0, command name: lua_loadscript.
Command added.
Adding a plugin command for plugin 0, command name: lua_debug.
Command added.
Plugin lua loaded successfully. Server is currently running 1 plugins.



Error: Waited 196 msec for missing asset "codescripts/delete.gsx".
Error: 
Error: ******* script compile error *******
Error: unknown function: (file 'code/lua_test.gsx', line 4)
    print( "Square root of " + num + " is " + mysqrt( num ) + "\n" );
                                              *
************************************
----- Server Shutdown -----
 
With the reason: Server fatal crashed: script compile error
unknown function
    print( "Square root of " + num + " is " + mysqrt( num ) + "\n" );
(see console for details)

 

qconsole.log

Edited by world

Share this post


Link to post
Share on other sites

You are not loading the lua script file

From readme example:

lua_loadscript "lua_scripts/test.lua" // script is located in fs_homepath/lua_scripts

 

  • Like 1

Share this post


Link to post
Share on other sites

It worked after I specified the absolute path to test.lua

lua_loadscript "/home/admin/cod4x_logs/server_2/lua_scripts/test.lua"

 

Share this post


Link to post
Share on other sites

@leiizko Is it possible for the plugin to work with mysql ?


I am getting the error:

****************** Lua Error: ******************

error loading module 'luasql.mysql' from file '/usr/local/lib/lua/5.1/luasql/mysql.so':
	/usr/local/lib/lua/5.1/luasql/mysql.so: wrong ELF class: ELFCLASS64
stack traceback:
	[C]: at 0xdf8d2260
	[C]: in function 'require'
	....cod4x_logs/server_2/lua_scripts/test.lua:8: in function <....cod4x_logs/server_2/lua_scripts/test.lua:3>

************************************************

 

test.lua:

Plugin_ScrAddFunction( "mysqltest" )

function mysqltest ()
  mysql = require "luasql.mysql"

  local env  = mysql.mysql()
  local conn = env:connect('dbName','user','password')
  print(env,conn)

  status,errorString = conn:execute([[CREATE TABLE sample3 (id INTEGER, name TEXT)]])
  print(status,errorString )

  status,errorString = conn:execute([[INSERT INTO sample3 values('12','Raj')]])
  print(status,errorString )

  cursor,errorString = conn:execute([[select * from sample3]])
  print(cursor,errorString)

  row = cursor:fetch ({}, "a")

  file = io.open("/home/admin/cod4x_logs/server_2/lua_scripts/test.txt", "a")
  io.output(file)

  while row do
     io.write("\n" .. string.format("Id: %s, Name: %s", row.id, row.name))
     row = cursor:fetch (row, "a")
  end
  -- close everything
  cursor:close()
  conn:close()
  env:close()
  file:close()
end

 

Share this post


Link to post
Share on other sites

Never tried it, in theory it should work. The error means you have 64bit luasql module, you need 32bit one to work with this plugin.

  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.