SHARE
TWEET

server-side gamemode file

a guest Jun 2nd, 2010 137 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ClientContainer
  2. {
  3.     int identifier;
  4.     int kills;
  5.     int deads;
  6.     int teamkills;
  7.     int suicides;
  8.  
  9.     bool dead;
  10.     uint64 timeDied;
  11. }
  12.  
  13. enum MessageIDs
  14. {
  15.     MESSAGE_ID_GAME_START,
  16.     MESSAGE_ID_GAME_END,
  17.     MESSAGE_ID_PLAYER_DIED
  18. }
  19.  
  20. ClientContainer[] clients(32);
  21.  
  22. void Init()
  23. {
  24.     for(int i = 0;i<32;i++)
  25.     {
  26.         clients[i].identifier = -1;
  27.     }
  28. }
  29.  
  30. void Update()
  31. {
  32.         for(int i = 0;i<32;i++)
  33.         {
  34.                 if(clients[i].identifier != -1)
  35.                 {
  36.                         if(clients[i].dead)
  37.                         {
  38.                                 Client@ client = GetClient(clients[i].identifier);
  39.                                 if(clients[i].timeDied+30000 >= GetTime())
  40.                                 {
  41.                                         clients[i].dead = false;
  42.                                         SpawnPlayer(client);
  43.                                 }
  44.                         }
  45.                 }
  46.         }
  47. }
  48.  
  49. void Cleanup()
  50. {
  51. }
  52.  
  53. void PlayerJoined(const Client@ client)
  54. {
  55.     int freeSpace = -1;
  56.     for(int i = 0;i<32;i++)
  57.     {
  58.         if(clients[i].identifier == -1)
  59.         {
  60.             freeSpace = i;
  61.             break;
  62.         }
  63.     }
  64.  
  65.     clients[freeSpace].identifier = client.identifier;
  66.     clients[freeSpace].kills = 0;
  67.     clients[freeSpace].deads = 0;
  68.     clients[freeSpace].teamkills = 0;
  69.     clients[freeSpace].dead = false;
  70.  
  71.     BitStream stream;
  72.     stream.WriteID(MESSAGE_ID_GAME_START);
  73.  
  74.     network.Send(@stream, client.address);
  75. }
  76.  
  77. void PlayerLeft(const Client@ client)
  78. {
  79.     int id = -1;
  80.     for(int i = 0;i<32;i++)
  81.     {
  82.         if(clients[i].identifier == client.identifier)
  83.         {
  84.             id = i;
  85.             break;
  86.         }
  87.     }
  88.  
  89.     clients[id].identifier = -1;
  90. }
  91.  
  92. ClientContainer@ GetClientContainer(const Client@ client)
  93. {
  94.     for(int i = 0;i<32;i++)
  95.     {
  96.         if(clients[i].identifier == client.identifier)
  97.             return @clients[i];
  98.     }
  99.  
  100.     return @ClientContainer();
  101. }
  102.  
  103. Client@ GetClient(int identifier)
  104. {
  105.         for(int i = 0;i<systemClients.size();i++)
  106.         {
  107.                 if(systemClients[i].identifier == identifier)
  108.                         return systemClients[i];
  109.         }
  110.  
  111.         return @Client();
  112. }
  113.  
  114. void PlayerDied(const Client@ client, const Client@ killer)
  115. {
  116.     ClientContainer@ clientContainer = GetClientContainer(client);
  117.     ClientContainer@ killerContainer = GetClientContainer(killer);
  118.     if(client.identifier == killer.identifier)
  119.     {
  120.         print("Player '");
  121.         print(client.username);
  122.         print("' commited suicide.\n");
  123.  
  124.         clientContainer.suicides++;
  125.         clientContainer.deads++;
  126.     }else{
  127.         print("Player '");
  128.         print(killer.username);
  129.         if(client.team == killer.team)
  130.             print("' teamkilled '");
  131.         else
  132.             print("' killed '");
  133.         print(client.username);
  134.         print("'.\n");
  135.  
  136.         if(client.team == killer.team)
  137.             killerContainer.teamkills++;
  138.  
  139.         clientContainer.deads++;
  140.         killerContainer.kills++;
  141.     }
  142.  
  143.     clientContainer.dead = true;
  144.     clientContainer.timeDied = GetTime();
  145.  
  146.     BitStream stream;
  147.     stream.WriteID(MESSAGE_ID_PLAYER_DIED);
  148.     stream.WriteInt(client.identifier);
  149.     stream.WriteInt(killer.identifier);
  150.  
  151.     network.Send(@stream, UnassignedSystemAddress);
  152. }
RAW Paste Data
Top