Author Topic: Script crashing on every kill  (Read 849 times)

0 Members and 1 Guest are viewing this topic.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Script crashing on every kill
« on: August 03, 2011, 02:28:05 am »
whenever i kill something, this script would crash about 10 times, causing the server to freeze up, i cannot figure out whats causing the script to overload
Code: (pascal) [Select]
const
Bullet = 1;
Nade = 2;
Shotgun = 3;
M79 = 4;
Flame = 5;
Punch = 6;
Arrow = 7;
FArrow = 8;
CNade = 9;
CPellet = 10;
Chainsaw = 11;
LAW = 12;
Knife = 13;
SGun = 14;
SCRIPTVER = '2.1.55';


var
x,y,x2,y2,Dist:Single;
PosX, PosY: Array[1..32] of Single;
BioKills,DKills: Array[0..32] of Integer;

function RangeKill(Owner, Victim, Range, HitMult, BulletType:Integer):Integer;
var i,Team:Byte;
begin
    { x := GetPlayerStat(Victim,'x');
     y := GetPlayerStat(Victim,'y');}
     Team := GetPlayerStat(Owner, 'Team');
      for i := 1 to 32 do begin
       {x2 := GetPlayerStat(i,'x');
       y2 := GetPlayerStat(i,'y');}
       if (Distance(x,y,x2,y2) <= Range) AND (Team <> GetPlayerStat(i, 'Team')) AND (GetPlayerStat(i,'Active') = true) AND (GetPlayerStat(i,'Team') = 2) AND (GetPlayerStat(i,'Alive') = true) then begin
         //CreateBullet(GetPlayerStat(i,'x'), GetPlayerStat(i,'y'), VelX,VelY,HitMult, BulletType, Owner);
         DoDamageBy(i,Owner, HitMult);
BioKills[Owner]:=BioKills[Owner]+1;
       end;
     end;
     WriteConsole(Owner,'Bio-Kills: '+Inttostr(BioKills[Owner]),$EE81FAA1);
     BioKills[Owner] := 0;
end;

procedure Nova(const X,Y,speed,decentralize,power: single; ID,style: byte; n: integer);
var i: integer;
angle: single;
begin
  angle := 2*pi/n;
  for i:=0 to n do
    CreateBullet(X+cos(angle*i)*decentralize, Y+sin(angle*i)*decentralize, cos(angle*i)*speed, sin(angle*i)*speed, power,style , ID );
end;


procedure OnPlayerKill(Killer, Victim: byte; Weapon: string);
Var F,i: Byte; Dist: Single; Wepname:String;
begin
 //if Weapon = 'Cluster Grenades' then begin
   //RangeKill(Killer, Victim, 500,100, Bullet);
  //end;
 
   if Weapon = 'Combat Knife' then begin
    RangeKill(Killer, Victim, 500,100, Bullet);
  end;

  if Weapon = 'Grenade' then begin
    RangeKill(Killer, Victim, 200,25, Bullet);
  end;
 
   //if Weapon = 'M79' then begin
    //RangeKill(Killer, Victim, 50,25, CPellet);
  //end;

  if Weapon = 'Barrett M82A1' then begin
    RangeKill(Killer, Victim, 200,50, Bullet);
  end;

  if Weapon = 'HK MP5' then begin
    RangeKill(Killer, Victim, 200, 10, Bullet);
  end;

  if Weapon = 'Ak-74' then begin
    RangeKill(Killer, Victim, 200, 10, Bullet);
  end;

  if Weapon = 'Steyr AUG' then begin
    RangeKill(Killer, Victim, 200, 10, Bullet);
  end;

  if Weapon = 'FN Minimi' then begin
    RangeKill(Killer, Victim, 200, 10, Bullet);
  end;

 if Weapon = 'Spas-12' then begin
    RangeKill(Killer, Victim, 300, 5, Shotgun);
  end;

  if Weapon = 'Ruger 77' then begin
 RangeKill(Killer, Victim, 225, 12, Bullet);
  end;

//if Weapon = 'Chainsaw' then begin
//     x := GetPlayerStat(Victim,'x');
//    y := GetPlayerStat(Victim,'y');
//    for i := 1 to 32 do begin
//      x2 := GetPlayerStat(i,'x');
//      y2 := GetPlayerStat(i,'y');
//      if (RayCast(x,y,x2,y2,Dist,300000)) AND (i <> Killer) AND (GetPlayerStat(i,'Active') = true) AND (GetPlayerStat(i,'Team') <> GetPlayerStat(Killer,'Team')) then begin   
//        CreateBullet(GetPlayerStat(i,'x'), GetPlayerStat(i,'y') - 0, 0,-10,1000, 3, Killer);
//        BioKills[Killer]:=BioKills[Killer]+1;
//      end;
//    end;
//    WriteConsole(Killer,'Bio-Kills: '+Inttostr(BioKills[Killer]),$EE81FAA1);
//    BioKills[Killer]:=0;
//  end;

  if Weapon = 'LAW' then begin
    RangeKill(Killer, Victim, 100,1000, Shotgun);
  end;

  //if Weapon = 'M79' then begin
    //RangeKill(Killer, Victim, 400,1000, CPellet);
  //end;

//if Weapon = 'Spas-12' then begin
//Nova(GetPlayerStat(Victim,'x'),Getplayerstat(Victim,'y'),200,30,0,Killer,4,200);
//end;
end;

procedure OnPlayerSpeak(ID: Byte; Text: string);
begin
if Lowercase(Text) = '!info biokills' then begin
WriteConsole(0,'This server is using Frostys BioKills script v'+SCRIPTVER, $00FFFF00);
WriteConsole(0,'The BioKills script kills or does damage to all zombies within a set range', $00FFFF00);
WriteConsole(0,'after a particular weapon is used', $00FFFF00);
WriteConsole(0,'ranges are different for each weapon', $00FFFF00);
end;
end;

i keep getting this just before script crash in ARSSE:
 OnPlayerKill: Access violation at address 080FB288, accessing address 0000005A

any idea whats causing this?

i have ruled out any possibility of script conflict by disabling all other custom scripts that use onplayerkill

heres the interesting part....:
if i uncomment out the code for CreateBullet and and the player coords and add VelX and VelY to the () part of Rangekill when i define the function and comment out DoDamageBy...it never crashes, it cant be an infinite eloop otherwise createbullet itself would freeze the server....its getting beyond a joke, i ahve to keep this script disabled as to not crash the server (server itself doesnt crash, just lags like crap to the point of total freezing and then i have to login to the website and restart it)

if DodamageBy isnt the issue then Why The F*** would the server have NO issues whatsover when DoDamageBy is replaced with Createbullet???????? i dont get it

thanks in advance

« Last Edit: August 03, 2011, 02:31:21 am by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: Script crashing on every kill
« Reply #1 on: August 03, 2011, 03:02:01 am »
First of all, optimize this script, it's very inefficient. Use GetPlayerXY instead of GetPlayerStat(), replace
Quote
if (Distance(x,y,x2,y2) <= Range) AND (Team <> GetPlayerStat(i, 'Team')) AND (GetPlayerStat(i,'Active') = true) AND (GetPlayerStat(i,'Team') = 2) AND (GetPlayerStat(i,'Alive') = true) then
with
if i <> victim then
if (GetPlayerStat(i,'Alive') = true) then
if (Distance(x,y,x2,y2) <= Range) then
if (GetPlayerStat(i,'Active') = true) then
if (Team <> GetPlayerStat(i, 'Team')) then
if (GetPlayerStat(i,'Team') = 2) then

Also
if Weapon = 'Combat Knife' then begin  lines with case Weapon of

Make sure if OnPlayerKill isn't called on a dead player again, causing infinite loops
« Last Edit: August 03, 2011, 03:06:15 am by tk »

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: Script crashing on every kill
« Reply #2 on: August 12, 2011, 06:36:01 pm »
Thanks tk but still having crash trouble

Code: (pascal) [Select]
const
Bullet = 1;
Nade = 2;
Shotgun = 3;
M79 = 4;
Flame = 5;
Punch = 6;
Arrow = 7;
FArrow = 8;
CNade = 9;
CPellet = 10;
Chainsaw = 11;
LAW = 12;
Knife = 13;
SGun = 14;
SCRIPTVER = '2.1.55';


var
x,y,x2,y2,Dist:Single;
PosX, PosY: Array[1..32] of Single;
BioKills,DKills: Array[0..32] of Integer;

function RangeKill(Owner, Victim, Range, HitMult, BulletType:Integer):Integer;
var i,Team:Byte;
begin
    GetPlayerXY(Victim,X,Y);
     Team := GetPlayerStat(Owner, 'Team');
      for i := 1 to 32 do begin
       GetPlayerXY(i,x2,y2);
       if i <> victim then
if (GetPlayerStat(i,'Alive') = true) then
         if (Distance(X,Y,x2,y2) <= Range) then
          if (GetPlayerStat(i,'Active') = true) then
           if (Team <> GetPlayerStat(i, 'Team')) then
            if (GetPlayerStat(i,'Team') = 2) then begin
         CreateBullet(GetPlayerStat(i,'x'), GetPlayerStat(i,'y'), 0,1,HitMult, BulletType, Owner);
         //DoDamageBy(i,Owner, HitMult);
BioKills[Owner]:=BioKills[Owner]+1;
       end;
     end;
     WriteConsole(Owner,'Bio-Kills: '+Inttostr(BioKills[Owner]),$EE81FAA1);
     BioKills[Owner] := 0;
end;

procedure Nova(const X,Y,speed,decentralize,power: single; ID,style: byte; n: integer);
var i: integer;
angle: single;
begin
  angle := 2*pi/n;
  for i:=0 to n do
    CreateBullet(X+cos(angle*i)*decentralize, Y+sin(angle*i)*decentralize, cos(angle*i)*speed, sin(angle*i)*speed, power,style , ID );
end;


procedure OnPlayerKill(Killer, Victim: byte; Weapon: string);
Var F,i: Byte; Dist: Single; Wepname:String;
begin
  Case Weapon of
   //'Cluster Grenades' : RangeKill(Killer, Victim, 50,100, Bullet);
 
   'Combat Knife' : RangeKill(Killer, Victim, 200,100, M79);

   'Grenade' : RangeKill(Killer, Victim, 200,25, Bullet);
 
   'M79' : RangeKill(Killer, Victim, 75, 5, CPellet);
 
   'Barrett M82A1': RangeKill(Killer, Victim, 200,2, Shotgun);

   'HK MP5' : RangeKill(Killer, Victim, 200, 1, Bullet);

   'Ak-74': RangeKill(Killer, Victim, 200, 10, Bullet);

   'Steyr AUG' : RangeKill(Killer, Victim, 200, 10, Bullet);

   'FN Minimi' : RangeKill(Killer, Victim, 200, 10, Bullet);

   'Spas-12' : RangeKill(Killer, Victim, 300, 5, Shotgun);

   'Ruger 77' : RangeKill(Killer, Victim, 225, 12, Bullet);

   'Chainsaw' : RangeKill(Killer, Victim, 150, 2, Shotgun);

   'LAW' : RangeKill(Killer, Victim, 100,1000, Shotgun);

  //'M79' : RangeKill(Killer, Victim, 400,1000, CPellet);

    'Spas-12' : Nova(GetPlayerStat(Victim,'x'),Getplayerstat(Victim,'y'),200,30,0,Killer,4,200);
end;
end;

procedure OnPlayerSpeak(ID: Byte; Text: string);
begin
if Lowercase(Text) = '!info biokills' then begin
WriteConsole(0,'This server is using Frostys BioKills script v'+SCRIPTVER, $00FFFF00);
WriteConsole(0,'The BioKills script kills or does damage to all zombies within a set range', $00FFFF00);
WriteConsole(0,'after a particular weapon is used', $00FFFF00);
WriteConsole(0,'ranges are different for each weapon', $00FFFF00);
end;
end;
check out my server! click here

If at first you don't succeed, Improvise! :D