silEnT's Lua API is aiming to be fully compatible to etpro's Lua API. Differences between silEnT's and etpro's Lua API are described in this documentation.
*Marks differences between silEnT's and etpro's Lua API
lua_status
lua_status
lua_modules
lua_allowedModules
Changing either cvar will cause all currently loaded modules to quit and be unloaded until the next map_restart, reset_match or map change.
*clientnum = et.ClientNumberFromString( string )
-- get number from client with partial name match 'ETPla' clientnum = et.ClientNumberFromString("ETPla")
fd, len = et.trap_FS_FOpenFile( filename, mode )
fd, len = et.trap_FS_FOpenFile("mymodule.log", et.FS_READ)
filedata = et.trap_FS_Read( fd, count )
fd, len = et.trap_FS_FOpenFile("mymodule.log", et.FS_READ) if len ~= -1 then filedata = et.trap_FS_Read(fd, len) end et.trap_FS_FCloseFile(fd)
count = et.trap_FS_Write( filedata, count, fd )
fd, len = et.trap_FS_FOpenFile("mymodule.log", et.FS_APPEND) content = "MODEVENT: X Y: Player X does something with player Y.\n" if len ~= -1 then count = et.trap_FS_Write(content, string.len(content), fd) end et.trap_FS_FCloseFile(fd)
et.trap_FS_Rename( oldname, newname )
et.trap_FS_Rename("mymodule.log", "mymodule.bak")
et.trap_FS_FCloseFile( fd )
fd, len = et.trap_FS_FOpenFile("mymodule.log", et.FS_READ) -- read file content here et.trap_FS_FCloseFile(fd)
*et.G_ClientSound( clientnum, soundindex )
-- play a sound for client #3 only soundindex = et.G_SoundIndex("sound/world/alarm_01.wav") et.G_ClientSound(3, soundindex)
milliseconds = et.trap_Milliseconds()
milliseconds = et.trap_Milliseconds()
et.G_Damage( target, inflictor, attacker, damage, dflags, mod )
-- do 50 damage with no protection (dflags = 32) on client #0 -- with MOD_UNKNOWN (mod = 0) as <world> entity (inflictor, attacker = 1022) et.G_Damage(0, 1022, 1022, 50, 32, 0)
DAMAGE_RADIUS 1 // damage was indirect DAMAGE_HALF_KNOCKBACK 2 // do less knockback DAMAGE_NO_KNOCKBACK 8 // do not affect velocity, just view angles DAMAGE_NO_TEAM_PROTECTION 16 // armor, shields, invulnerability, and godmode have no effect DAMAGE_NO_PROTECTION 32 // armor, shields, invulnerability, and godmode have no effect DAMAGE_DISTANCEFALLOFF 64 // distance falloff
*flooding = et.ClientIsFlooding( clientnum )
if et.ClientIsFlooding(clientnum) == 1 then -- client is flooding, do something end
*et.G_AddSkillPoints( ent, skill, points )
-- add 100.5 points to heavy weapons skill (skill = 5) of client #0 et.G_AddSkillPoints(0, 5, 100.5)
*et.G_LoseSkillPoints( ent, skill, points )
-- remove 100.5 points from heavy weapons skill (skill = 5) of client #0 et.G_LoseSkillPoints(0, 5, 100.5)
(variable) = et.gentity_get ( entnum, fieldname, arrayindex )
et.gentity_set( entnum, fieldname, arrayindex, value )
*permission = et.G_shrubbot_permission( ent, flag )
-- check if client #1 has permission for flag "C" if et.G_shrubbot_permission(1, "C") == 1 then -- client has permission, do something end
*level = et.G_shrubbot_level( ent )
-- get shrubbot level for client #2 level = et.G_shrubbot_level(2)
et_ClientSpawn( clientNum, revived, *teamChange, *restoreHealth )
intercepted = et_ClientCommand( clientNum, command )
intercepted = et_ConsoleCommand( *command )
(customObit) = et_Obituary( victim, killer, meansOfDeath )
function et_Obituary(victim, killer, meansOfDeath) if victim == killer and meansOfDeath == 26 then customObit = "%s ^7had an ^1EXPLOSIVE ^7relationship with his dynamite." return string.format(customObit, et.gentity_get(victim, "pers.netname")) end end
*et.CS_PLAYERS
et.EXEC_NOW
et.EXEC_INSERT
et.EXEC_APPEND
et.FS_READ
et.FS_WRITE
et.FS_APPEND
et.FS_APPEND_SYNC
et.SAY_ALL
et.SAY_TEAM
et.SAY_BUDDY
et.SAY_TEAMNL
et.HOSTARCH
*LUA_PATH
*LUA_CPATH
*LUA_DIRSEP
Like qagame, lua modules are unloaded and reloaded on map_restart and map changes. This means that all global variables and other information is lost. Modules may choose to store persistent data in cvars or external files.
Q: OMG I hate the libary prefix et.* on everything!
A: Use the following code to remove the prefix:
table.foreach(et, function(func, value) _G[func] = value; end)
Q: How do I reload my lua module without restarting the whole server?
A: Use map_restart, reset_match or simply change the map.
Q: OMG my lua module doesn't work!
A: Make sure you added your module's filename to the lua_modules cvar (e.g. set lua_modules "mymodule.lua").