Advertisement
Guest User

playerFunctions

a guest
Jun 22nd, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 9.66 KB | None | 0 0
  1. unit playerFunctions;
  2.  
  3. { function damagemod(damage,maxhp:integer):integer;
  4.   // This function will return a modified value of damage depending on a theoretical
  5.   // amount of maximum health the victim has. The actually dealt damage is
  6.   // proportionally decreased in case of maximum health above 150 and decreased in
  7.   // case of lower maximum health. Please note that maximum health is a theoretical
  8.   // value and actual damage a real value.
  9.  
  10.  function getids(ishuman:boolean):array of byte;
  11.   // This function will return an array consisting of IDs of either all human players
  12.   // or all bots.
  13.  
  14.   function getstr(input:string; part:byte):string;
  15.    // A short version of getpiece(), that always uses one space as the delimiter. Use the
  16.    // normal version of getpiece() if you divide parts with a different delimiter.
  17.    
  18.   function getint(input:string):integer;
  19.    // Short version of intToStr()
  20.  
  21.   function getbyte(input:string):byte;
  22.    // Will return a byte instead of an integer.
  23.    
  24. }
  25.  
  26. interface
  27. // ******
  28.  function isregistered(id:byte)          :boolean;
  29.  function isflagger(id:byte)             :boolean;
  30.  function isground(id:byte)              :boolean;
  31.  function isactive(id:byte)              :boolean;
  32.  function isalive(id:byte)               :boolean;
  33.  function ishuman(id:byte)               :boolean;
  34.  
  35.  function getdeaths(id:byte)             :integer;
  36.  function getkills(id:byte)              :integer;
  37.  function gethp(id:byte)                 :integer;
  38.  function getping(id:byte)               :integer;
  39.  function getvest(id:byte)               :integer;
  40.  function gettime(id:byte)               :integer;
  41.  function getping(id:byte)               :integer;
  42.  function getport(id:byte)               :integer;
  43.  function getjets(id:byte)               :integer;
  44.  
  45.  function getsecondary(id:byte)          :byte;
  46.  function getgrenades(id:byte)           :byte;
  47.  function getprimary(id:byte)            :byte;
  48.  function getid(name:string)             :byte;
  49.  function getteam(id:byte)               :byte;
  50.  function getammo1(id:byte)              :byte;
  51.  function getammo2(id:byte)              :byte;
  52.  
  53.  function getvelx(id:byte)               :single;
  54.  function getvely(id:byte)               :single;
  55.  function getx(id:byte)                  :single;
  56.  function gety(id:byte)                  :single;
  57.  
  58.  function getdirection(id:byte)          :string;
  59.  function gettagid(id:byte)              :string;
  60.  function gethwid(id:byte)               :string;
  61.  function getname(id:byte)               :string;
  62.  function getip(id:byte)                 :string;
  63.  
  64.  function getstr(input:string; part:byte):string;
  65.  function getbyte(input:string)          :byte;
  66.  function getint(input:string)           :integer;
  67.  
  68.  function damagemod(damage,maxhp:integer):integer;
  69.  function getids(human:boolean)          :array of byte;    
  70.  
  71. implementation
  72. // ******
  73.  
  74.  function isalive(id:byte):boolean;
  75.  begin
  76.   try result := getplayerstat(id,'alive');
  77.   except
  78.    writeln('ERROR: playerFunctions -> isalive() : ID not found');
  79.   end;
  80.  end;
  81.  
  82.  function isground(id:byte):boolean;
  83.  begin
  84.   try result := getplayerstat(id,'ground');
  85.   except
  86.    writeln('ERROR: playerFunctions -> isground() : ID not found');
  87.   end;
  88.  end;
  89.  
  90.  function ishuman(id:byte):boolean;
  91.  begin
  92.   try result := getplayerstat(id,'human');
  93.   except
  94.    writeln('ERROR: playerFunctions -> ishuman() : ID not found');
  95.   end;
  96.  end;
  97.  
  98.  function isactive(id:byte):boolean;
  99.  begin
  100.    result := getplayerstat(id,'active');
  101.  end;
  102.  
  103.  function damagemod(damage,maxhp:integer):integer;
  104.  begin
  105.   try result := damage * 150 / maxhp;
  106.   except
  107.    writeln('ERROR: playerFunctions -> damagemod() : Division by zero');
  108.   end;
  109.  end;
  110.  
  111.  function gethp(id:byte):integer;
  112.  begin
  113.   try result := getplayerstat(id,'health');
  114.   except
  115.    writeln('ERROR: playerFunctions -> gethp() : ID not found');
  116.   end;
  117.  end;
  118.  
  119.  function getteam(id:byte):byte;
  120.  begin
  121.   try result := getplayerstat(id,'team');
  122.   except
  123.    writeln('ERROR: playerFunctions -> getteam() : ID not found');
  124.   end;
  125.  end;
  126.  
  127.  function getkills(id:byte):integer;
  128.  begin
  129.   try result := getplayerstat(id,'kills');
  130.   except
  131.    writeln('ERROR: playerFunctions -> getkills() : ID not found');
  132.   end;
  133.  end;
  134.  
  135.  function getdeaths(id:byte):integer;
  136.  begin
  137.   try result := getplayerstat(id,'deaths');
  138.   except
  139.    writeln('ERROR: playerFunctions -> getdeaths() : ID not found');
  140.   end;
  141.  end;
  142.  
  143.  function getx(id:byte):single;
  144.  begin
  145.   try result := getplayerstat(id,'x');
  146.   except
  147.    writeln('ERROR: playerFunctions -> getx() : ID not found');
  148.   end;
  149.  end;
  150.  
  151.  function gety(id:byte):single;
  152.  begin
  153.   try result := getplayerstat(id,'y');
  154.   except
  155.    writeln('ERROR: playerFunctions -> gety() : ID not found');
  156.   end;
  157.  end;
  158.  
  159.  function gethwid(id:byte):string;
  160.  begin
  161.   try result := getplayerstat(id,'hwid');
  162.   except
  163.    writeln('ERROR: playerFunctions -> gethwid() : ID not found');
  164.   end;
  165.  end;
  166.  
  167.  function getname(id:byte):string;
  168.  begin
  169.   try result := getplayerstat(id,'name');
  170.   except
  171.    writeln('ERROR: playerFunctions -> getname() : ID not found');
  172.   end;
  173.  end;
  174.  
  175.  function getid(name:string):byte;
  176.  var i:byte;
  177.  begin
  178.   result := 0;
  179.   for i := 1 to 32 do
  180.    if getplayerstat(i,'active') = true then
  181.     if getplayerstat(i,'name') = name then begin
  182.      result := i;
  183.      break;
  184.     end;
  185.   if result = 0 then writeln('ERROR: playerFunctions -> getid() : Name not found in game');
  186.  end;
  187.  
  188.  function getstr(text:string; part:byte):string;
  189.  begin
  190.   result := getpiece(text,' ',part);
  191.   if result = '' then writeln('ERROR: playerFunctions -> getstr() : Part = NIL');
  192.  end;
  193.  
  194.  function getint(input:string):integer;
  195.  begin
  196.   try result := strtoint(input);
  197.   except
  198.    result := 0;
  199.    writeln('ERROR: playerFunctions -> getint() : Invalid string input');
  200.   end;
  201.  end;
  202.  
  203.  function getbyte(input:string):byte;
  204.  begin
  205.   try result := strtoint(input);
  206.   except
  207.    result := 0;
  208.    writeln('ERROR: playerFunctions -> getint() : Invalid string input');
  209.   end;
  210.  end;
  211.  
  212.  function getprimary(id:byte):byte;
  213.  begin
  214.   try result := getplayerstat(id,'primary');
  215.   except
  216.    result := 77;
  217.    writeln('ERROR: playerFunctions -> getprimary() : ID not found');
  218.   end;
  219.  end;
  220.  
  221.  function getsecondary(id:byte):byte;
  222.  begin
  223.   try result := getplayerstat(id,'secondary');
  224.   except
  225.    result := 77;
  226.    writeln('ERROR: playerFunctions -> getsecondary() : ID not found');
  227.   end;
  228.  end;
  229.  
  230.  function getammo1(id:byte):byte;
  231.  begin
  232.   try result := getplayerstat(id,'ammo');
  233.   except
  234.    result := 0;
  235.    writeln('ERROR: playerFunctions -> getammo1() : ID not found');
  236.   end;
  237.  end;
  238.  
  239.  function getammo2(id:byte):byte;
  240.  begin
  241.   try result := getplayerstat(id,'secammo');
  242.   except
  243.    result := 0;
  244.    writeln('ERROR: playerFunctions -> getammo2() : ID not found');
  245.   end;
  246.  end;
  247.  
  248.  function getping(id:byte):integer;
  249.  begin
  250.   try result := getplayerstat(id,'ping');
  251.   except
  252.    result := 0;
  253.    writeln('ERROR: playerFunctions -> getping() : ID not found');
  254.   end;
  255.  end;
  256.  
  257.  function getport(id:byte):integer;
  258.  begin
  259.   try result := getplayerstat(id,'port');
  260.   except
  261.    result := 0;
  262.    writeln('ERROR: playerFunctions -> getport() : ID not found');
  263.   end;
  264.  end;
  265.  
  266.  function getjets(id:byte):integer;
  267.  begin
  268.   try result := getplayerstat(id,'jets');
  269.   except
  270.    result := 0;
  271.    writeln('ERROR: playerFunctions -> getjets() : ID not found');
  272.   end;
  273.  end;
  274.  
  275.  function getgrenades(id:byte):byte;
  276.  begin
  277.   try result := getplayerstat(id,'grenades');
  278.   except
  279.    result := 0;
  280.    writeln('ERROR: playerFunctions -> getgrenades() : ID not found');
  281.   end;
  282.  end;
  283.  
  284.  function isflagger(id:byte):boolean;
  285.  begin
  286.   try result := getplayerstat(id,'flagger');
  287.   except
  288.    result := false;
  289.    writeln('ERROR: playerFunctions -> isflagger() : ID not found');
  290.   end;
  291.  end;
  292.  
  293.  function gettime(id:byte):integer;
  294.  begin
  295.   try result := getplayerstat(id,'time');
  296.   except
  297.    result := 0;
  298.    writeln('ERROR: playerFunctions -> gettime() : ID not found');
  299.   end;
  300.  end;
  301.  
  302.  function getvelx(id:byte):single;
  303.  begin
  304.   try result := getplayerstat(id,'velx');
  305.   except
  306.    result := 0;
  307.    writeln('ERROR: playerFunctions -> getvelx() : ID not found');
  308.   end;
  309.  end;
  310.  
  311.  function getvely(id:byte):single;
  312.  begin
  313.   try result := getplayerstat(id,'vely');
  314.   except
  315.    result := 0;
  316.    writeln('ERROR: playerFunctions -> getvely() : ID not found');
  317.   end;
  318.  end;
  319.  
  320.  function getvest(id:byte):integer;
  321.  begin
  322.   try result := getplayerstat(id,'vest');
  323.   except
  324.    result := 0;
  325.    writeln('ERROR: playerFunctions -> getvest() : ID not found');
  326.   end;
  327.  end;
  328.  
  329.  function getdirection(id:byte):string;
  330.  begin
  331.   try result := getplayerstat(id,'direction');
  332.   except
  333.    result := '';
  334.    writeln('ERROR: playerFunctions -> getdirection() : ID not found');
  335.   end;
  336.  end;
  337.  
  338.  function isregistered(id:byte):boolean;
  339.  begin
  340.   try result := getplayerstat(id,'registered');
  341.   except
  342.    result := false;
  343.    writeln('ERROR: playerFunctions -> isregistered() : ID not found');
  344.   end;
  345.  end;
  346.  
  347.  function gettagid(id:byte):string;
  348.  begin
  349.   try result := getplayerstat(id,'tagid');
  350.   except
  351.    result := '';
  352.    writeln('ERROR: playerFunctions -> gettagid() : ID not found');
  353.   end;
  354.  end;
  355.  
  356.  function getids(ishuman:boolean):array of byte;
  357.  var i:byte; len:integer;
  358.  begin
  359.   for i := 1 to 32 do
  360.    if (getplayerstat(i,'active') = true) and (getplayerstat(i,'human') = ishuman) then begin
  361.     inc(len,1);
  362.     setarraylength(result,len);
  363.     result[len-1] := i;
  364.    end;
  365.   if len = 0 then writeln('ERROR: playerFunctions -> getids() : Server does not hold any '+iif(ishuman,'players','bots'));
  366.  end;
  367.  
  368. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement