Advertisement
Guest User

Flash Bang

a guest
Jan 28th, 2018
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 27.02 KB | None | 0 0
  1. unit CustomGrenades;
  2. //Script Writed By Dominik. Version 2018.01.28.004; 265.196:535
  3.  
  4. interface //Add in next:
  5. //Using PlaySound
  6. implementation
  7. const
  8.     //Optimize
  9.     MaxPlayer = 16;                 //[2-32] Max players what can be on your server.
  10.     AllowKeyPress = True;           //[true|false] Allow you to change the grenade using the keys.
  11.     //Colors
  12.     ColorW = $adc600;               //[Longint] Color displayed text on chat using the command /help (WriteConsole).
  13.     FlashColor = $F1F1F1;           //[Longint] Color flashed. DONT EDIT. Edit only for funny :)
  14.     HudColor = $D9D5D1;             //[Longint] Color hud. Text on the screen.
  15.     NadeInfoColor = $CC0000;        //[Longint] Color nade inscription above the grenade.
  16.     FlashInfoColor = $CDCDCD;       //[Longint] Color flash inscription above the grenade.
  17.     //Design
  18.     LayerFlash = 36;                //[Number] For other programmers, or if you dont see the texts, change it. (BigText)
  19.     Method2FlashLayer = 40;         //[Number] For other programmers, or if you dont see the texts, change it. (WorldText)
  20.     LayerHud = 37;                  //[Number] For other programmers, or if you dont see the texts, change it. (BigText)
  21.     FirstJoinLayer = 38;            //[Number] For other programmers, or if you dont see the texts, change it  (BigText)
  22.     NadeInfoLayerStart = 41;        //[Number] For other programmers, or if you dont see the texts, change it. (WorldText) Must be > Method2FlashLayer num.
  23.     NadeInfoTime = 58;              //[Number] <60 be transparency effect, >70 be the inscription on the map becomes longer as the grenade explodes. DONT EDIT.
  24.     HudSize = 0.050;                //[Number] Hud size on screen.
  25.     HudPosX = 12;                   //[Number] Hud position X on screen.
  26.     HudPosY = 405;                  //[Number] Hud position Y on screen.
  27.     NadeInfoSize = 0.038;           //[Number] Size of inscription on nade.
  28.     NadeInfoCorrectionX = 12.75;    //[Number] Position correction X of inscription on nade.
  29.     NadeInfoCorrectionY = 6.7;      //[Number] Position correction Y of inscription on nade.
  30.     FirstJoinText = true;           //[true|false] true add text to use command /flashhelp if player first join server.
  31.     FlashAll = true;                //[true|false] true - all, false - enemy
  32.     SelfFlash = true;               //[true|false] true - player can blind himself, false - player can`t blind himself. This setting works if FlashAll is false.
  33.     FlashSee = 2;                   //[1-3] Inscription above your grenade see: 1 - All players, 2 - You and your team, 3 - Only you.
  34.     //Flash config
  35.     MaxDistance = 250;              //[Number] The maximum range on which players will be blinded
  36.     MinimalFlashTime = 80;          //[Number] The minimum time of blinding caused by flash. 60 ~ 1s
  37.     MaxFlashTime = 240;             //[Number] The maximum time of blinding caused by flash. 60 ~ 1s
  38.     MinimalDistToGainDamage = 85;   //[Number] The minimum distance at which the damage can be inflicted by flash grenade. DONT EDIT.
  39.     MaxFlashDamage = 28;            //[Number] Maximum damage that a player can get from a flash grenade.
  40.     FlashMethod = 2;                //[1-2] 1 - Using BigText, old method, can be partial screen blinding effect (at very very high resolutions). 2 - Using WorldText work for all resolution. There will be no partial screen blinding effect.
  41.     UseRayCastForNadeDisplay = true;//[true|false] Works only if realistic mode active. True - You will not see the inscription if the grenade will not be in sight. False - off this effect, all time see inscription on nade.
  42.     AntyNadeMove = true;
  43.     VelListMax = 3;                 //[Number] DONT EDIT; If AntyNadeMove true and dont work try set to 6 and set FrezTime to 5;    VelListMax must be FrezTime+1  - Best option
  44.     FrezTime = 2;                   //[Number] DONT EDIT; If AntyNadeMove true and dont work try set to 5 and set VelListMax to 6;  FrezTime must be VelListMax-1  - Best option
  45.     //Max grenade count
  46.     MaxNormalCount = 2;             //[Number] Specifies the maximum number of grenades, 0 to off.
  47.     MaxFlashCount = 1;              //[Number] Specifies the maximum number of flash, 0 to off.
  48.     //Granadekit config
  49.     DisableGranadeKit = false;      //[true|false] True - Disable granadekit spawn, False - Enables granadekit spawn.
  50.     GranadeKitNadeGive = 2;         //[Positive number] Specifies the maximum amount of grenades to be granted after picking up granadekit.
  51.     GranadeKitFlashGive = 1;        //[Positive number] Specifies the maximum amount of flash to be granted after picking up granadite
  52.     DistanceToGetNadeKit = 10.0;    //[Positive single number] The distance in which the player must be to make granadekit work. DONT EDIT.
  53.     RayCastCorection = 1;           //Dont Edit
  54.  
  55. type tNade = record
  56.     NadeCount: byte;
  57.     FlashCount: byte;
  58.     LastPosX,LastPosY:single;
  59.     FrezleTime:integer;
  60.     Style: byte;
  61.     FlashList, NadeList, LastVelX, LastVelY: TStringList;
  62. end;
  63.  
  64. var
  65.     Nade: array[1..MaxPlayer] of tNade;
  66.  
  67. function Commands(Player: TActivePlayer; Text: string): Boolean;
  68. begin
  69.     result:=false;
  70.     text:=lowercase(text);
  71.     if (Text='/set') or (text='/change') then begin
  72.         if (Nade[Player.ID].Style<>3) then begin
  73.             if (Nade[Player.ID].Style=0) then begin
  74.                 if (Nade[Player.ID].FlashCount>0) then Nade[Player.ID].Style := 1;
  75.             end else if (Nade[Player.ID].NadeCount>0) then Nade[Player.ID].Style := 0;
  76.         end;
  77.         exit;
  78.     end;
  79.     if (Text='/smoke') or (Text='/nade') or (Text='/cc1') then begin
  80.         if (Nade[Player.ID].Style<>3) then begin
  81.             if (Nade[Player.ID].Style=1) then begin
  82.                 if (Nade[Player.ID].NadeCount>0) then Nade[Player.ID].Style := 0;
  83.             end;
  84.         end;
  85.         exit;
  86.     end;
  87.     if (Text='/tabac') or (Text='/flash') or (Text='/cc2') then begin
  88.         if (Nade[Player.ID].Style<>3) then begin
  89.             if (Nade[Player.ID].Style=0) then begin
  90.                 if (Nade[Player.ID].FlashCount>0) then Nade[Player.ID].Style := 1;
  91.             end;
  92.         end;
  93.         exit;
  94.     end;
  95.     if (Text='/help') or (Text='/flashhelp') then begin
  96.         Player.WriteConsole('Grenade type info (Script create by Dominik):',ColorW-200);
  97.         Player.WriteConsole('Minimal flash time: '+FormatFloat('0.00',MinimalFlashTime/60.0)+'s, Max flash time: '+FormatFloat('0.00',MaxFlashTime/60.0)+'s, Max flash range: '+FormatFloat('0.00',MaxDistance/10.0)+'m                                                                                 ',ColorW+700);
  98.         Player.WriteConsole('Max flash destruction range: '+FormatFloat('0.00',MinimalDistToGainDamage/10.0)+'m, Max flash damage: '+FormatFloat('0.00',MaxFlashDamage)+'dmg                                                                                 ',ColorW+700);
  99.         Player.WriteConsole('Max grenades: '+inttostr(MaxNormalCount)+', Max glash: '+inttostr(MaxFlashCount)+iif(DisableGranadeKit=false,', Grenadekit gives: '+inttostr(GranadeKitNadeGive)+' nades, '+inttostr(GranadeKitFlashGive)+' flash','')+'                                                                                 ',ColorW+700);
  100.         Player.WriteConsole('Flash will blind everyone - '+iif(FlashAll=true,'true','false')+', Self blinded - '+iif(SelfFlash=true,'possible','impossible')+', Flash dont move you: '+iif(AntyNadeMove=true,'true','false')+'                                                                                 ',ColorW+700);
  101.         if (Game.Realistic) and (UseRayCastForNadeDisplay=true) then begin
  102.             case FlashSee of
  103.                 1 : begin
  104.                         Player.WriteConsole('Everyone can see inscription above your grenade, but realistic mode is active.                                                                                 ',ColorW+700);
  105.                         Player.WriteConsole('If your granade isn`t visible for enemy, they will not see an inscription above your grenade                                                                                 ',ColorW+700);
  106.                     end;
  107.                 2 : Player.WriteConsole('Inscription on the grenade will see you and your team friends.                                                                                 ',ColorW+700);
  108.                 3 : Player.WriteConsole('Inscription on the grenade will see only you.                                                                                 ',ColorW+700);
  109.             end;
  110.         end else
  111.         begin
  112.             case FlashSee of
  113.                 1 : Player.WriteConsole('Everybody will see inscription above your grenade, also enemy.                                                                                 ',ColorW+700);
  114.                 2 : Player.WriteConsole('Inscription on the grenade will see you and your team friends.                                                                                 ',ColorW+700);
  115.                 3 : Player.WriteConsole('Inscription on the grenade will see only you.                                                                                 ',ColorW+700);
  116.             end;
  117.         end;
  118.         Player.WriteConsole('/set   /change      - Switch grenade type.                                                                                                   ',ColorW);
  119.         Player.WriteConsole('/nade  /cc1 /smoke  - Change grenade type to normal.                                                                                         ',ColorW);
  120.         Player.WriteConsole('/flash /cc2 /tabac  - Change the grenade to flash.                                                                                           ',ColorW);
  121.         Player.WriteConsole('Default taunt: Alt+1 is commands /smoke means change to normal grenade.                                                                                         ',ColorW);
  122.         Player.WriteConsole('Default taunt: Alt+2 is commands /tabac means change to flash grenade.                                                                                           ',ColorW);
  123.         if AllowKeyPress then Player.WriteConsole('Press key crouch + switch weapon - Change grenade type.                                                                       ',ColorW);
  124.     end;
  125. end;
  126.  
  127. procedure JoinGame(Player: TActivePlayer; Team: TTeam);
  128. begin
  129.     if (Player.Human) and (FirstJoinText=true) then begin
  130.         Player.WriteConsole('Write /flashhelp to see how use flash grenade!',ColorW+3500);
  131.         Player.BigText(FirstJoinLayer,'Write /flashhelp to see how use flash grenade!',155,HudColor,0.09,55,295);
  132.     end;
  133. end;
  134.  
  135. procedure JoinTeam(Player: TActivePlayer; Team: TTeam);
  136. begin
  137.     Nade[Player.ID].FlashList := File.CreateStringList();
  138.     Nade[Player.ID].NadeList := File.CreateStringList();
  139.     Nade[Player.ID].LastVelX := File.CreateStringList();
  140.     Nade[Player.ID].LastVelY := File.CreateStringList();
  141.     Nade[Player.ID].FrezleTime := 0;
  142.     if (Player.Human) then begin
  143.         if (FlashMethod=1) then Player.BigText(LayerFlash,'',0,FlashColor,0.1,0,0) else Player.WorldText(Method2FlashLayer,'+',0,FlashColor,0.1,Player.X,Player.Y);
  144.         if (Team.ID=5) then Player.BigText(LayerHud,'',0,HudColor,0.1,0,0);
  145.     end;
  146.     Nade[Player.ID].Style := 0;
  147.     Nade[Player.ID].NadeCount := MaxNormalCount;
  148.     Nade[Player.ID].FlashCount := MaxFlashCount;
  149. end;
  150.  
  151. procedure LeaveGame(Player: TActivePlayer; Kicked: Boolean);
  152. begin
  153.     if (FlashMethod=1) then Player.BigText(LayerFlash,'',0,FlashColor,0.1,0,0) else Player.WorldText(Method2FlashLayer,'+',0,FlashColor,0.1,Player.X,Player.Y);
  154. end;
  155.  
  156. procedure OnAfterRespawn(Player: TActivePlayer);
  157. begin
  158.     if (FlashMethod=1) then Player.BigText(LayerFlash,'',0,FlashColor,0.1,0,0) else Player.WorldText(Method2FlashLayer,'+',0,FlashColor,0.1,Player.X,Player.Y);
  159.     Nade[Player.ID].Style := 0;
  160.     Nade[Player.ID].NadeCount := MaxNormalCount;
  161.     Nade[Player.ID].FlashCount := MaxFlashCount;
  162.     Nade[Player.ID].LastVelX := File.CreateStringList();
  163.     Nade[Player.ID].LastVelY := File.CreateStringList();
  164.     Nade[Player.ID].FrezleTime := 0;
  165. end;
  166.  
  167. procedure ChangeAfter(Next: string);
  168. var i: byte;
  169. begin
  170.     if (disablegranadekit=true) or ((GranadeKitNadeGive=0) and (GranadeKitFlashGive=0)) then begin
  171.         for i := 1 to 254 do if (Map.Spawns[i].Style=8) then Map.Spawns[i].Active := false;
  172.         for i := 1 to 90 do if (Map.Objects[i].Style=17) then Map.Objects[i].Kill;
  173.     end;
  174.     for i := 1 to MaxPlayer do if (Players[i].Active) then begin
  175.         if (Players[i].Human) then begin
  176.             if (FlashMethod=1) then Players[i].BigText(LayerFlash,'',0,FlashColor,0.1,0,0) else Players[i].WorldText(Method2FlashLayer,'+',0,FlashColor,0.1,Players[i].X,Players[i].Y);
  177.         end;
  178.         Nade[i].Style := 0;
  179.         Nade[i].NadeCount := MaxNormalCount;
  180.         Nade[i].FlashCount := MaxFlashCount;
  181.     end;
  182. end;
  183.  
  184. function NadeDamage(Shooter, Victim: TActivePlayer; Damage: single; Bullet: byte): single;
  185. var dmg:single; b:byte; i:integer; X2, Y2, Dist, TimeFlash, MaxDist: single;
  186. begin
  187.     Result := Damage;
  188.     dmg := Damage;
  189.     if (MaxFlashDamage>0) then begin
  190.         try
  191.             if (Map.Bullets[Bullet].GetOwnerWeaponId=50) then begin
  192.                 for b := 1 to MaxPlayer do if (Players[b].Active) then begin
  193.                     for i := 0 to (Nade[b].FlashList.Count-1) do begin
  194.                         if (Nade[b].FlashList[i]=inttostr(Bullet)) then begin
  195.                             X2 := Victim.X-Map.Bullets[Bullet].X; Y2 := Victim.Y-Map.Bullets[Bullet].Y; Dist := X2*X2+Y2*Y2;
  196.                             MaxDist:=MinimalDistToGainDamage*MinimalDistToGainDamage; //Dominik
  197.                             if (Dist<=MaxDist) then begin
  198.                                 if not Map.RayCast(Map.Bullets[Bullet].X,Map.Bullets[Bullet].Y-RayCastCorection,Victim.X,Victim.Y-RayCastCorection,false, false, true, true, 2) then begin
  199.                                     TimeFlash:=((100-((Dist/MaxDist)*100))/100);
  200.                                     dmg:=TimeFlash*MaxFlashDamage;
  201.                                 end;
  202.                             end;
  203.                             Result := dmg;
  204.                             exit;
  205.                         end;
  206.                     end;
  207.                 end;
  208.             end;
  209.         except
  210.         end;
  211.     end;
  212. end;
  213.  
  214. function CheckThisSameNades(ID:byte; check:string): boolean;
  215. var i: integer;
  216. begin
  217.     Result := false;
  218.     for i := 0 to (Nade[ID].NadeList.Count-1) do begin
  219.         if (Nade[ID].NadeList[i]=check) then begin
  220.             Result := true;
  221.             exit;
  222.         end;
  223.     end;
  224.     for i := 0 to (Nade[ID].FlashList.Count-1) do begin
  225.         if (Nade[ID].FlashList[i]=check) then begin
  226.             Result := true;
  227.             exit;
  228.         end;
  229.     end;
  230. end;
  231.  
  232. procedure NadesCreate();
  233. var i: byte;
  234. begin
  235.     for i := 1 to 254 do if (Map.Bullets[i].Active) then begin
  236.         if (Map.Bullets[i].GetOwnerWeaponId=50) then begin
  237.             if (Nade[Map.Bullets[i].Owner].Style=0) then begin
  238.                 if (Nade[Map.Bullets[i].Owner].NadeCount>0) then begin
  239.                     if (CheckThisSameNades(Map.Bullets[i].Owner, inttostr(i)) = false) then begin
  240.                         Nade[Map.Bullets[i].Owner].NadeList.Append(inttostr(i));
  241.                         Nade[Map.Bullets[i].Owner].NadeCount:=(Nade[Map.Bullets[i].Owner].NadeCount-1);
  242.                         if (Nade[Map.Bullets[i].Owner].NadeCount<=0) then if (Nade[Map.Bullets[i].Owner].FlashCount>0) then Nade[Map.Bullets[i].Owner].Style := 1;
  243.                     end;
  244.                 end;
  245.             end else if (Nade[Map.Bullets[i].Owner].Style=1) then begin
  246.                 if (Nade[Map.Bullets[i].Owner].FlashCount>0) then begin
  247.                     if (CheckThisSameNades(Map.Bullets[i].Owner, inttostr(i))=false) then begin
  248.                         Nade[Map.Bullets[i].Owner].FlashList.Append(inttostr(i));
  249.                         Nade[Map.Bullets[i].Owner].FlashCount:=(Nade[Map.Bullets[i].Owner].FlashCount-1);
  250.                         if (Nade[Map.Bullets[i].Owner].FlashCount<=0) then if (Nade[Map.Bullets[i].Owner].NadeCount>0) then Nade[Map.Bullets[i].Owner].Style := 0;
  251.                     end;
  252.                 end;
  253.             end;
  254.         end;
  255.     end;
  256. end;
  257.  
  258. procedure FlashPlayers(Owner:byte; FlashX, FlashY:single; Team:byte);
  259. var i:byte; X2, Y2, Dist, TimeFlash, MaxDist: single; RealTimeFlash:integer;
  260. begin
  261.     if (FlashAll=true) then begin
  262.         for i := 1 to MaxPlayer do if (Players[i].Active) then begin
  263.             if (Players[i].Alive) and (Players[i].Team<5) then begin
  264.                 X2 := Players[i].X-FlashX; Y2 := Players[i].Y-FlashY; Dist := X2*X2+Y2*Y2;
  265.                 MaxDist:=MaxDistance*MaxDistance; //By
  266.                 if (Dist<=MaxDist) then begin
  267.                     Nade[i].FrezleTime := FrezTime;
  268.                     if not Map.RayCast(FlashX,FlashY-RayCastCorection,Players[i].X,Players[i].Y-RayCastCorection,false, false, true, true, 2) then begin
  269.                         TimeFlash:=((100-((Dist/MaxDist)*100))/100);
  270.                         RealTimeFlash:=Round(TimeFlash*MaxFLashTime);
  271.                         if (RealTimeFlash<MinimalFlashTime) then RealTimeFlash:=MinimalFlashTime;
  272.                         if (FlashMethod=1) then Players[i].BigText(LayerFlash,'+',RealTimeFlash,FlashColor,60,-5000,-6420) else Players[i].WorldText(Method2FlashLayer,'+',RealTimeFlash,FlashColor,1280,Players[i].X-82304,Players[i].Y-136832);//20,Players[i].X-1286,Players[i].Y-2138);
  273.                     end;
  274.                 end;
  275.             end;
  276.         end;
  277.     end else
  278.     begin
  279.         for i := 1 to MaxPlayer do if (Players[i].Active) then begin
  280.             if (Players[i].Alive) and (Players[i].Team<5) and (i<>owner) and (Players[i].Team<>Team) then begin
  281.                 X2 := Players[i].X-FlashX; Y2 := Players[i].Y-FlashY; Dist := X2*X2+Y2*Y2;
  282.                 MaxDist:=MaxDistance*MaxDistance;
  283.                 if (Dist<=MaxDist) then begin
  284.                     Nade[i].FrezleTime := FrezTime;
  285.                     if not Map.RayCast(FlashX,FlashY-RayCastCorection,Players[i].X,Players[i].Y-RayCastCorection,false, false, true, true, 2) then begin
  286.                         TimeFlash:=((100-((Dist/MaxDist)*100))/100);
  287.                         RealTimeFlash:=Round(TimeFlash*MaxFLashTime);
  288.                         if (RealTimeFlash<MinimalFlashTime) then RealTimeFlash:=MinimalFlashTime;
  289.                         if SelfFlash then begin
  290.                             if (FlashMethod=1) then Players[owner].BigText(LayerFlash,'+',RealTimeFlash,FlashColor,60,-5000,-6420) else Players[owner].WorldText(Method2FlashLayer,'+',RealTimeFlash,FlashColor,1280,Players[owner].X-82304,Players[owner].Y-136832);
  291.                         end;
  292.                         if (FlashMethod=1) then Players[i].BigText(LayerFlash,'+',RealTimeFlash,FlashColor,60,-5000,-6420) else Players[i].WorldText(Method2FlashLayer,'+',RealTimeFlash,FlashColor,1280,Players[i].X-82304,Players[i].Y-136832);
  293.                     end;
  294.                 end;
  295.             end;
  296.         end;
  297.     end;
  298. end;
  299.  
  300. procedure RemoveNades();
  301. var i,b: byte;
  302. begin
  303.     for i := 1 to MaxPlayer do begin
  304.         if (Nade[i].NadeList.Count>0) then begin
  305.             for b := 0 to Nade[i].NadeList.Count-1 do begin
  306.                 try
  307.                     if (Map.Bullets[strtoint(Nade[i].NadeList[b])].Active=false) then begin
  308.                         Nade[i].NadeList.Delete(b); b:=b;
  309.                         if Nade[i].NadeList.Count=0 then exit;
  310.                     end;
  311.                 except
  312.                 end;
  313.             end;
  314.         end;
  315.         if (Nade[i].FlashList.Count>0) then begin
  316.             for b := 0 to Nade[i].FlashList.Count-1 do begin
  317.                 try
  318.                     if (Map.Bullets[strtoint(Nade[i].FlashList[b])].Active=false) then begin
  319.                         FlashPlayers(i,Map.Bullets[strtoint(Nade[i].FlashList[b])].X,Map.Bullets[strtoint(Nade[i].FlashList[b])].Y, Players[i].Team);
  320.                         Nade[i].FlashList.Delete(b); b:=b;
  321.                         if Nade[i].FlashList.Count=0 then exit;
  322.                     end;
  323.                 except
  324.                 end;
  325.             end;
  326.         end;
  327.     end;
  328. end;
  329.  
  330. procedure NadeControl();
  331. var i:byte;
  332. begin
  333.     for i := 1 to MaxPlayer do if (Players[i].Active) then begin
  334.         if (Players[i].Team < 5) then begin
  335.             if (Players[i].Grenades < 1) then begin
  336.                 if (Nade[i].NadeCount>0) or (Nade[i].FlashCount>0) then Players[i].GiveBonus(4);
  337.             end;
  338.             Players[i].BigText(LayerHud,'Type: '+iif(Nade[i].Style=0,'Grenades','Flash')+chr(13)+chr(10)+'Nade: '+inttostr(Nade[i].NadeCount)+Chr(13)+Chr(10)+'Flash: '+inttostr(Nade[i].FlashCount),75,HudColor,HudSize,HudPosX,HudPosY);
  339.         end;
  340.     end;
  341. end;
  342.  
  343. procedure DisplayNadeInfo();
  344. var i,b,c: byte;
  345. begin
  346.     for i := 1 to 254 do if (Map.Bullets[i].Active) then begin
  347.         if (Map.Bullets[i].GetOwnerWeaponId=50) then begin
  348.             case FlashSee of
  349.                 1:  begin
  350.                         if (Game.Realistic) and (UseRayCastForNadeDisplay=true) then begin
  351.                             for b := 1 to MaxPlayer do if (Players[b].Active) then begin
  352.                                 if (Players[Map.Bullets[i].Owner].Team=Players[b].Team) then begin
  353.                                     if (Nade[b].NadeList.IndexOf(inttostr(i))>-1) then begin
  354.                                         for c := 1 to MaxPlayer do if (Players[c].Active) then begin
  355.                                             if (Players[b].Team = Players[c].Team) then Players[c].WorldText(NadeInfoLayerStart+i,'Nade!',NadeInfoTime,NadeInfoColor,NadeInfoSize,Map.Bullets[i].X-NadeInfoCorrectionX,Map.Bullets[i].Y-NadeInfoCorrectionY) else if not Map.RayCast(Map.Bullets[i].X,Map.Bullets[i].Y-RayCastCorection,Players[c].X,Players[c].Y-RayCastCorection,true, false, false, false, 2) then Players[c].WorldText(NadeInfoLayerStart+i,'Nade!',NadeInfoTime,NadeInfoColor,NadeInfoSize,Map.Bullets[i].X-NadeInfoCorrectionX,Map.Bullets[i].Y-NadeInfoCorrectionY);
  356.                                         end;
  357.                                     end else if (Nade[b].FlashList.IndexOf(inttostr(i))>-1) then begin
  358.                                         for c := 1 to MaxPlayer do if (Players[c].Active) then begin
  359.                                             if (Players[b].Team = Players[c].Team) then Players[c].WorldText(NadeInfoLayerStart+i,'Flash!',NadeInfoTime,FlashInfoColor,NadeInfoSize,Map.Bullets[i].X-NadeInfoCorrectionX,Map.Bullets[i].Y-NadeInfoCorrectionY) else if not Map.RayCast(Map.Bullets[i].X,Map.Bullets[i].Y-RayCastCorection,Players[c].X,Players[c].Y-RayCastCorection,true, false, false, false, 2) then Players[c].WorldText(NadeInfoLayerStart+i,'Flash!',NadeInfoTime,FlashInfoColor,NadeInfoSize,Map.Bullets[i].X-NadeInfoCorrectionX,Map.Bullets[i].Y-NadeInfoCorrectionY);
  360.                                         end;
  361.                                     end;
  362.                                 end;
  363.                             end;
  364.                         end else
  365.                         begin
  366.                             for b := 1 to MaxPlayer do if (Players[b].Active) then begin
  367.                                 if (Nade[b].NadeList.IndexOf(inttostr(i))>-1) then Players.WorldText(NadeInfoLayerStart+i,'Nade!',NadeInfoTime,NadeInfoColor,NadeInfoSize,Map.Bullets[i].X-NadeInfoCorrectionX,Map.Bullets[i].Y-NadeInfoCorrectionY) else if (Nade[b].FlashList.IndexOf(inttostr(i))>-1) then Players.WorldText(NadeInfoLayerStart+i,'Flash!',NadeInfoTime,FlashInfoColor,NadeInfoSize,Map.Bullets[i].X-NadeInfoCorrectionX,Map.Bullets[i].Y-NadeInfoCorrectionY);
  368.                             end;
  369.                         end;
  370.                     end;
  371.                 2: begin
  372.                         for b := 1 to MaxPlayer do if (Players[b].Active) then begin
  373.                             if (Players[Map.Bullets[i].Owner].Team=Players[b].Team) then begin
  374.                                 if (Nade[b].NadeList.IndexOf(inttostr(i))>-1) then begin
  375.                                     for c := 1 to MaxPlayer do if (Players[c].Active) and (Players[b].Team = Players[c].Team) then Players[c].WorldText(NadeInfoLayerStart+i,'Nade!',NadeInfoTime,NadeInfoColor,NadeInfoSize,Map.Bullets[i].X-NadeInfoCorrectionX,Map.Bullets[i].Y-NadeInfoCorrectionY);
  376.                                 end else if (Nade[b].FlashList.IndexOf(inttostr(i))>-1) then for c := 1 to MaxPlayer do if (Players[c].Active) and (Players[b].Team = Players[c].Team) then Players[c].WorldText(NadeInfoLayerStart+i,'Flash!',NadeInfoTime,FlashInfoColor,NadeInfoSize,Map.Bullets[i].X-NadeInfoCorrectionX,Map.Bullets[i].Y-NadeInfoCorrectionY);
  377.                             end;
  378.                         end;
  379.                     end;
  380.                 3: if (Nade[Map.Bullets[i].Owner].NadeList.IndexOf(inttostr(i))>-1) then Players[Map.Bullets[i].Owner].WorldText(NadeInfoLayerStart+i,'Nade!',NadeInfoTime,NadeInfoColor,NadeInfoSize,Map.Bullets[i].X-NadeInfoCorrectionX,Map.Bullets[i].Y-NadeInfoCorrectionY) else if (Nade[Map.Bullets[i].Owner].FlashList.IndexOf(inttostr(i))>-1) then Players[Map.Bullets[i].Owner].WorldText(NadeInfoLayerStart+i,'Flash!',NadeInfoTime,FlashInfoColor,NadeInfoSize,Map.Bullets[i].X-NadeInfoCorrectionX,Map.Bullets[i].Y-NadeInfoCorrectionY);
  381.             end;
  382.         end;
  383.     end;
  384. end;
  385.  
  386. procedure keypresschange();
  387. var i:byte;
  388. begin
  389.     for i := 1 to MaxPlayer do if (Players[i].Active) then begin
  390.         if (Players[i].KeyChangeWeap) and (Players[i].KeyCrouch) then begin   //KEY PRESS EDIT
  391.             if (Nade[i].Style<>3) then begin
  392.                 if (Nade[i].Style=0) then begin
  393.                     if (Nade[i].FlashCount>0) then Nade[i].Style := 1;
  394.                 end else if (Nade[i].NadeCount>0) then Nade[i].Style := 0;
  395.             end;
  396.         end;
  397.     end;
  398. end;
  399.  
  400. procedure UseGranadeKit(Player: TActivePlayer; Kit: TActiveMapObject);
  401. var temp:integer;
  402. begin
  403.     if (Kit.Style=17) then begin
  404.         if (Nade[Player.ID].NadeCount<MaxNormalCount) or (Nade[Player.ID].FlashCount<MaxFlashCount) then begin
  405.             if (GranadeKitNadeGive > 0) then begin
  406.                 temp := Nade[Player.ID].NadeCount+GranadeKitNadeGive;
  407.                 if (temp>MaxNormalCount) then Nade[Player.ID].NadeCount:=MaxNormalCount else Nade[Player.ID].NadeCount := temp;
  408.             end;
  409.             if (GranadeKitFlashGive > 0) then begin
  410.                 temp := Nade[Player.ID].FlashCount+GranadeKitFlashGive;
  411.                 if (temp>MaxFlashCount) then Nade[Player.ID].FlashCount:=MaxFlashCount else Nade[Player.ID].FlashCount := temp;
  412.             end;
  413.         end;
  414.     end;
  415. end;
  416.  
  417. procedure NadeKitUse();
  418. var KillHere: boolean; i,b:byte; temp:integer; UnDeadBox: TNewMapObject;
  419. begin
  420.     if (GranadeKitNadeGive=0) and (GranadeKitFlashGive=0) then exit;
  421.     for i := 1 to MaxPlayer do if (Players[i].Active) then begin
  422.         if (Players[i].Team<5) then begin
  423.             for b := 1 to 90 do if (Map.Objects[b].Active) then begin
  424.                 if (Map.Objects[b].Style=17) then begin
  425.                     if (Distance(Players[i].X,Players[i].Y,Map.Objects[b].X,Map.Objects[b].Y)<DistanceToGetNadeKit) then begin
  426.                         KillHere := false;
  427.                         if (GranadeKitNadeGive > 0) then begin
  428.                             if (Nade[i].NadeCount<MaxNormalCount) then begin
  429.                                 KillHere:=true;
  430.                                 UnDeadBox := TNewMapObject.Create;
  431.                                 UnDeadBox.Style:=17; UnDeadBox.X:=Map.Objects[b].X; UnDeadBox.Y:=Map.Objects[b].Y+12000;
  432.                                 Map.Objects[b].Kill; Map.AddObject(UnDeadBox); UnDeadBox.Free;
  433.                                 temp := Nade[i].NadeCount+GranadeKitNadeGive;
  434.                                 if (temp>MaxNormalCount) then Nade[i].NadeCount:=MaxNormalCount else Nade[i].NadeCount := temp;
  435.                             end;
  436.                         end;
  437.                         if (GranadeKitFlashGive > 0) then begin
  438.                             if (Nade[i].FlashCount<MaxFlashCount) then begin
  439.                                 if (KillHere=false) then begin
  440.                                     UnDeadBox := TNewMapObject.Create;
  441.                                     UnDeadBox.Style:=17; UnDeadBox.X:=Map.Objects[b].X; UnDeadBox.Y:=Map.Objects[b].Y+12000;
  442.                                     Map.Objects[b].Kill; Map.AddObject(UnDeadBox); UnDeadBox.Free;
  443.                                 end;
  444.                                 KillHere:=true;
  445.                                 temp := Nade[i].FlashCount+GranadeKitFlashGive;
  446.                                 if (temp>MaxFlashCount) then Nade[i].FlashCount:=MaxFlashCount else Nade[i].FlashCount := temp;
  447.                             end;
  448.                         end;
  449.                         if (KillHere) then break;
  450.                     end;
  451.                 end;
  452.             end;
  453.         end;
  454.     end;
  455. end;
  456.  
  457. procedure Frezzle();
  458. var i:byte;
  459. begin
  460.     if (AntyNadeMove=true) then begin
  461.         for i:= 1 to MaxPlayer do if (Players[i].Active) and (Players[i].Team<5) then begin
  462.             if (Nade[i].FrezleTime <= 0) then begin
  463.                 Nade[i].LastPosX := Players[i].X;
  464.                 Nade[i].LastPosY := Players[i].Y;
  465.                 Nade[i].LastVelX.Append(floattostr(Players[i].VelX));
  466.                 if (Nade[i].LastVelX.Count>VelListMax) then Nade[i].LastVelX.Delete(0);
  467.                 Nade[i].LastVelY.Append(floattostr(Players[i].VelY));
  468.                 if (Nade[i].LastVelY.Count>VelListMax) then Nade[i].LastVelY.Delete(0);
  469.             end else
  470.             begin
  471.                 if (Nade[i].FrezleTime>0) then begin
  472.                     Nade[i].FrezleTime := Nade[i].FrezleTime-1;
  473.                     Players[i].Move(Nade[i].LastPosX,Nade[i].LastPosY);
  474.                     Players[i].SetVelocity(0,0);
  475.                     if (Nade[i].FrezleTime=0) and (Nade[i].LastVelX.Count=VelListMax) and (Nade[i].LastVelY.Count=VelListMax) then Players[i].SetVelocity(StrToFloat(Nade[i].LastVelX[0]),StrToFloat(Nade[i].LastVelY[0]));
  476.                 end;
  477.             end;
  478.         end;
  479.     end;
  480. end;
  481.  
  482. procedure Timers(Ticks: integer);
  483. begin
  484.     RemoveNades();
  485.     NadesCreate();
  486.     NadeControl();
  487.     DisplayNadeInfo();
  488.     NadeKitUse();
  489.     Frezzle();
  490.     if (AllowKeyPress=true) then begin
  491.         if ((Ticks mod 34) = 0) then keypresschange();
  492.     end;
  493. end;
  494.  
  495. procedure Recompile();
  496. var i:byte;
  497. begin
  498.     Game.MaxGrenades := 1;
  499.     for i := 1 to MaxPlayer do begin
  500.         Nade[i].Style := 0;
  501.         Nade[i].NadeCount := MaxNormalCount;
  502.         Nade[i].FlashCount := MaxFlashCount;
  503.         Nade[i].FrezleTime := 0;
  504.         Nade[i].FlashList := File.CreateStringList();
  505.         Nade[i].NadeList := File.CreateStringList();
  506.         Nade[i].LastVelX := File.CreateStringList();
  507.         Nade[i].LastVelY := File.CreateStringList();
  508.     end;
  509. end;
  510.  
  511. procedure ScriptDecl();
  512. var i:byte;
  513. begin
  514.     for i := 0 to 5 do Game.Teams[i].OnJoin := @JoinTeam;
  515.     Game.TickThreshold := 1;
  516.     Game.OnClockTick := @Timers;
  517.     Game.OnLeave := @LeaveGame;
  518.     Game.OnJoin := @JoinGame;
  519.     Map.OnAfterMapChange := @ChangeAfter;
  520.     for i := 1 to MaxPlayer do begin
  521.         Players[i].OnDamage := @NadeDamage;
  522.         Players[i].OnKitPickup := @UseGranadeKit;
  523.         Players[i].OnAfterRespawn := @OnAfterRespawn;
  524.         Players[i].OnCommand := @Commands;
  525.     end;
  526. end;
  527.  
  528. initialization
  529. begin
  530.     ScriptDecl();
  531.     Recompile();
  532. end;
  533.  
  534. finalization;
  535. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement