Difference between revisions of "ETPro:Lua Sample Code"
From WolfWiki
m |
Rookie One (Talk | contribs) (There's no such thing as et.G_Printf. Changed everything to et.G_Print. Also fixed various typos.) |
||
Line 10: | Line 10: | ||
function test_lua_functions() | function test_lua_functions() | ||
et.trap_Cvar_Set( "bla1", "bla2" ) | et.trap_Cvar_Set( "bla1", "bla2" ) | ||
− | et. | + | et.G_Print( "sv_hostname [" .. et.trap_Cvar_Get( "sv_hostname" ) .. "]\n" ) |
− | et. | + | et.G_Print( "configstring 1 [" .. et.trap_GetConfigstring( 1 ) .. "]\n" ) |
et.trap_SetConfigstring( 4, "yadda test" ) | et.trap_SetConfigstring( 4, "yadda test" ) | ||
− | et. | + | et.G_Print( "configstring 4 [" .. et.trap_GetConfigstring( 4 ) .. "]\n" ) |
et.trap_SendConsoleCommand( et.EXEC_APPEND, "cvarlist *charge*\n" ) | et.trap_SendConsoleCommand( et.EXEC_APPEND, "cvarlist *charge*\n" ) | ||
et.trap_SendServerCommand( -1, "print \"Yadda yadda\"" ) | et.trap_SendServerCommand( -1, "print \"Yadda yadda\"" ) | ||
− | et. | + | et.G_Print( "gentity[1022].classname = [" .. et.gentity_get( 1022, "classname" ) .. "]\n" ) |
end | end | ||
-- called when game inits | -- called when game inits | ||
function et_InitGame( levelTime, randomSeed, restart ) | function et_InitGame( levelTime, randomSeed, restart ) | ||
− | et. | + | et.G_Print( "et_InitGame [" .. levelTime .. "] [" .. randomSeed .. "] [" .. restart .. "]\n" ) |
et.RegisterModname( "bani qagame " .. et.FindSelf() ) | et.RegisterModname( "bani qagame " .. et.FindSelf() ) | ||
-- test_lua_functions() | -- test_lua_functions() | ||
Line 29: | Line 29: | ||
function et_RunFrame( levelTime ) | function et_RunFrame( levelTime ) | ||
if math.mod( levelTime, 1000 ) == 0 then | if math.mod( levelTime, 1000 ) == 0 then | ||
− | -- et. | + | -- et.G_Print( "et_RunFrame [" .. levelTime .. "]\n" ) |
end | end | ||
end | end | ||
Line 36: | Line 36: | ||
-- return 1 if intercepted, 0 if passthrough | -- return 1 if intercepted, 0 if passthrough | ||
function et_ClientCommand( clientNum, cmd ) | function et_ClientCommand( clientNum, cmd ) | ||
− | et. | + | et.G_Print( "et_ClientCommand: [" .. et.trap_Argc() .. "] [" .. cmd .. "]\n" ) |
return 0 | return 0 | ||
end | end | ||
Line 43: | Line 43: | ||
-- return 1 if intercepted, 0 if passthrough | -- return 1 if intercepted, 0 if passthrough | ||
function et_ConsoleCommand() | function et_ConsoleCommand() | ||
− | et. | + | et.G_Print( "et_ConsoleCommand: [" .. et.trap_Argc() .. "] [" .. et.trap_Argv(0) .. "]\n" ) |
if et.trap_Argv(0) == "listmods" then | if et.trap_Argv(0) == "listmods" then | ||
i = 1 | i = 1 | ||
Line 49: | Line 49: | ||
modname, signature = et.FindMod( i ) | modname, signature = et.FindMod( i ) | ||
if modname and signature then | if modname and signature then | ||
− | et. | + | et.G_Print( "vm slot [" .. i .. "] name [" .. modname .. "] signature [" .. signature .. "]\n" ) |
et.IPCSend( i, "hello" ) | et.IPCSend( i, "hello" ) | ||
end | end | ||
Line 61: | Line 61: | ||
-- called when we receive an IPC from another VM | -- called when we receive an IPC from another VM | ||
function et_IPCReceive( vmnumber, message ) | function et_IPCReceive( vmnumber, message ) | ||
− | et. | + | et.G_Print( "IPCReceive [" .. et.FindSelf() .. "] from [" .. vmnumber .. "] message [" .. message .. "]\n" ) |
end | end | ||
-- called for every ClientConnect | -- called for every ClientConnect | ||
function et_ClientConnect( clientNum, firstTime, isBot ) | function et_ClientConnect( clientNum, firstTime, isBot ) | ||
− | et. | + | et.G_Print( "et_ClientConnect: [" .. clientNum .. "] [" .. firstTime .. "] [" .. isBot .. "]\n" ) |
-- return "go away" | -- return "go away" | ||
return nil | return nil | ||
Line 73: | Line 73: | ||
-- called for every ClientDisconnect | -- called for every ClientDisconnect | ||
function et_ClientDisconnect( clientNum ) | function et_ClientDisconnect( clientNum ) | ||
− | et. | + | et.G_Print( "et_ClientDisconnect: [" .. clientNum .. "]\n" ) |
end | end | ||
-- called for every ClientBegin | -- called for every ClientBegin | ||
function et_ClientBegin( clientNum ) | function et_ClientBegin( clientNum ) | ||
− | et. | + | et.G_Print( "et_ClientBegin: [" .. clientNum .. "]\n" ) |
end | end | ||
-- called for every ClientUserinfoChanged | -- called for every ClientUserinfoChanged | ||
function et_ClientUserinfoChanged( clientNum ) | function et_ClientUserinfoChanged( clientNum ) | ||
− | et. | + | et.G_Print( "et_ClientUserinfoChanged: [" .. clientNum .. "] = [" .. et.trap_GetUserinfo( clientNum ) .. "]\n" ) |
end | end | ||
− | -- called for every | + | -- called for every trap_Print |
function et_Print( text ) | function et_Print( text ) | ||
− | -- et. | + | -- et.G_Print( "et_Print [" .. text .. "]\n" ) |
end | end | ||
function et_ClientSay( cno, mode, text ) | function et_ClientSay( cno, mode, text ) | ||
− | et.G_Printf( "et_ClientSay [ | + | et.G_Printf( "et_ClientSay [" .. cno .. "] [" .. mode .. "] [" .. text .. "]\n" ) |
et.G_Say( cno, mode, text ) | et.G_Say( cno, mode, text ) | ||
return 1 | return 1 |
Revision as of 17:59, 11 November 2005
This code does nothing useful besides demonstrate and exercise the ETPro:Lua Mod API
-- printf wrapper function et.G_Printf(...) et.G_Print(string.format(unpack(arg))) end -- test some of the supported etpro lua functions function test_lua_functions() et.trap_Cvar_Set( "bla1", "bla2" ) et.G_Print( "sv_hostname [" .. et.trap_Cvar_Get( "sv_hostname" ) .. "]\n" ) et.G_Print( "configstring 1 [" .. et.trap_GetConfigstring( 1 ) .. "]\n" ) et.trap_SetConfigstring( 4, "yadda test" ) et.G_Print( "configstring 4 [" .. et.trap_GetConfigstring( 4 ) .. "]\n" ) et.trap_SendConsoleCommand( et.EXEC_APPEND, "cvarlist *charge*\n" ) et.trap_SendServerCommand( -1, "print \"Yadda yadda\"" ) et.G_Print( "gentity[1022].classname = [" .. et.gentity_get( 1022, "classname" ) .. "]\n" ) end -- called when game inits function et_InitGame( levelTime, randomSeed, restart ) et.G_Print( "et_InitGame [" .. levelTime .. "] [" .. randomSeed .. "] [" .. restart .. "]\n" ) et.RegisterModname( "bani qagame " .. et.FindSelf() ) -- test_lua_functions() end -- called every server frame function et_RunFrame( levelTime ) if math.mod( levelTime, 1000 ) == 0 then -- et.G_Print( "et_RunFrame [" .. levelTime .. "]\n" ) end end -- called for every clientcommand -- return 1 if intercepted, 0 if passthrough function et_ClientCommand( clientNum, cmd ) et.G_Print( "et_ClientCommand: [" .. et.trap_Argc() .. "] [" .. cmd .. "]\n" ) return 0 end -- called for every consolecommand -- return 1 if intercepted, 0 if passthrough function et_ConsoleCommand() et.G_Print( "et_ConsoleCommand: [" .. et.trap_Argc() .. "] [" .. et.trap_Argv(0) .. "]\n" ) if et.trap_Argv(0) == "listmods" then i = 1 repeat modname, signature = et.FindMod( i ) if modname and signature then et.G_Print( "vm slot [" .. i .. "] name [" .. modname .. "] signature [" .. signature .. "]\n" ) et.IPCSend( i, "hello" ) end i = i + 1 until modname == nil or signature == nil return 1 end return 0 end -- called when we receive an IPC from another VM function et_IPCReceive( vmnumber, message ) et.G_Print( "IPCReceive [" .. et.FindSelf() .. "] from [" .. vmnumber .. "] message [" .. message .. "]\n" ) end -- called for every ClientConnect function et_ClientConnect( clientNum, firstTime, isBot ) et.G_Print( "et_ClientConnect: [" .. clientNum .. "] [" .. firstTime .. "] [" .. isBot .. "]\n" ) -- return "go away" return nil end -- called for every ClientDisconnect function et_ClientDisconnect( clientNum ) et.G_Print( "et_ClientDisconnect: [" .. clientNum .. "]\n" ) end -- called for every ClientBegin function et_ClientBegin( clientNum ) et.G_Print( "et_ClientBegin: [" .. clientNum .. "]\n" ) end -- called for every ClientUserinfoChanged function et_ClientUserinfoChanged( clientNum ) et.G_Print( "et_ClientUserinfoChanged: [" .. clientNum .. "] = [" .. et.trap_GetUserinfo( clientNum ) .. "]\n" ) end -- called for every trap_Print function et_Print( text ) -- et.G_Print( "et_Print [" .. text .. "]\n" ) end function et_ClientSay( cno, mode, text ) et.G_Printf( "et_ClientSay [" .. cno .. "] [" .. mode .. "] [" .. text .. "]\n" ) et.G_Say( cno, mode, text ) return 1 end