Advertisement
ShutDlc

Bleeding

Jul 29th, 2015
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.19 KB | None | 0 0
  1. //========================================================================================================
  2. //Class
  3. //========================================================================================================
  4.  
  5. public class PlayerData {
  6.     public IPlayer player = null;
  7.     public bool IsBleeding = false;
  8.     public float LastHealth = 100f;
  9.     public float BleedCounter = 0f;
  10.  
  11.     public PlayerData (IPlayer ply){
  12.         this.player = ply;
  13.     }
  14.  
  15. }
  16.  
  17. //========================================================================================================
  18. //Vars
  19. //========================================================================================================
  20.  
  21. List<PlayerData> DataList = new List<PlayerData>();
  22. Random rnd = new Random();
  23.  
  24. //========================================================================================================
  25. //Const
  26. //========================================================================================================
  27.  
  28. const float MINDAMAGE = 2f; //Damage you need to take to have a chance to bleed
  29. const float MAXDAMAGE = 50f; //Damage that grant 100% of bleeding
  30. const float DAMAGEBLEEDING = 2f; // Damage per bleeding per tick
  31. const float BLEEDTIME = 6f; //Time needed to heal (*500ms)
  32.  
  33. //========================================================================================================
  34. //methods
  35. //========================================================================================================
  36.  
  37. public void OnStartup(){
  38.     foreach (IPlayer ply in Game.GetPlayers()){
  39.         DataList.Add(new PlayerData(ply));
  40.     }
  41.  
  42.     Game.ShowPopupMessage("Bleeding mode activated\nCrouch to heal your wounds", new Color(0,100,150));
  43.    
  44.     IObjectTimerTrigger timerTriger = (IObjectTimerTrigger)Game.CreateObject("TimerTrigger");
  45.     timerTriger.SetIntervalTime(500);
  46.     timerTriger.SetRepeatCount(0);
  47.     timerTriger.SetScriptMethod("Script_BleedCheck");
  48.     timerTriger.Trigger();
  49. }
  50.  
  51. public void Script_BleedCheck(TriggerArgs args){
  52.     foreach (PlayerData data in DataList){
  53.         IPlayer ply = data.player;
  54.         float health = ply.GetHealth();
  55.  
  56.         if (health < data.LastHealth - MINDAMAGE && !ply.IsBurning){
  57.             float dmg = data.LastHealth - health - MINDAMAGE;
  58.             if (!data.IsBleeding){
  59.                 data.IsBleeding = true;
  60.                 Game.PlayEffect("CFTXT",ply.GetWorldPosition(),"Bleeding !");
  61.                 data.BleedCounter = BLEEDTIME;
  62.             }
  63.         }
  64.         else if (data.LastHealth < health){
  65.             if (data.IsBleeding){
  66.                 data.IsBleeding = false;
  67.                 Game.PlayEffect("CFTXT",ply.GetWorldPosition(),"Healed !");
  68.             }
  69.         }
  70.  
  71.         if (data.IsBleeding && !ply.IsDead){
  72.            
  73.             if (ply.IsCrouching){
  74.                 data.BleedCounter -= 1f;
  75.                 if (data.BleedCounter < 0f){
  76.                     data.IsBleeding = false;
  77.                     Game.PlayEffect("CFTXT",ply.GetWorldPosition(),"Healed !");
  78.                 }
  79.             }
  80.  
  81.             if (ply.IsBurning){
  82.                     data.IsBleeding = false;
  83.                     Game.PlayEffect("CFTXT",ply.GetWorldPosition(),"Cauterized !");
  84.             }
  85.  
  86.             if (rnd.Next(5) == 0)
  87.                 for (int i = 5; i>0; i--)
  88.                     Game.PlayEffect("BLD",ply.GetWorldPosition()+ new Vector2(rnd.Next(-5,6),rnd.Next(-5,6)));
  89.  
  90.             ply.SetHealth(health - DAMAGEBLEEDING);
  91.             if (health < DAMAGEBLEEDING) ply.Kill();
  92.         }
  93.  
  94.         data.LastHealth = ply.GetHealth();
  95.     }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement