Advertisement
neatekFb

SourcePawn - player check - Lesson #3

Mar 22nd, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 0.82 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3.  
  4. public OnPluginStart()
  5. {
  6.     RegAdminCmd("sm_sethp", sm_sethp, ADMFLAG_ROOT);
  7. }
  8.  
  9. // sm_sethp <userid> <health>
  10. public Action:sm_sethp(int client, int args)
  11. {
  12.     char userid[86]; // use userid from console 'status'
  13.     char health[86];
  14.     GetCmdArg(1, userid, sizeof(userid));
  15.     GetCmdArg(2, health, sizeof(health));
  16.     int target = GetClientOfUserId(StringToInt(userid));
  17.     if(Client_IsValid(target) && IsPlayerAlive(target)) {
  18.         SetEntityHealth(target, StringToInt(health));
  19.     }
  20. }
  21.  
  22. stock bool:Client_IsValid(client, bool:checkConnected=true)
  23. {
  24.     if (client > 4096) {
  25.         client = EntRefToEntIndex(client);
  26.     }
  27.  
  28.     if (client < 1 || client > MaxClients) {
  29.         return false;
  30.     }
  31.  
  32.     if (checkConnected && !IsClientConnected(client)) {
  33.         return false;
  34.     }
  35.  
  36.     return true;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement