Guest User

Test Script

a guest
Dec 10th, 2011
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Samp.API;
  5. using Samp.Scripts;
  6. using Samp.Client;
  7.  
  8. namespace testscript
  9. {
  10.     class test : ScriptBase
  11.     {
  12.         public override void OnLoad() // When the script loads
  13.         {
  14.             /* Add Event Handlers In Here*/
  15.             Player.OnPlayerCommandText += new EventHandler<Player.OnPlayerCommandTextEventArgs>(Player_OnPlayerCommandText); // Adding the OnPlayerCommandText Event Handler
  16.         }
  17.  
  18.         public override void OnUnload() // When the script unloads
  19.         {
  20.             /* Deconstruct Event Handlers In Here [Must]*/
  21.             Player.OnPlayerCommandText -= new EventHandler<Player.OnPlayerCommandTextEventArgs>(Player_OnPlayerCommandText); // Removing the OnPlayerCommandText Event Handler
  22.         }
  23.  
  24.         private void Player_OnPlayerCommandText(object sender, Player.OnPlayerCommandTextEventArgs e) // Declaring the function which will handle OnPlayerCommandText Event
  25.         {
  26.             string[] cmd = e.text.Split(' '); //Declaring the string array which will split the command, the player wrote on console into words
  27.             if (String.Compare(cmd[0], "/test") == 0) // Comparing the if the first word of the command is /test or not
  28.             {
  29.                 int playerid = e.player.ID; // Get the player id who wrote the message
  30.                 //If so then it will trigger everything in here
  31.                 NativeFunctionRequestor.RequestFunction("SendClientMessage", playerid, -1, @"I love {00FF00} C#!"); // Requesting the function which is SendClientMessage with it's specific parameters
  32.             }
  33.         }
  34.     }
  35. }
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment