Author Topic: Exception: Access violation  (Read 2244 times)

0 Members and 1 Guest are viewing this topic.

Offline soldat-game

  • Camper
  • ***
  • Posts: 407
Exception: Access violation
« on: September 12, 2016, 11:51:44 am »
Code: [Select]
if (PlayerInfo[ID].Wep2=17) or (PlayerInfo[ID].Wep2=0) or (PlayerInfo[ID].Wep2=11) then begin
NS:=TNewWeapon.Create(); NS.WType:=PlayerInfo[ID].Wep1; NS.Ammo:=GetMinAmmo(PlayerInfo[ID].Wep1);
NW:=TNewWeapon.Create(); NW.WType:=13; NW.Ammo:=GetMinAmmo(13);
if (PlayerInfo[ID].Wep2<>17) then WepAmmo[PlayerInfo[ID].Wep2][ID]:=(GetMinAmmo(PlayerInfo[ID].Wep2)-Random(0,1+Trunc(RanDropAmmo*GetMinAmmo(PlayerInfo[ID].Wep2))));
WepAmmo[13][ID]:=GetMaxAmmo(13);
Players[ID].ForceWeapon(NS,NW);
NS.Free(); NW.Free();
end;

Exception: Access violation ---> Players[ID].ForceWeapon(NS,NW);

WHY? Falcon why all changes why all dont work?

Offline Mighty

  • Camper
  • ***
  • Posts: 276
Re: Exception: Access violation
« Reply #1 on: September 13, 2016, 02:48:14 am »
Please show us values of NS and NW fields right before the line that generates an error.
Also, it's good practice to use constants representing weapon types instead of numbers.
You can find the constants on the wiki: TWeapon.WType
xFire: macmil        e-mail: macekmil@gmail.com
My scripts: Accuracy Script       Flashbang       Punishments GUID
            CatchMe Gamemod       AntiFake
            CW System             AntiFakeGUID

Offline soldat-game

  • Camper
  • ***
  • Posts: 407
Re: Exception: Access violation
« Reply #2 on: September 13, 2016, 02:22:08 pm »
Code: [Select]
procedure WeaponAmmoChangeLimit(ID:byte);
var NW,NS:TNewWeapon; WeapChangeRan:byte;
begin
case (PlayerInfo[id].ClassID) of
1: begin
if (PlayerInfo[ID].Resp=False) then begin
if (Players[id].Primary.Wtype>16) then PlayerInfo[ID].Wep1 := 17 else PlayerInfo[ID].Wep1 := Players[id].Primary.Wtype;
if (Players[id].Secondary.Wtype>16) then PlayerInfo[ID].Wep2 := 17 else PlayerInfo[ID].Wep2 := Players[id].Secondary.Wtype;
if (PlayerInfo[ID].Wep1<18) and (PlayerInfo[ID].Wep2<18) then begin
WepAmmo[PlayerInfo[ID].Wep1][ID]:=GetMaxAmmo(PlayerInfo[ID].Wep1);
WepAmmo[PlayerInfo[ID].Wep2][ID]:=GetMaxAmmo(PlayerInfo[ID].Wep2);
end;
if (PlayerInfo[ID].Wep2=12) or (PlayerInfo[ID].Wep2=13) then begin
WeapChangeRan:=iif(Random(1,3)=1,11,0);
NS:=TNewWeapon.Create(); NS.WType:=PlayerInfo[ID].Wep1; NS.Ammo:=GetMinAmmo(PlayerInfo[ID].Wep1);
NW:=TNewWeapon.Create(); NW.WType:=WeapChangeRan; NW.Ammo:=GetMinAmmo(WeapChangeRan);
WepAmmo[PlayerInfo[ID].Wep2][ID]:=(GetMinAmmo(PlayerInfo[ID].Wep2)-Random(0,1+Trunc(RanDropAmmo*GetMinAmmo(PlayerInfo[ID].Wep2))));
WepAmmo[WeapChangeRan][ID]:=GetMaxAmmo(WeapChangeRan);
Players[ID].ForceWeapon(NS,NW);
NS.Free(); NW.Free();
end;
end else
begin
WepAmmo[1][ID]:=GetMaxAmmo(1);
WepAmmo[3][ID]:=GetMaxAmmo(3);
WepAmmo[4][ID]:=GetMaxAmmo(4);
WepAmmo[0][ID]:=GetMaxAmmo(0);
WepAmmo[11][ID]:=GetMaxAmmo(11);
end;
end;
2: begin
if (PlayerInfo[ID].Resp=False) then begin
if (Players[id].Primary.Wtype>16) then PlayerInfo[ID].Wep1 := 17 else PlayerInfo[ID].Wep1 := Players[id].Primary.Wtype;
if (Players[id].Secondary.Wtype>16) then PlayerInfo[ID].Wep2 := 17 else PlayerInfo[ID].Wep2 := Players[id].Secondary.Wtype;
if (PlayerInfo[ID].Wep1<18) and (PlayerInfo[ID].Wep2<18) then begin
WepAmmo[PlayerInfo[ID].Wep1][ID]:=GetMaxAmmo(PlayerInfo[ID].Wep1);
WepAmmo[PlayerInfo[ID].Wep2][ID]:=GetMaxAmmo(PlayerInfo[ID].Wep2);
end;
if (PlayerInfo[ID].Wep2=12) or (PlayerInfo[ID].Wep2=13) then begin
WeapChangeRan:=iif(Random(1,3)=1,11,0);
NS:=TNewWeapon.Create(); NS.WType:=PlayerInfo[ID].Wep1; NS.Ammo:=GetMinAmmo(PlayerInfo[ID].Wep1);
NW:=TNewWeapon.Create(); NW.WType:=WeapChangeRan; NW.Ammo:=GetMinAmmo(WeapChangeRan);
WepAmmo[PlayerInfo[ID].Wep2][ID]:=(GetMinAmmo(PlayerInfo[ID].Wep2)-Random(0,1+Trunc(RanDropAmmo*GetMinAmmo(PlayerInfo[ID].Wep2))));
WepAmmo[WeapChangeRan][ID]:=GetMaxAmmo(WeapChangeRan);
Players[ID].ForceWeapon(NS,NW);
NS.Free(); NW.Free();
end;
end else
begin
WepAmmo[2][ID]:=GetMaxAmmo(2);
WepAmmo[9][ID]:=GetMaxAmmo(9);
WepAmmo[10][ID]:=GetMaxAmmo(10);
WepAmmo[0][ID]:=GetMaxAmmo(0);
WepAmmo[11][ID]:=GetMaxAmmo(11);
end;
end;
3: begin
if (PlayerInfo[ID].Resp=False) then begin
if (Players[id].Primary.Wtype>16) then PlayerInfo[ID].Wep1 := 17 else PlayerInfo[ID].Wep1 := Players[id].Primary.Wtype;
if (Players[id].Secondary.Wtype>16) then PlayerInfo[ID].Wep2 := 17 else PlayerInfo[ID].Wep2 := Players[id].Secondary.Wtype;
if (PlayerInfo[ID].Wep1<18) and (PlayerInfo[ID].Wep2<18) then begin
WepAmmo[PlayerInfo[ID].Wep1][ID]:=GetMaxAmmo(PlayerInfo[ID].Wep1);
WepAmmo[PlayerInfo[ID].Wep2][ID]:=GetMaxAmmo(PlayerInfo[ID].Wep2);
end;
if (PlayerInfo[ID].Wep2=12) or (PlayerInfo[ID].Wep2=13) then begin
WeapChangeRan:=iif(Random(1,3)=1,11,0);
NS:=TNewWeapon.Create(); NS.WType:=PlayerInfo[ID].Wep1; NS.Ammo:=GetMinAmmo(PlayerInfo[ID].Wep1);
NW:=TNewWeapon.Create(); NW.WType:=WeapChangeRan; NW.Ammo:=GetMinAmmo(WeapChangeRan);
WepAmmo[PlayerInfo[ID].Wep2][ID]:=(GetMinAmmo(PlayerInfo[ID].Wep2)-Random(0,1+Trunc(RanDropAmmo*GetMinAmmo(PlayerInfo[ID].Wep2))));
WepAmmo[WeapChangeRan][ID]:=GetMaxAmmo(WeapChangeRan);
Players[ID].ForceWeapon(NS,NW);
NS.Free(); NW.Free();
end;
end else
begin
WepAmmo[5][ID]:=GetMaxAmmo(5);
WepAmmo[6][ID]:=GetMaxAmmo(6);
WepAmmo[8][ID]:=GetMaxAmmo(8);
WepAmmo[0][ID]:=GetMaxAmmo(0);
WepAmmo[11][ID]:=GetMaxAmmo(11);
end;
end;
4: begin
if (PlayerInfo[ID].Resp=False) then begin
if (Players[id].Primary.Wtype>16) then PlayerInfo[ID].Wep1 := 17 else PlayerInfo[ID].Wep1 := Players[id].Primary.Wtype;
if (Players[id].Secondary.Wtype>16) then PlayerInfo[ID].Wep2 := 17 else PlayerInfo[ID].Wep2 := Players[id].Secondary.Wtype;
if (PlayerInfo[ID].Wep1<18) and (PlayerInfo[ID].Wep2<18) then begin
WepAmmo[PlayerInfo[ID].Wep1][ID]:=GetMaxAmmo(PlayerInfo[ID].Wep1);
WepAmmo[PlayerInfo[ID].Wep2][ID]:=GetMaxAmmo(PlayerInfo[ID].Wep2);
end;
if (PlayerInfo[ID].Wep2=17) or (PlayerInfo[ID].Wep2=0) or (PlayerInfo[ID].Wep2=11) then begin
NS:=TNewWeapon.Create(); NS.WType:=PlayerInfo[ID].Wep1; NS.Ammo:=GetMinAmmo(PlayerInfo[ID].Wep1);
NW:=TNewWeapon.Create(); NW.WType:=13; NW.Ammo:=GetMinAmmo(13);
if (PlayerInfo[ID].Wep2<>17) then WepAmmo[PlayerInfo[ID].Wep2][ID]:=(GetMinAmmo(PlayerInfo[ID].Wep2)-Random(0,1+Trunc(RanDropAmmo*GetMinAmmo(PlayerInfo[ID].Wep2))));
WepAmmo[13][ID]:=GetMaxAmmo(13);
Players[ID].ForceWeapon(NS,NW);
NS.Free(); NW.Free();
end;
end else
begin
WepAmmo[2][ID]:=GetMaxAmmo(2);
WepAmmo[4][ID]:=GetMaxAmmo(4);
WepAmmo[7][ID]:=GetMaxAmmo(7);
WepAmmo[12][ID]:=GetMaxAmmo(12);
WepAmmo[13][ID]:=GetMaxAmmo(13);
end;
end;
end;
end;

Offline soldat-game

  • Camper
  • ***
  • Posts: 407
Re: Exception: Access violation
« Reply #3 on: September 14, 2016, 10:40:51 am »
FlagX[1] := round(Map.RedFlag.X);   FlagY[1] := round(Map.RedFlag.Y); ---> Could not call proc (Could not call proc)
flagx and other array 1.2 single

if (isCompile=false) then begin
   isCompile := True;
   FlagX[1] := round(Map.RedFlag.X);   FlagY[1] := round(Map.RedFlag.Y);
   flagX[2] := round(Map.BlueFlag.X);   FlagY[2] := round(Map.BlueFlag.Y);
end;