Lua Examples: Difference between revisions

From MyGamingTalk
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Lua is a server sided scripting language allowing users to customize their servers and settings to the fullest. Here below you will be able to find many examples on how the Lua Wolf API works in silEnT while getting a general understanding of lua.
Lua is a server sided scripting language allowing users to customize their servers and settings to the fullest. Here below you will be able to find many examples on how the Lua Wolf API works in silEnT while getting a general understanding of lua.


=== et.RegisterModname() ===
= et.RegisterModname() =




Line 16: Line 16:
     et.RegisterModname( "^1MY MOD NAME" )
     et.RegisterModname( "^1MY MOD NAME" )
  end
  end
=  =
 
 
= et.trap_Cvar_Get() =
 
 
'''Example Usage'''
 
function et_InitGame( levelTime, randomSeed, restart )
    maxclients = et.trap_Cvar_Get( "sv_maxclients" )
    et.trap_SendServerCommand( -1, "chat this server has "..maxclients.." slots!" ) -- -1 represents as all clients.
  end
 
'''or'''
 
function et_InitGame( levelTime, randomSeed, restart )
    local silent_anticheat = et.trap_Cvar_Get( "sv_sac" ) -- local represents that this can only be used in this function.
    if silent_anticheat == 1 then
      et.trap_SendServerCommand( -1, "chat This server has silent anticheat enabled!" ) -- -1 represents as all clients.
    else
      et.trap_SendServerCommand( -1, "chat This server has silent anticheat disabled!" ) -- -1 represents as all clients.
    end
end

Latest revision as of 00:11, 3 April 2015

Lua is a server sided scripting language allowing users to customize their servers and settings to the fullest. Here below you will be able to find many examples on how the Lua Wolf API works in silEnT while getting a general understanding of lua.

et.RegisterModname()

Example Usage

function et_InitGame( levelTime, randomSeed, restart )
   local modname = "^1MY MOD NAME"
   et.RegisterModname( modname )
end

or

function et_InitGame( levelTime, randomSeed, restart )
   et.RegisterModname( "^1MY MOD NAME" )
end


et.trap_Cvar_Get()

Example Usage

function et_InitGame( levelTime, randomSeed, restart )
   maxclients = et.trap_Cvar_Get( "sv_maxclients" )
   et.trap_SendServerCommand( -1, "chat this server has "..maxclients.." slots!" ) -- -1 represents as all clients.
end

or

function et_InitGame( levelTime, randomSeed, restart )
   local silent_anticheat = et.trap_Cvar_Get( "sv_sac" ) -- local represents that this can only be used in this function.
   if silent_anticheat == 1 then
      et.trap_SendServerCommand( -1, "chat This server has silent anticheat enabled!" ) -- -1 represents as all clients.
   else
      et.trap_SendServerCommand( -1, "chat This server has silent anticheat disabled!" ) -- -1 represents as all clients.
   end
end