Created
September 22, 2016 23:05
-
-
Save shavitush/04093833d610ef97a6971e846edde3c8 to your computer and use it in GitHub Desktop.
SourcePawn example for someone that requested it!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// has all the main functions you will be using. | |
#include <sourcemod> | |
// initialize variables | |
float gF_MyNumber = 0.2; | |
int gI_MyNumber = 3; | |
any gA_MyNumber = 5; // can be everything! | |
char gC_MyChar = view_as<char>('a'); // casting | |
// void OnPluginStart() | |
// called when the plugin loads. | |
public void OnPluginStart() | |
{ | |
// syntax: void PrintToServer(const char[] format, any ...) | |
PrintToServer("Our float is %.02f", gF_MyNumber); | |
PrintToServer("Our integer is %d", gI_MyNumber); | |
PrintToServer("Our any is %d", gA_MyNumber); | |
PrintToServer("Our char is %c", gC_MyChar); | |
// syntax: void PrintToChatAll(const char[] format, any ...) | |
PrintToChatAll("Hello, world!"); | |
// syntax: void RegConsoleCmd(const char[] cmd, ConCmd callback, const char[] description="", int flags=0) | |
RegConsoleCmd("sm_test_console", Command_TestConsole, "Test command!"); | |
// void RegAdminCmd(const char[] cmd, ConCmd callback, int adminflags, const char[] description="", const char[] group="", int flags=0) | |
RegAdminCmd("sm_test_admin", Command_TestAdmin, ADMFLAG_GENERIC, "Test admin command!"); | |
} | |
// void OnPluginEnd() | |
public void OnPluginEnd() | |
{ | |
// for(before; condition; after) | |
// MaxClients is the amount of the maximum player slots so we can iterate | |
for(int i = 1; i <= MaxClients; i++) | |
{ | |
// syntax: bool IsClientConnected(int client) | |
if(!IsClientConnected(i)) | |
{ | |
continue; | |
} | |
// syntax: bool IsClientInGame(int client) | |
if(!IsClientInGame(i)) | |
{ | |
continue; | |
} | |
// syntax: bool IsPlayerAlive(int client) | |
bool bAlive = IsPlayerAlive(i); | |
// \x03 is the team color | |
// \x01 returns to default | |
// %N is a formatting parameter that translates a client index to name | |
PrintToChat(i, "Hey \x03%N\x01! You are %s.", i, bAlive? "alive":"dead"); | |
} | |
} | |
// syntax: public Action FUNCTION(int client, int args) | |
public Action Command_TestConsole(int client, int args) | |
{ | |
// syntax: void ReplyToCommand(int client, const char[] format, any ...) | |
ReplyToCommand(client, "Hey~ the <CONSOLE> command works!"); | |
// must be returned so we don't get 'unknown command'. | |
// Plugin_Continue lets everything run as usual but stops the Action | |
// Plugin_Changed applies changes to references | |
// Plugin_Stop stops the game and plugin hooks | |
// Plugin_Handled stops the game but not the plugin hooks | |
return Plugin_Handled; | |
} | |
// syntax: public Action FUNCTION(int client, int args) | |
public Action Command_TestAdmin(int client, int args) | |
{ | |
// syntax: void ReplyToCommand(int client, const char[] format, any ...) | |
ReplyToCommand(client, "Hey~ the <ADMIN> command works!"); | |
// must be returned so we don't get 'unknown command'. | |
// Plugin_Continue lets everything run as usual but stops the Action | |
// Plugin_Changed applies changes to references | |
// Plugin_Stop stops the game and plugin hooks | |
// Plugin_Handled stops the game but not the plugin hooks | |
return Plugin_Handled; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment