Author Topic: Sometimes the damage is different than it should be?  (Read 3074 times)

0 Members and 1 Guest are viewing this topic.

Offline soldat-game

  • Camper
  • ***
  • Posts: 407
Sometimes the damage is different than it should be?
« on: June 26, 2017, 11:19:58 am »
Sometimes the damage is different than it should be?
GWN() return string weapon name from ini
function OnDamage(Shooter, Victim: TActivePlayer; Damage: Single; BulletId: Byte): Single;
var TempIndexID: int64; c,c2,c3,ShootSpeed: single; WeaponID: byte;
begin
...
Code: [Select]
ShootSpeed:=sqrt((Map.Bullets[BulletId].VelX*Map.Bullets[BulletId].VelX)+(Map.Bullets[BulletId].VelY*Map.Bullets[BulletId].VelY));
c := (WeaponsINI.ReadFloat(GWN(WeaponID),'Damage',0)*100)*(ShootSpeed/100)*WeaponsINI.ReadFloat(GWN(WeaponID),'ModifierHead',0);
c2 := (WeaponsINI.ReadFloat(GWN(WeaponID),'Damage',0)*100)*(ShootSpeed/100)*WeaponsINI.ReadFloat(GWN(WeaponID),'ModifierChest',0);
c3 := (WeaponsINI.ReadFloat(GWN(WeaponID),'Damage',0)*100)*(ShootSpeed/100)*WeaponsINI.ReadFloat(GWN(WeaponID),'ModifierLegs',0);
if (iif(Victim.Vest>0,Trunc(0.25*c),c)=Damage) then DrawTextEx(Shooter.ID,108,'Headshoot!',400,$F15D70,0.055,12,385) else
if (iif(GetPlayerStat(Victim.ID,'Vest')>0,Trunc(0.25*c2),c2)=Damage) then DrawTextEx(Shooter.ID,108,'BODY!',400,$F15D70,0.055,12,385) else
if (iif(GetPlayerStat(Victim.ID,'Vest')>0,Trunc(0.25*c3),c3)=Damage) then DrawTextEx(Shooter.ID,108,'LEGS!',400,$F15D70,0.055,12,385) else begin
WriteLn(Floattostr(c)+'    '+Floattostr(damage));
WriteLn(Floattostr(c2)+'    '+Floattostr(damage));
WriteLn(Floattostr(c3)+'    '+Floattostr(damage));
end;
...
end;

Offline soldat-game

  • Camper
  • ***
  • Posts: 407
Re: Sometimes the damage is different than it should be?
« Reply #1 on: June 26, 2017, 12:06:31 pm »
Im Try:
Code: [Select]
function RealDMG(nonreal:single):single;
var real:string;
begin
real:=floattostr(nonreal);
real:=Copy(real,1,8);
Result:=strtofloat(real);
end;

But

Offline NiCeShOoT|GuY

  • Major(1)
  • Posts: 21
Re: Sometimes the damage is different than it should be?
« Reply #2 on: June 26, 2017, 11:21:14 pm »
The damage are different for different shots, and are caused by different bullet speeds. Because in the code "ShootSpeed" is the only variable in the formula.
1.constant returned from WeaponsINI object: (WeaponsINI.ReadFloat(GWN(WeaponID),'Damage',0)*100)
2.constant returned from WeaponsINI object: WeaponsINI.ReadFloat(GWN(WeaponID),'ModifierHead',0)
3.variable from real-time bullet speed: (ShootSpeed/100)
where
ShootSpeed:=sqrt((Map.Bullets[BulletId].VelX*Map.Bullets[BulletId].VelX)+(Map.Bullets[BulletId].VelY*Map.Bullets[BulletId].VelY));

Code: [Select]
c := (WeaponsINI.ReadFloat(GWN(WeaponID),'Damage',0)*100)*(ShootSpeed/100)*WeaponsINI.ReadFloat(GWN(WeaponID),'ModifierHead',0);

To fix the unstable damage problem, you should find a way to turn every variables into constants. ("ShootSpeed" in this case)
probably by pulling up bullet speed from WeaponsINI, instead of using real time bullet speed data like in your current code.
ShootSpeed:=sqrt((Map.Bullets[BulletId].VelX*Map.Bullets[BulletId].VelX)+(Map.Bullets[BulletId].VelY*Map.Bullets[BulletId].VelY));
« Last Edit: June 27, 2017, 04:58:35 am by NiCeShOoT|GuY »

Offline soldat-game

  • Camper
  • ***
  • Posts: 407
Re: Sometimes the damage is different than it should be?
« Reply #3 on: June 27, 2017, 02:54:29 am »
LOL, But it must be the speed of the bullet at the moment of the hit. This allows you to determine what damage a player has committed and based on where the player hit.

Offline soldat-game

  • Camper
  • ***
  • Posts: 407
Re: Sometimes the damage is different than it should be?
« Reply #4 on: June 27, 2017, 03:51:36 am »
Im use, seems to work, for sure you could always be too round real2.
But anyway I want to find out what the dev has broken that is the divergence of the calculation!
Code: [Select]
function RealDMG(nonreal:single):single;
var real,real2:string;
begin
real := floattostr(nonreal);
real2 := Copy(GetPiece(real,'.',1),1,2);
Result:=strtofloat(GetPiece(real,'.',0)+'.'+real2);
end;