Headache

Vida, chaleco y dinero server-side

Jun 19th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.71 KB | None | 0 0
  1. #include <a_samp>
  2. #include <foreach>
  3.  
  4. #undef MAX_PLAYERS
  5. #define MAX_PLAYERS (100)
  6.  
  7. // Variables.
  8. new Dinero[MAX_PLAYERS];
  9. new Float:Vida[MAX_PLAYERS];
  10. new Float:Chaleco[MAX_PLAYERS];
  11. new Float:VidaCheat[MAX_PLAYERS];
  12. new Float:ChalecoCheat[MAX_PLAYERS];
  13.  
  14. public OnFilterScriptInit()
  15. {
  16.     EnableVehicleFriendlyFire(); // Permitimos hacerle daño a vehículos.
  17.     SetTimer("Anticheat", 1000, 1); // Ejecutamos la función cada 1 segundo.
  18.     return 1;
  19. }
  20.  
  21. public OnPlayerConnect(playerid)
  22. {
  23.     SetPlayerTeam(playerid, 1); // Evitamos el daño por defecto de las armas.
  24.     ResetPlayerMoney(playerid); // Reiniciamos el dinero del jugador.
  25.     Vida[playerid] = 0.0; // Reiniciamos la variable.
  26.     Chaleco[playerid] = 0.0; // Reiniciamos la variable.
  27.     VidaCheat[playerid] = 0.0; // Reiniciamos la variable.
  28.     ChalecoCheat[playerid] = 0.0; // Reiniciamos la variable.
  29.     return 1;
  30. }
  31.  
  32. public OnPlayerSpawn(playerid)
  33. {
  34.     EstablecerVida(playerid, 100.0); // Damos 100 de vida al spawnar.
  35.     return 1;
  36. }
  37.  
  38. // Configuramos los daños, es útil por si alguien quiere usar algún sistema de daños personalizado.
  39. public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
  40. {
  41.     new Float:vida = Vida[playerid];
  42.     new Float:chaleco = Chaleco[playerid];
  43.     if(issuerid != INVALID_PLAYER_ID) // Si el daño lo produce otro jugador.
  44.     {
  45.         GetPlayerHealth(playerid, vida);
  46.         GetPlayerArmour(playerid, chaleco);
  47.         if(amount) // Si tenemos algo de chaleco, vamos a perder chaleco antes que vida.
  48.         {
  49.             if(chaleco > amount) EstablecerChaleco(playerid, chaleco-amount);
  50.             else
  51.             {
  52.                 EstablecerChaleco(playerid, 0.0);
  53.                 chaleco = amount-chaleco;
  54.                 if(chaleco >= vida) EstablecerVida(playerid, 0.0);
  55.                 else EstablecerVida(playerid, vida-chaleco);
  56.             }
  57.         }
  58.         else
  59.         {
  60.             if(vida > amount) EstablecerVida(playerid, vida-amount);
  61.             else EstablecerVida(playerid, 0.0);
  62.         }
  63.     }
  64.     else // Si el daño se lo produce uno mismo, no pierde armadura, sólo vida.
  65.     {
  66.         GetPlayerHealth(playerid, vida);
  67.         if(vida > amount) EstablecerVida(playerid, vida-amount);
  68.         else EstablecerVida(playerid, 0.0);
  69.     }
  70.     return 1;
  71. }
  72.  
  73. // Timer anticheat.
  74. forward Anticheat();
  75. public Anticheat()
  76. {
  77.     foreach(new i : Player)
  78.     {
  79.         GetPlayerHealth(i, VidaCheat[i]);
  80.         GetPlayerArmour(i, ChalecoCheat[i]);
  81.         if(ObtenerDinero(i) != GetPlayerMoney(i))
  82.         {
  83.             ResetPlayerMoney(i);
  84.             ActualizarDinero(i, ObtenerDinero(i));
  85.         }
  86.         // if(VidaCheat[i] > 0.0 && Vida[playerid] < VidaCheat[i])
  87.         if(VidaCheat[i] != Vida[i])
  88.         {
  89.             VidaCheat[i] = Vida[i];
  90.             EstablecerVida(i, VidaCheat[i]);
  91.         }
  92.         // if(ChalecoCheat[i] > 0.0 && Chaleco[playerid] < ChalecoCheat[i])
  93.         if(ChalecoCheat[i] != Chaleco[i])
  94.         {
  95.             ChalecoCheat[i] = Chaleco[i];
  96.             EstablecerChaleco(i, ChalecoCheat[i]);
  97.         }
  98.     }
  99. }
  100.  
  101. // Función para sumar un monto específico de dinero a un jugador.
  102. stock DarDinero(playerid, dinero)
  103. {
  104.     new string[12];
  105.     Dinero[playerid] += dinero;
  106.     ResetPlayerMoney(playerid);
  107.     GivePlayerMoney(playerid, Dinero[playerid]);
  108.     format(string, sizeof(string), "~g~ +%d$", dinero);
  109.     GameTextForPlayer(playerid, string, 5000, 1);
  110.     PlayerPlaySound(playerid, 1083, 0.0, 0.0, 0.0);
  111.     return Dinero[playerid];
  112. }
  113.  
  114. // Función para restar un monto específico de dinero a un jugador.
  115. stock QuitarDinero(playerid, dinero)
  116. {
  117.     new string[12];
  118.     Dinero[playerid]-= dinero;
  119.     ResetPlayerMoney(playerid);
  120.     GivePlayerMoney(playerid, -Dinero[playerid]);
  121.     format(string, sizeof(string), "~r~ -%d$", dinero);
  122.     GameTextForPlayer(playerid, string, 5000, 1);
  123.     PlayerPlaySound(playerid, 1084, 0.0, 0.0, 0.0);
  124.     return Dinero[playerid];
  125. }
  126.  
  127. // Función para actualizar el dinero de un jugador al valor correspondiente.
  128. stock ActualizarDinero(playerid, dinero)
  129. {
  130.     Dinero[playerid] = dinero;
  131.     ResetPlayerMoney(playerid);
  132.     GivePlayerMoney(playerid, Dinero[playerid]);
  133.     return Dinero[playerid];
  134. }
  135.  
  136. // Función para reiniciar el dinero de un jugador a 0.
  137. stock ReiniciarDinero(playerid)
  138. {
  139.     Dinero[playerid] = 0;
  140.     ResetPlayerMoney(playerid);
  141.     GivePlayerMoney(playerid, Dinero[playerid]);
  142.     return Dinero[playerid];
  143. }
  144.  
  145. // Función para obtener la cifra exacta del dinero que tiene un jugador.
  146. stock ObtenerDinero(playerid) return Dinero[playerid];
  147.  
  148. // Función para establecer la vida de un jugador a la cantidad indicada.
  149. stock EstablecerVida(playerid, Float:vida)
  150. {
  151.     Vida[playerid] = vida;
  152.     return SetPlayerHealth(playerid, vida);
  153. }
  154.  
  155. // Función para establecer el chaleco de un jugador a la cantidad indicada.
  156. stock EstablecerChaleco(playerid, Float:chaleco)
  157. {
  158.     Chaleco[playerid] = chaleco;
  159.     return SetPlayerArmour(playerid, chaleco);
  160. }
Advertisement
Add Comment
Please, Sign In to add comment