0 Members and 1 Guest are viewing this topic.
This function is known to cause bugs on both Client and Server! On some Operating Systems this function will cease to function properly after awhile. So dont email me about it.
Const AutoAirstrikeFrequency=6;//min RaidsPerStrike=12; RaidInterval=3;//s RaidAccuracy=0.3;//*MissilesPerRaid*MissileStep MissilesPerRaid=12; MissileStep=40;//distance between missilesVar AirstrikesAllowed:boolean; AutoAirStrikesAllowed:boolean; TargetTeam:byte; PerformingAirstrike:boolean; Raid:byte; FP:shortint;//flags positions =1 if red flag on the left side of the map and blue flag is on the right side of the map CenterX,CenterY:single;Procedure ShowGreeting(player:byte); Begin writeConsole(player, 'Server is using AirStrike scipt v0.8 by VTT', rgb(20,20,20)); End;Procedure GetMapParams; Var BlueFlagX,BlueFlagY,RedFlagX,RedFlagY:single; Begin GetFlagsXY(BlueFlagX, BlueFlagY, RedFlagX, RedFlagY); CenterX:=(BlueFlagX+RedFlagX)/2; CenterY:=(BlueFlagY+RedFlagY)/2; FP:=iif(RedFlagX<BlueFlagX,1,-1); ShowGreeting(0); writeConsole(0, 'FP='+inttostr(FP), rgb(20,20,20)); writeConsole(0, 'Cen: ('+floattostr(round(CenterX))+' ; '+floattostr(Round(CenterY))+' )', rgb(20,20,20)); End;Procedure PerformAirStrike(Team:byte); Begin case Team of 1: if AlphaPlayers=0 then exit; 2: begin if BravoPlayers=0 then Exit; end; else exit; end; WriteConsole(0, 'Test point passed '+inttostr(Team), rgb(20,20,20)); Raid:=0; TargetTeam:=Team; DrawText(0,'Air-raid warning!',330,RGB(240,20,20),0.15,70,400); Case team of 1: WriteConsole(0, 'AirStrike on Alpha team!', rgb(240,20,20)); 2: WriteConsole(0, 'AirStrike on Bravo team!', rgb(20,20,240)); end; PerformingAirstrike:=true; End;Procedure StopAirStrike; Begin PerformingAirstrike:=false; DrawText(0,'Air-raid warning over!',330,RGB(20,240,20),0.15,30,400); WriteConsole(0, 'AirStrike Complete!', rgb(20,20,20)); End; Function PickWinningTeam():byte; Var i:byte; AlphaPoints,BravoPoints:integer; Label q; Begin result:=1;//cheching score if AlphaScore>BravoScore then goto q; if AlphaScore<BravoScore then begin result:=2; goto q; end;//checking summary points for i:=1 to NumPlayers do begin if GetPlayerStat(i,'Team')=1 then AlphaPoints:=AlphaPoints+GetPlayerStat(i,'Kills'); if GetPlayerStat(i,'Team')=2 then BravoPoints:=BravoPoints+GetPlayerStat(i,'Kills'); end; if AlphaPoints>BravoPoints then goto q; if AlphaPoints<BravoPoints then begin result:=2; goto q; end;//checking summary deths for i:=1 to NumPlayers do begin if GetPlayerStat(i,'Team')=1 then AlphaPoints:=AlphaPoints+GetPlayerStat(i,'Deaths'); if GetPlayerStat(i,'Team')=2 then BravoPoints:=BravoPoints+GetPlayerStat(i,'Deaths'); end; if ((AlphaPoints<BravoPoints) and (AlphaPlayers>0)) then goto q; if ((AlphaPoints>BravoPoints) and (BravoPlayers>0)) then begin result:=2; goto q; end;//checking amaunt of players if AlphaPlayers>BravoPlayers then goto q; if AlphaPlayers<BravoPlayers then begin result:=2; goto q; end;//randomly choosing winning team result:=iif(Random(0,1)=0,1,2);q: case result of 1: WriteConsole(0, 'Winning team is Alpha', rgb(20,20,20)); 2: WriteConsole(0, 'Winning team is Bravo', rgb(20,20,20)); end; End;Function PickRandomPlayer(Team:byte):byte; Var i:byte; Begin case Team of 1: if AlphaPlayers=0 then begin StopAirStrike; exit; end; 2: if BravoPlayers=0 then begin StopAirStrike; exit; end; end; case Team of 1: i:=Random(1,AlphaPlayers); 2: i:=Random(1,BravoPlayers); end; result:=1; repeat if GetPlayerStat(result,'Team')=Team then i:=i-1 else result:=result+1; until i=0; writeConsole(0, 'Target player is '+IDtoName(result), rgb(20,20,20)); End;Procedure PerformAirRaid(Player:byte); Var i:integer; c:smallint; TargetLocationX,TargetLocationY:single; Begin case TargetTeam of 1:c:=1; 2:c:=-1; end; If ((Player=0) or (Player>NumPlayers)) then begin StopAirStrike; exit; end; GetPlayerXY(Player,TargetLocationX,TargetLocationY); i:=Round(MissileStep*MissilesPerRaid*RaidAccuracy); TargetLocationX:=TargetLocationX+FP*c*(MissilesPerRaid*MissileStep*0.5+Random(-i,i)); TargetLocationY:=CenterY-500; writeConsole(0, 'Target coordinates: ('+floattostr(round(TargetLocationX))+' ; '+floattostr(Round(TargetLocationY))+' )', rgb(20,20,20)); for i:=0 to MissilesPerRaid-1 do CreateBullet(TargetLocationX-FP*MissileStep*c*i,TargetLocationY,-0.05*FP*c,10-i,10000,8,0); End;Procedure EnableAirStrikes; Begin AirstrikesAllowed:=true; WriteConsole(0, 'Airstrikes on', rgb(20,240,20)); End;Procedure DisableAirStrikes; Begin AirstrikesAllowed:=false; if PerformingAirstrike then StopAirStrike; WriteConsole(0, 'Airstrikes off', rgb(240,20,20)); End;Procedure EnableAutoAirStrikes; Begin EnableAirStrikes; AutoAirStrikesAllowed:=true; writeConsole(0, 'AutoAirstrikes will be performed every '+inttostr(AutoAirstrikeFrequency), rgb(20,240,20)); End;Procedure DisableAutoAirStrikes; Begin AutoAirStrikesAllowed:=false; WriteConsole(0, 'AutoAirstrikes off', rgb(240,20,20)); End;Procedure AirstrikesControler(Msg:string); Label q; Begin IF Msg='/airstrikes 0' then begin DisableAirStrikes; goto q; end; IF Msg='/airstrikes 1' then begin EnableAirStrikes; goto q; end; IF Msg='/autoairstrikes 0' then begin DisableAutoAirStrikes; goto q; end; IF Msg='/autoairstrikes 1' then begin EnableAutoAirStrikes; goto q; end; IF Msg='/airstrike' then if not PerformingAirstrike then begin PerformAirStrike(PickWinningTeam); goto q; end; IF Msg='/airstrike1' then if not PerformingAirstrike then begin PerformAirStrike(1); goto q; end; IF Msg='/airstrike2' then if not PerformingAirstrike then begin PerformAirStrike(2); goto q; end;q: End;
Procedure OnAdminMessage(IP, Msg: string); Begin AirstrikesControler(Msg); End;Procedure ActivateServer(); Begin FP:=1; //GetMapParams; //GetMapParams for some reason don't give proper results when server starts, so Fp:=1 for TW BattleField AirstrikesAllowed:=true; AutoAirStrikesAllowed:=true; End;Procedure AppOnIdle(Ticks: integer); Begin //AirStrikes if ((Ticks mod(60*RaidInterval)=0) and (PerformingAirstrike)) then if Raid<RaidsPerStrike then begin PerformAirRaid(PickRandomPlayer(TargetTeam)); Raid:=raid+1; end else StopAirstrike; //AutoAirStrikes if ((Ticks mod(3600*AutoAirstrikeFrequency)=0) and (AirstrikesAllowed) and (AutoAirStrikesAllowed)) then PerformAirStrike(PickWinningTeam); End;Function OnCommand(ID: Byte; Text: string): boolean;//NOTE: This function will be called when an admin types a / command. Begin AirstrikesControler(Text); Result := false; // Return true if you want to ignore the command typed. End;Procedure OnJoinGame(ID, Team: byte); Begin ShowGreeting(ID); End;Procedure OnMapChange(NewMap: string); Begin GetMapParams; End;
My server doesnt likeFP:=1;andAirstrikesControler(Msg);
Ok, and where do i put the other code? and where in the includes do i place it?
// All files specified below here will be // compiled for use with any SoldatServer// Scripts. Use // to mark a comment.// Manual:// http://enesce.com/help///SocketCore.pasAirStrike.pasCore.pasNetworkCore.pasAdminCore.pas
I wonder how Enesce does this. Surely he doesn't use this function as it is buggy.
As I said, works good on some OS's, in my case I use Debian Stable and some funky unique kernel by layeredtech....