Difference between revisions of "Hooks"

From King Arthur's Gold Wiki
Jump to: navigation, search
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
Hooks are special methods in KAG Beta that are available to be defined in any script, and will run every time.
  
Hooks are special methods in KAG 1.0 that are available to be defined in any script, and will run every time.
+
The list of hooks can be found at Manual/interface/Hooks.txt.
 
+
The list of hooks can be found at Base/Scripts/Interface/Hooks.txt.
+
  
 
== Example ==
 
== Example ==
Line 10: Line 9:
 
<syntaxhighlight lang="cpp" enclose="div">
 
<syntaxhighlight lang="cpp" enclose="div">
 
void onNewPlayerJoin( CRules@ this, CPlayer@ player ) {
 
void onNewPlayerJoin( CRules@ this, CPlayer@ player ) {
     client_AddToChat("Welcome "+player.getUsername()+"!");
+
     if (player !is null) {
 +
      client_AddToChat("Welcome "+player.getUsername()+"!");
 +
    }
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 21:14, 21 August 2013

Hooks are special methods in KAG Beta that are available to be defined in any script, and will run every time.

The list of hooks can be found at Manual/interface/Hooks.txt.

Example

For example, let's say we wanted to show a welcome message to new players that joined. We'd create a mod named "welcome", add it to the gamemodes we want it in, and make a file called "welcome.as" that contained:

void onNewPlayerJoin( CRules@ this, CPlayer@ player ) {
    if (player !is null) {
       client_AddToChat("Welcome "+player.getUsername()+"!");
    }
}

onNewPlayerJoin is a Hook that is run whenever a new Player joins the server. This will send them a Chat message welcoming them.