Comandos Halo Sapp
Comandos Halo Sapp
Comandos Halo Sapp
!
!
!
!
!
!
!
The author of this document is not affiliated with the developer of SAPP.
Table of Contents
Table of Contents
What am I reading?
Introduction to SAPP
Setting up SAPP
SAPP files
Init.txt files
10
Server init.txt
10
SAPP init.txt
11
Commands
12
Command Arguments
12
Player Expression
13
IP/mask
15
Commands Lists
19
19
23
SAPP Logging
23
Map downloading
24
Admin Management
25
Custom Commands
27
28
Player Commands
30
Banning
31
Chat Banning
32
Events
33
33
Naughty Commands
35
39
39
Events
41
2
Lua Scripting
44
Callbacks
46
Functions
48
An example script
51
Credits, Links
54
!
What am I reading?
This document provides information on SAPP and its various features. This document
was made, mainly because SAPP's online documentation is difficult to understand, it's
missing information despite the latest update being out for weeks, or it's just a hassle to
get information.
!
!
!
Before you continue reading, please know that I am not affiliated with SAPP,
seh, or Santa Klaus.
Revision 1.1:
- Initial Revision.
Introduction to SAPP
SAPP is a powerful extension for the dedicated server for Halo PC and Halo Custom
Edition. It has many features to it, with a popular and well-known feature being no-lead
mode, something unique to SAPP. It also has an advanced admin system allowing a
server to have admins without even using an rcon password. It also has rcon brute force
protection for those that do use rcon passwords. There's a lot of features that may be
found to be very useful to server admins.
Setting up SAPP
SAPP is fairly easy to set up and get a game running. You will need to download a few
things in addition to SAPP.
Requirement
Where to get?
SAPP
http://xhalo.tk
PC: http://www.microsoft.com/en-us/
download/details.aspx?id=8510
!
What you're going to want to do first is open the dedicated server installer. Follow the
instructions and install it to whatever directory you choose. If you are purchasing a Halo
PC server from a server provider, it's probably already installed.
You're going to want to decompress SAPP. Choose the version of SAPP that is best for
you; use CE for Custom Edition and PC for the standard version of Halo.
SAPP comes in a .7z archive. I've used a couple different programs for
extracting .7z archives on Windows and OS X, and I do not know of any for
Linux. Here are the programs I use:
Windows: http://www.7-zip.org
(Mac) OS X: http://www.kekaosx.com/en/
You're going to want to move the strings.dll file and the halo[ce]ded.exe file located
inside of the server folder to a safe location. Put them in a folder or rename them. Then,
place the contents of the .7z file inside of the server folder.
You're going to want to open the init.txt file inside of the Halo dedicated server folder
and remove all sv_mapcycle_add commands. Somewhere towards the end, you're
going to want to have the load command and the mapcycle_begin command after it.
These commands are expected to only be ran when the server starts, not when SAPP
starts.
Example init.txt:
sv_name "This is my server. There are many like it, but this one is mine"
sv_maxplayers 16
sv_public 1
sv_mapcycle_timeout 3
sv_rcon_password pass1234
!
load
!
You're going to want to run the dedicated server to initialize the SAPP files. Just run it
once, then close it once you see SAPP load. If it did not load (SAPP version 8.2.2 did
not show up), try entering the load command at console.
!
Renting a Halo server can be somewhat pricey, and you have less control over your
server, but it removes the worry of having to have specific arguments or deal with ports.
If you want all of your dedicated server files, gametypes, and SAPP files to be contained
in the same folder server, use "-path ." as an argument. You will have to manually add
gametypes if you make them. Gametypes are stored as folders in the savegames folder
in the Halo (or Halo CE) folder located in the My Games folder in your Documents
folder.
If you choose to have the default setup (without -path .), your server files will be created
in the Halo (or Halo CE) folder in your My Games folder in your Documents folder. If you
create gametypes in Halo PC, they will be available to the Halo PC dedicated server. If
you create gametypes in Halo CE, it will be available in the Halo CE dedicated server.
Doing this will allow only one SAPP server setup as well as require you to go through
several folders to get to your SAPP files, instead of the files being inside of the server
folder.
You're also going to want to have to be sure that your server's port is open for UDP
packets. If you are behind a router, you may have to resort to forwarding ports.
Remember that each port can only be used by one server. The default port is 2302, but
you may use the -port argument to specify a custom port.
SAPP files
After starting up and loading SAPP for the first time, it will create a number of files and
folders ready to be edited. You do not need to use or know all of the files for a working
server. If you choose to utilize all of SAPP's features, you should keep your
modifications as non-gameplay intrusive as possible, or else people may get frustrated
when playing on your server. I will go over the uses of some of these files. You can use
the files command to list these files, too.
File
Usage
admins.txt
alias.txt
areas.txt
Stores areas from the area command. These areas are per-map.
commands.txt
events.txt
init.txt
ipbans.txt
locations.txt
lua (folder)
Stores lua scripts. These scripts can be loaded with the lua load
command. See Lua Scripts Loading and Unloading for installing
scripts or Lua Scripting for creating scripts.
mapcycle.txt
mapvotes.txt
Stores a list of games that players can vote on. See Mapcycle
and Map Voting.
sapp.log
users.txt
!
9
Init.txt files
In order to use a dedicated server, you need to enter commands in order to open maps.
You can enter these commands, yourself, when the dedicated server starts, or you can
have the dedicated server enter them for you for less of a hassle. Using an init.txt file is
strongly recommended.
Your dedicated server has two init.txt files. One is opened when the Halo Dedicated
Server starts up, located in the server folder. The other file is loaded when SAPP loads,
located in the SAPP folder.
Server init.txt
This file is opened when the server starts. It comes preinstalled with the Halo PC server.
The Halo dedicated server (and client) can read init.txt files with LF (Unix) or CRLF
(Windows) line endings. It cannot read CR line endings, which may occur on Textedit on
older versions of Mac OS X. Your server's init.txt file should contain the load command
so SAPP can be loaded upon startup. If SAPP is not loaded, the dedicated server will
function as a normal dedicated server, with no SAPP features being available. You may
want to have a server name, specify max players, specify whether or not the server is
public (broadcasts to lobby), a mapcycle timeout to reduce time between games, and an
rcon password. You can place the load command anywhere in the init.txt file, but SAPP
commands will not work unless SAPP is loaded.
sv_name "This is my server. There are many like it, but this one is mine"
sv_maxplayers 16
sv_public 1
sv_mapcycle_timeout 3
sv_rcon_password pass1234
!
!
load
10
!
!
!
If you are going to use a mapcycle, using SAPP's mapcycle provides more control,
having some entries work only when a certain number of players are in-game. Halo's
stock mapcycle is still another option. Halo's mapcycle requires that you use
sv_mapcycle_add for each map, then use sv_mapcycle_begin. SAPP's mapcycle only
requires that mapcycle_begin and sapp_mapcycle 1 be used, while having the
mapcycle stored in mapcycle.txt (see Mapcycles for information).
SAPP init.txt
This file contains commands that are loaded whenever SAPP is loaded, and it is
automatically generated if it is nonexistent when SAPP has loaded. Most settings in
SAPP get destroyed when SAPP is unloaded. Scripts also need to be loaded via
commands; they do not automatically get loaded. You can further customize SAPP by
using many of its commands, then storing these customizations here so they are run
every time SAPP is started. These commands do not have to be SAPP commands.
Avoid putting commands in here that will end the game, such as
mapcycle_begin, sv_mapcycle_begin, sv_map, map, etc. Players may
become frustrated if the game ends prematurely when reloading SAPP.
A very useful command to include here would be the no_lead 1 command, to enable nolead. Some other useful commands would be sapp_console 1 to override sv_status and
chat_console_echo 1 to see player chat messages in console.
no_lead 1
sapp_console 1
chat_console_echo 1
11
Commands
There are many commands in SAPP. Commands are required in the Halo Dedicated
Server to start a game.
Command Arguments
Most commands require arguments, usually more than one argument. Arguments tell
SAPP how to run a specific command, and they are separated with spaces. Let's look at
the k command (kick) for example.
!
!
The first part of the command, k, is the command name. "<player_expr>" is the first
argument and "[reason]" is the second argument. In this document, commands use
brackets to show which arguments are required. Do not actually write them down in the
console with brackets. Angle brackets <> are required arguments. Square brackets []
are optional arguments.
Valid: k 1
Valid: k New001
Valid: k 1 Aimbotting
Valid: k New001 Aimbotting
Not Valid: k Aimbotting
When spaces are needed in an argument, you can use quotations "" to surround a
phrase as one argument.
12
Player Expression
If you looked at the k command, it had <player_expr> as one of its commands. Player
expr is used to identify the player that is to be kicked, but there are many ways to get it
to identify the player.
The first method is commonly used on every server, using player indices. Instead of
using sv_players, one can also use the pl command for a simpler list. They have the
same indices, so it is purely preference.
!
The numbers that precede each player is their player index. To kick "Arbiter", for
example, one can use k 1. To kick mrguyman, use k 5.
Another method is by directly using player names. To kick Arbiter, one can use k Arbiter.
This is case sensitive.
There are also wildcard searches. One can use k *e and it will kick all players who have
names that end with a lowercase e. Using k *e* will kick all players who have a
lowercase e in their name. There are numerous other expressions to choose from. Be
careful what you enter, and double check before entering the command. Remember to
use quotations when spaces are needed. It does not hurt to use quotations when they
are not necessary.
13
Player Expression
Description
number
me
rt
bt
pl
admin
rand
randred
randblue
14
IP/mask
Manual IP banning, using the ipbanrange command, requires specifying an IP/mask. v1
admins can also use IP ranges for additional security.
The SAPP website refers to a table for information about it. http://danielmiessler.com/
images/subnetting-table.png. It is fairly confusing looking at the table to understand
what a mask is, and there aren't enough examples, but if it helps, then it helps. Here's a
much simpler table.
Bytes ignored
Range
/24
255.255.255.000
last byte
X.X.X.0 to X.X.X.255
/16
255.255.000.000
X.X.0.0 to X.X.255.255
/8
255.000.000.000
X.0.0.0 to X.255.255.255
!
For those of you who don't quite understand it, an IPv4 address has four numbers, each
one byte in size. These numbers can be between 0 and 255.
!
!
When a command asks for an IP/mask, specifying a mask is optional. You can actually
specify just an IP, such as 192.168.0.1, which will cause the command to affect players
with an IP of 192.168.0.1.
However, IPs can change, and sometimes a subnet mask is needed to cover a range of
IPs. A mask is used to separate IPs into blocks of IP addresses, known as subnets. An
IP/mask in SAPP uses the CIDR format. It is written as an IP, followed by a forward
slash, followed by a number between 0 and 32.
!
!
15
The number after the forward slash specifies the number of 1 bits from significant to
least significant.
!
!
If you notice, the last byte is 00000000. Any bit that is equal to 0 is ignored when
checking for IP, so the last byte is completely ignored.
65.126.40.203
= 01000001.01111110.00101000.11001011!
/24 = 11111111.11111111.11111111.00000000!
65.126.40.203/24 = 01000001.01111110.00101000.11001011!
So, all players that have an IP that starts with 65.126.40 will be IP-banned. Let's say
that this player tried to change her IP and tried to rejoin with an IP of 65.126.40.123.
65.126.40.123
= 01000001.01111110.00101000.01111011!
/24 = 11111111.11111111.11111111.00000000!
65.126.40.123/24 = 01000001.01111110.00101000.01111011!
!
Comparing the two masked IPs:
!
65.126.40.203/24 = 01000001.01111110.00101000.11001011!
65.126.40.123/24 = 01000001.01111110.00101000.01111011!
!
!
16
124.251.131.62
= 01111100.11111011.10000011.00111110!
/19 = 11111111.11111111.11100000.00000000!
124.251.131.62/19 = 01111100.11111011.10000011.00111110!
!
!
= 01111100.11111011.10000001.00011001!
/19 = 11111111.11111111.11100000.00000000!
124.251.129.25/19 = 01111100.11111011.10000001.00011001!
!
!
Comparing the two masked IPs:
!
124.251.131.62/19 = 01111100.11111011.10000011.00111110!
124.251.129.25/19 = 01111100.11111011.10000001.00011001!
!
!
!
Let's say a different player tries to join, having a very similar IP of 124.251.127.62.
124.251.127.62
= 01111100.11111011.01111111.00111110!
/19 = 11111111.11111111.11100000.00000000!
124.251.127.62/19 = 01111100.11111011.01111111.00111110!
!
!
Comparing the two masked IPs:
!
124.251.131.62/19 = 01111100.11111011.10000011.00111110!
124.251.127.62/19 = 01111100.11111011.01111111.00111110!
17
When you use a mask and have it specify over a range of IPs, you may risk affecting
unintended people. The lower the CIDR mask, the more IPs you affect. Reducing the
mask by 1 doubles the affected IPs, so it is an exponential increase of affected IP
addresses.
CIDR Mask
Subnet Mask
Range
IPv4 Addresses
/24
255.255.255.000
X.X.X.0 to X.X.X.255
256
/16
255.255.000.000
X.X.0.0 to X.X.255.255
65536
/8
255.000.000.000
X.0.0.0 to X.255.255.255
16777216
/0
000.000.000.000
0.0.0.0 to 255.255.255.255
4294967296 (all)
!
Also know that routers may leave their IP ranges when changing IP addresses,
depending on ISP.
For more information on subnet masks, there is a page I found on the Internet about it.
http://doc.m0n0.ch/quickstartpc/intro-CIDR.html
18
Commands Lists
Here are several categories of commands. They are separated then sorted
alphabetically to make it easier for you to find the commands. Tab completion does not
work for SAPP commands. You can use the list command, but it is a very disgusting
sight.
Server Management Commands
These commands are used to control many aspects of the server and don't fall into any
specific category.
Command
Description
admin_prefix <string>
afk
afks
alias <player_expr>
anticamp [seconds]
[distance]
anticheat [enabled]
Admin
19
Command
Description
antispam [type]
Admin
balance_teams
block_tc [enabled]
c4_ag [enabled]
change_password <old>
<new>
0
4
collect_aliases [enabled]
[valid only]
cpu
custom_sleep [milliseconds]
cmdstart1 [character]
disable_sj [enabled]
20
Command
Description
dns [ip/domain]
gs_ping_fix [enabled]
inf <player_expr>
ip <player_number>
kdr <player_expr>
list
-1
map
maplist
max_idle [seconds]
msg_prefix <prefix>
mtv <enabled>
no_lead [enabled]
password [password]
sv_password alias
pl
packet_limit [amount]
query_add <value> <value> Add a pair of strings to the query string. I'm
unsure how or if this works.
Admin
query_del <index>
query_list
sapp_console [enabled]
21
Command
Description
save_score [enabled]
say <player_expr>
<message>
Admin
4
say_prefix [enabled]
scrim_mode [enabled]
set_ccolor <color>
!
!
teamup
tell <message>
text <string>
Prints <string>.
unlock_console_log
<enabled>
uptime
v [version]
yeye
!
22
Description
load
N/A
N/A
unload
reload
Admin
!
SAPP Logging
SAPP has logging support, allowing chat messages, commands, game changes, player
joining/leaving (with IP, hash, and name), and other cool things. Logs are, by default,
stored in sapp.log.
Command
Description
Admin
log [enabled]
Enable/disable logging.
log_rotation [KiB]
log_name [name]
log_note <string>
23
Map downloading
In a normal Halo server, the server has to be restarted when a new map is installed. A
nice feature about SAPP is that you can install maps without restarting the server. In
fact, you can download maps the maps using SAPP and it can automatically load the
map.
Command
Description
Admin
map_download <ID>
map_load <map_name>
map_query <string>
maplist
!
Use map_query <string> to search for a map with <string> in its name. You will be
presented with a list of maps that contain <string>, each with numbers (IDs), starting
from 0, next to them. Select a map and use map_download <ID> to download that map.
Note: Almost all of the maps are Halo CE maps. This feature is intended for
Halo CE servers.
24
Admin Management
In my opinion, calling the two different admin types "v1" and "v2" is stupid, because v1
is still supported and the names do not describe the types at all. Regardless, it is
officially called "v1" and "v2".
Command
Description
Admin
rcon_password [password]
sv_rcon_password alias
sapp_rcon <enabled>
!
V1 admins are based on CD hash and optionally IP address.
!
!
Command
Description
admin_change_level
<index> <admin level>
adminadd <player_expr>
<admin level> [IP/mask 1]
[IP/mask 2] etc
adminadd_samelevel [0,1,2]
admindel <index>
admindel_samelevel [0,1,2]
admins
Admin
4
25
!
V2 admins are based on a profile name and password.
Command
Description
Admin
4
admin add_manually
Like "admin add", except that the player name
<player name> <password> must be entered, and it works on offline players.
<admin level>
admin list
admin change_level
<admin> <admin level>
change_password
<old_password>
<new_password>
!
!
!
26
Custom Commands
SAPP allows for custom commands in the commands.txt file in the format of
commandname 'commands' adminlevel. Custom commands performs commands in
succession, separating commands with semicolons.
!
Custom commands.txt:
!
You can also use the cmd command to add or remove custom commands.
Command
Description
Admin
cmd list
!
You can also rename SAPP commands and specify custom levels of the commands.
These settings are destroyed when SAPP is unloaded. If you need these settings to
persist, you will need to place the setcmd for each command in your SAPP's init.txt.
Command
Description
setcmd <command>
<name/level>
Admin
4
27
!
!
Command
Description
Admin
sapp_mapcycle [enabled]
map_skip [%]
skips
mapcycle
mapcycle_add <map>
<game variant> [ID]
mapcycle_del <ID>
mapcycle_begin
map_next
map_prev
map_spec <ID>
!
The map cycle is stored in the mapcycle.txt file, rather than in an init.txt file in the format
of mapname:gamevariant:minplayers:maxplayers. sapp_mapcycle will need to be
enabled.
Example mapcycle.txt:
bloodgulch:CTF:6:16
carousel:Slayer:0:12
ratrace:Race:0:12
sidewinder:CTF:8:16
28
SAPP will skip items if there are fewer players than minplayers or more players than
maxplayers.
Some servers also use map voting, which allows players to choose the next game from
a list when the game has ended. mapvote must be enabled to use map voting.
Command
Description
Admin
mapvote [enabled]
max_votes [votes]
sapp_mapcycle [enabled]
!
Votes are stored in the mapvotes.txt file as map:gamevariant:description, where
description is what is shown to players.
Example mapvotes.txt:
29
Player Commands
These commands are meant to be used by players. All players can execute commands
that have an admin level of -1.
Command
Description
about
-1
info
-1
-1
login <password>
-1
stats
-1
sv_stats
-1
whatsnext
This will tell the user what the next game is.
-1
lead [enabled]
Admin
30
Banning
These commands help remove troublemakers and afk-ers from your server.
Command
Description
afk_kick [seconds]
aimbot_ban [score]
[ban type]
Admin
4
!
0
1
2
3
b <player_expr> [minutes]
[reason]
bans
sv_banlist alias
full_ipban [enabled]
hide_admin [enabled]
ipban <player_expr>
[minutes] [reason]
iprangeban <name>
<IP/mask> [reason]
[minutes]
k <player_expr> [reason]
ping_kick [ping]
31
Command
Description
Admin
refresh_ipbans
ub <index>
Chat Banning
Another useful feature is the ability to ban players from chatting. Like admin
management, there are two flavors of chat banning: textban (CD-key hash-based) and
mute (IP-based).
Textban:
Command
Description
Admin
textban <player_expr>
[minutes]
textbans
textunban <index>
Mute:
Command
Description
Admin
mute <player_expr>
[minutes]
mutes
unmute <index>
32
Events
Events were introduced long before Lua scripting as a simple way to have custom
actions to occur in certain conditions. Events are stored in events.txt.
Events can be listed and removed in console, but they cannot be added. You must
manually add events to the events.txt file yourself and reload SAPP to add new events.
Command
Description
Admin
events
eventdel <index>
Remove event.
Type:
0 = Global String
1 = Global Integer
2 = Global Float
3 = Player String
4 = Player Integer
5 = Player Float
var_del <var>
List variables.
var_list
Installing lua scripts is fairly simple. First, you will want to have "lua 1" in your SAPP's
init.txt file to enable callbacks. It's disabled by default. To install a script, place the script
in the lua folder, then call lua_load <script name> to activate it.
33
Command
Description
Admin
lua <enabled>
lua_api_v
lua_load <script>
lua_unload <script>
!
!
34
Naughty Commands
These commands are meant for tweaking the game, changing things and such. You can
use these in your scripts or events. You can also disable them by enabling scrim mode.
All commands require level 4 admin access, which can be changed using the setcmd
command. If you do use the setcmd command, you should put it in your SAPP's init.txt.
When amount is one of the arguments, you can specify how you wish to modify the
value.
[amount]
Description
: (or nothing)
!
!
When a tag path is needed, you can open the map in a map editor to find the tag paths
and classes. For example, the banshee is a vehi tag and has the path
vehicles\banshee\banshee_mp.
Command
Description
35
Command
Description
area list
area listall
battery <player_expr>
[amount] [type]
boost <player_expr>
ctf_score <player_expr>
[amount]
ctf_score_team <team>
[amount]
disable_all_objects <team>
<disable>
disable_all_vehicles <team>
<disable>
36
Command
Description
disable_object <object_name>
[team]
disabled_objects
enable_object <ID>
god <player_expr>
hp <player_expr> [amount]
kill <player_expr>
Kills <player_expr>
lag <player_expr>
loc list
loc listall
olist [g/w/v]
s <player_expr> [amount]
sh <player_expr> [amount]
slayer_score <player_expr>
[amount]
slayer_score_team <team>
[amount]
37
Command
Description
st <player_expr> [red|blue]
t <player_expr>
<location_name>
tp <player_expr>
<player_number>
ungod <player_expr>
unlag <player_expr>
vdel <player_number>
vexit <player_expr>
wadd <player_expr>
wdel <player_expr>
<weapon_number>
38
Variable
Description
$n
Player index.
$name
Player name.
$hash
$ip
Player's ip.
$tk
$kills
$assists
$deaths
$suicides
$streak
$combo
$score
$botscore
39
Variable
Description
$x, $y, $z
$hp
$sh
$invis
$team
$oteam
$lvl
$map
$mode
$gt
$ffa
$svname
$pn
$reds
$blues
$rand
!
!
40
Events
The format for an event in events.txt is event_name [condition] 'command'. [condition] is
in square brackets, so it is optional. Command must be single quotes, and like custom
commands, you can use multiple commands in succession with semicolons.
Event
Description
event_aenter
event_alive
event_camp
event_join
event_kill
event_login
event_score
event_snap
event_start
event_suicide
event_teamswitch
41
Event
Description
event_tk
event_venter
event_vexit
event_warp
event_wdrop
!
Variables can be placed in either condition or the command for more complex events. In
commands, these variables are replaced with their respective value. One must use
operators for comparing variables in conditions.
Condition Description
:
Is equal to string.
!:
Is equal to value.
!=
>
<
>=
<=
!
Lastly, we must write a command (or list of commands separated with semicolons) to
get executed when the event has occurred and the condition has been met (if there is a
condition). Single quotes must be used to encompass the command, thus single quotes
cannot be used in the command for writing English contractions (don't, won't, shouldn't,
42
shan't, mustn't, she'd, etc.), so they must be spelled out (do not, would not, should not,
shall not, must not, she would, etc.).
There are also a couple commands that can only be used in events used for delaying
the script.
Command
Description
wait [ms]
w8 [s]
!
An example of an event: Let's say we want to announce when a player gets a killing
spree. First, we need to find the correct event, which is event_kill. Next, we need to
have it continue when a player gets 5 kills without dying. Then, we must have it actually
announce that the player "is on a killing spree!".
Let's break it up: event_kill is the event. $streak=5 checks if the player's $streak variable
is equal to 5. 'say * "$name is on a killing spree"' executes the say command, replacing
$name with the name of the player.
43
Lua Scripting
New to SAPP, Lua scripting is a very versatile way of controlling the game. When you
get a syntax error in one of your scripts, SAPP will display the error on the console upon
loading SAPP, and it will become impossible to load the script with lua_load. Be sure to
keep eyes on the console.
For editing scripts, I recommend a text editor with syntax highlighting. There are
numbers to choose from, and most of them are free. You can, of course, edit lua scripts
with your operating system's text editor (Notepad on Windows, Textedit on OS X,
depends on Linux distribution on Linux).
The first thing you may want to put down is the API version for the script. SAPP will not
accept scripts that are too new or too old, and it needs this to determine if the script is
compatible. The variable is api_version, and it takes up only one line. At the time I wrote
this, the current version was 1.3.0.0, but you can get the version with lua_api_v. This is
a global variable, and it should be placed outside of any function in the script.
api_version = "1.3.0.0"!
44
There are two functions that are required for any function for your script: OnScriptLoad()
and OnScriptUnload().
function OnScriptLoad()!
end!
function OnScriptUnload()!
!
end!
!
You aren't required to have anything in the functions, but they are required to be
present. If you want, you can write each function in one line.
You cannot get any callbacks registered if you do not use OnScriptLoad(). You should
undo permanent changes made to the game with OnScriptUnload(), if applicable.
45
Callbacks
The bare minimums of a script is api_version, OnScriptLoad(), and OnScriptUnload().
Once you have those, you have a script, but then your script does nothing. Scripts can
use functions that are run when events occur, known as a callback. In OnScriptLoad(),
you need to use register_callback() for registering callbacks. PlayerIndex is an integer
between 1 and 16 for the player. All arguments other than PlayerIndex are strings.
Callback
Arguments
Description
EVENT_ALIVE
PlayerIndex
EVENT_AREA_ENTER
PlayerIndex,AreaName
EVENT_AREA_EXIT
PlayerIndex,AreaName
EVENT_BETRAY
EVENT_CAMP
PlayerIndex,CampKills
EVENT_CHAT
PlayerIndex,Message
EVENT_DIE
PlayerIndex,KillerIndex
EVENT_GAME_END
EVENT_GAME_START
EVENT_JOIN
PlayerIndex
EVENT_KILL
46
Callback
Arguments
Description
EVENT_LEAVE
PlayerIndex
EVENT_LOGIN
PlayerIndex
EVENT_SCORE
PlayerIndex
EVENT_SNAP
PlayerIndex,SnapScore
EVENT_SPAWN
PlayerIndex
EVENT_SUICIDE
PlayerIndex
EVENT_TEAM_SWITCH
PlayerIndex
EVENT_VEHICLE_ENTER
PlayerIndex
EVENT_VEHICLE_EXIT
PlayerIndex
EVENT_WARP
PlayerIndex
EVENT_WEAPON_DROP
PlayerIndex,Slot
EVENT_WEAPON_PICKUP PlayerIndex,Type,Slot
!
You cannot get any callbacks registered if you do not use OnScriptLoad().
47
Functions
Functions are necessary for your script to have any effect on the game.
Function
Description
execute_command(command)
Execute a command.
get_var(PlayerIndex, variable)
say(PlayerIndex,message)
say_all(message)
cprint(message,color)
rand(min,max)
rand(max)
rand()
to_real_index(PlayerIndex)
to_player_index(RealPlayerIndex)
player_present(PlayerIndex)
player_alive(PlayerIndex)
get_player(PlayerIndex)
get_dynamic_player(PlayerIndex)
get_object_memory(ObjectID)
spawn_object(type,name,x,y,z)
destroy_object(ObjectID)
Deletes an object.
sync_ammo(ObjectID)
assign_weapon(ObjectID,
PlayerIndex)
48
There are also some I/O functions for reading and writing memory on Halo for advanced
scripts. Reading returns the read value on success, and writing returns true on success,
while failure simply crashes the server (see below).
Reading:
Function
Description
read_char(address)
read_byte(address)
read_short(address)
read_word(address)
read_int(address)
read_dword(address)
read_float(address)
read_double(address)
read_string(address)
!
Writing:
Function
Description
write_char(address,value)
write_byte(address,value)
write_short(address,value)
write_word(address,value)
write_int(address,value)
write_dword(address,value)
write_float(address,value)
write_double(address,value)
write_string(address,value)
You can use the lua_call command to call lua functions from your script.
49
!
By default, these functions do no checks, and will crash the server if any access
violation occurs. Access violations can occur when reading/writing an invalid address or
writing to a read-only address.
To prevent crashes from reading/writing invalid addresses allow writing to Halo's code,
you will need to turn on safe_read or safe_write, depending on what you're doing. This
will also cause read_xxxx and write_xxxx to return true or false depending on success.
However, this will also cause the read/write functions to take longer, so turn it off when
you're done reading/writing.
Function
Description
safe_read(boolean)
safe_write(boolean)
!
If you're interested in changing Halo's code, you can use the new signature scanning
function which scans for bytes. Use masked bytes (??) for bytes that can vary, such as
pointers. Do not use spaces or have it start with a masked byte. Store the address of
your result in a variable so you do not lose it or have to search more than once.
Function
Description
sig_scan(signature)
!
You should be very careful with editing Halo's code as you can cause the Halo server to
crash or do unpredictable things. When editing Halo's code, you must use safe_write,
because code is read-only, or else Halo will crash.
50
An example script
A script for kicking players who are named New001.
api_version
=
"1.3.0.0"
function
OnScriptLoad()
register_callback(cb['EVENT_JOIN'],
"OnPlayerJoin")
end
function
OnScriptUnload()
end
function
OnPlayerJoin(PlayerIndex)
local
name
=
get_var(PlayerIndex,"$name")
if(name
==
"New001")
then
execute_command('k
'
..
PlayerIndex
..
'
"Get
a
name."')
end
end
!
Let's examine it part by part. First, we have the required api_version.
!
api_version
=
"1.3.0.0"
!
Next, we have the function OnScriptLoad().
function
OnScriptLoad()
register_callback(cb['EVENT_JOIN'],
"OnPlayerJoin")
end
EVENT_JOIN
PlayerIndex
!
We aren't doing very much with the script or making any permanent changes, so we can
leave it blank.
!
!
51
function
OnPlayerJoin(PlayerIndex)
local
name
=
get_var(PlayerIndex,"$name")
if(name
==
"New001")
then
execute_command('k
'
..
PlayerIndex
..
'
"Get
a
name."')
end
end
This particular function is where the script takes action. Let's look at it line-by-line:
This stores a variable into the local variable name. Local variables are destroyed after
they leaves the function's scope. According to the list of variables:
$name
Player name.
!
We are comparing name against the name "New001".
!
if(name
==
"New001")
then
!
If the player's name is New001, it will continue to the block. If it is not, it will skip to the if
statement's end.
We now execute a command, concatenating 'k ', PlayerIndex, and ' "Get a name."'.
The k command:
k <player_expr> [reason]
!
!
52
Notice that we are using single quotes for the strings, and double quotes for "Get a
name.", because "Get a name." is one argument, which must be encompassed with
double quotes, and a double quote will not terminate a single quote string. You could
use double quotes, but you would need to use an escape sequence, \" instead of a
simple double quote.
To summarize:
!
!
53
Credits, Links
!
002 - I am the guy who wrote this. Hi there!
seh - The guy who develops SAPP. Thanks a lot!
OpenCarnage (http://opencarnage.net) - This is an awesome forum; I check my private
messages almost every day if you want to contact me here.
SAPP's official website (http://xhalo.tk) - This is where you get SAPP.
54