Difference between revisions of "My First Script"

From AlliedModders Wiki
Jump to: navigation, search
m
 
Line 1: Line 1:
== Intro ==
+
#REDIRECT [[Introduction to SourceMod Plugins]]
This is a Hello World type plugin tutorial.  Every beginner should learn these first baby steps. The full code is at the bottom.  Now let's begin.
 
 
 
== Includes ==
 
We first need to have our include file added.  This file is located in the addons/sourcemod/scripting/include/ .  Includes are your best friend.  They give you access to all functions Sourcemod and its Module Extensions allow! Note: This always goes at the top of the entire source code.
 
<pawn>
 
#include <sourcemod>
 
</pawn>
 
 
 
== Plugin Info ==
 
Next we give our information, so people who download know who made it and what version they have.
 
<pawn>
 
public Plugin:myinfo = {
 
name = "Hello Gaben",
 
author = "AlliedModders, LLC",
 
description = "Hi",
 
version = "1.0",
 
url = "http://www.sourcemod.net/"
 
};
 
</pawn>
 
 
 
== Initialize ==
 
This function will be used in nearly every plugin available.  It is your friend.  This runs one time when your plugin is loaded.  You will use it to register many of SourceMod's capabilities including Custom Console Commands, CVARs, Natives, and Forwards.
 
 
 
Here I just ran a simple function I created to print a '''LogMessage''' to our log files in '''sourcemod/logs/''' folder.
 
<pawn>
 
public OnPluginStart()
 
{
 
SayHello();
 
}
 
</pawn>
 
 
 
== My Function ==
 
Here is the function ran at OnPluginStart().  Very simple and it uses the '''LogMessage''' function located in '''sourcemod.inc'''. 
 
<pawn>
 
//Print Message to LogFile
 
SayHello()
 
{
 
LogMessage("Hello Gaben | Time: %i", GetTime());
 
}
 
</pawn>
 
 
 
== Conclusion ==
 
Sourcemod scripting has been extended in syntax compared to AMXX.  This allows for better organization.  However there is the learning curve of learning the syntax for each corresponding function or variable.  Study the includes in the scripting/includes folder and you should be fine.  All functions are in there so make them your friend!
 
 
 
Here is the code used in its entirety.
 
<pawn>
 
/* Hello Gaben */
 
 
 
#include <sourcemod>
 
 
 
public Plugin:myinfo = {
 
name = "Hello Gaben",
 
author = "AlliedModders, LLC",
 
description = "Hi",
 
version = "1.0",
 
url = "http://www.sourcemod.net/"
 
};
 
 
 
public OnPluginStart()
 
{
 
SayHello();
 
}
 
 
 
SayHello()
 
{
 
LogMessage("Hello Gaben | Time: %i", GetTime());
 
}
 
</pawn>
 
 
 
[[Category:SourceMod Scripting]]
 
[[Category:SourceMod Development]]
 

Latest revision as of 19:08, 15 November 2007