Author Topic: OnPlayerDamage  (Read 1072 times)

0 Members and 1 Guest are viewing this topic.

Offline dominikkk26

  • Camper
  • ***
  • Posts: 404
    • PMGsite
OnPlayerDamage
« on: October 20, 2013, 01:44:52 pm »
Yo I've got some script and there is something wrong, however, start the script variables sometimes mixed with other functions shows buguja and are in working order.
The Annex gives the code.
Code: (passcal) [Select]
function OnPlayerDamage(Victim,Shooter: Byte;Damage: Integer): integer;
var
tmpDmg: double;
i: byte;
begin
for i := 1 to MAXPLAYER do
begin
tmpDmg:=Damage;
if(tmpDmg>=0)then begin
NDamage := Damage;
UpdateServStats();
UpdateNickname(GetPlayerStat(i,'name'),i);
if ShowDamage = 'true' then begin
if Language[Shooter] = 'EN' then WriteConsole(Shooter,'Victim: '+GetPlayerStat(Victim,'Name')+' Dmg = '+floattostr(tmpDmg),Good);
if Language[Victim] = 'EN' then WriteConsole(Victim,'Inflicting damage: '+GetPlayerStat(Shooter,'Name')+' Dmg = '+floattostr(tmpDmg),Bad);
if Language[Shooter] = 'PL' then WriteConsole(Shooter,'Ofiara: '+GetPlayerStat(Victim,'Name')+' Dmg = '+floattostr(tmpDmg),Good);
if Language[Victim] = 'PL' then WriteConsole(Victim,'Otrzymane obrarzenia: '+GetPlayerStat(Shooter,'Name')+' Dmg = '+floattostr(tmpDmg),Bad);
end;
NDamageZ[Shooter] := Round(tmpDmg);
NDamageO[Victim] := Round(tmpDmg);
UpdateNickname(GetPlayerStat(i,'name'),i);
if not NDamageZ[Shooter] = 0 then begin
NDamageZ[Shooter] := 0;
end;
if not NDamageO[Victim] = 0 then begin
NDamageO[Victim] := 0;
end;
end;
Result:=Round(tmpDmg);
end;
end;
« Last Edit: October 22, 2013, 04:01:50 pm by dominikkk26 »

Offline kicikici

  • Soldier
  • **
  • Posts: 180
Re: OnPlayerDamage
« Reply #1 on: October 20, 2013, 03:15:41 pm »
I wonder what is so important in function UpdateNickname(GetPlayerStat(i,'name'),i); that is called 2 times in each loop.
Also why all code in OnPlayerDamage is inserted in loop : for i := 1 to MAXPLAYER do when only one function UpdateNickname(GetPlayerStat(i,'name'),i); reffer to variable i.
I think that this things could cause problem - OnPlayerDamage is called a many many times and have a lot to do.
Classic banana

Offline dominikkk26

  • Camper
  • ***
  • Posts: 404
    • PMGsite
Re: OnPlayerDamage
« Reply #2 on: October 22, 2013, 09:22:13 am »
It just does not matter already checked.
The problem is that the variables in the mix
NDamageZ - damage done
NDamageO - damage incurred

I guess I wrote it wrong I wrote this renewal (code below)
Code: [Select]
var
tmpDmg: double;
MaxHealth, Otrzymane: integer;
begin
tmpDmg := Damage;
NDamage := Damage;
MaxHealth := iif(Command('/realistic')='1',65,150);
Otrzymane := MaxHealth-(Damage*100/MaxHealth);
UpdateServStats();
if (Victim <> Shooter) then begin
if Language[Shooter] = 'EN' then begin
if ShowDamage = 'true' then WriteConsole(Shooter,'Victim: '+GetPlayerStat(Victim,'Name')+' Dmg = '+floattostr(tmpDmg),Good);
NDamageZ[Shooter] := Round(tmpDmg);
if(GetPlayerStat(Shooter,'Active')=true) then begin
UpdateNickname(GetPlayerStat(Shooter,'name'),Shooter);
if not NDamageZ[Shooter] = 0 then NDamageZ[Shooter] := 0;
end;
end;
if Language[Victim] = 'EN' then begin
if ShowDamage = 'true' then WriteConsole(Victim,'Inflicting damage: '+GetPlayerStat(Shooter,'Name')+' Dmg = '+floattostr(tmpDmg),Bad);
NDamageO[Victim] := Otrzymane;
if(GetPlayerStat(Victim,'Active')=true) then begin
UpdateNickname(GetPlayerStat(Victim,'name'),Victim);
if not NDamageO[Victim] = 0 then NDamageO[Victim] := 0;
end;
end;
if Language[Shooter] = 'PL' then begin
if ShowDamage = 'true' then WriteConsole(Shooter,'Ofiara: '+GetPlayerStat(Victim,'Name')+' Dmg = '+floattostr(tmpDmg),Good);
NDamageZ[Shooter] := Round(tmpDmg);
if(GetPlayerStat(Shooter,'Active')=true) then begin
UpdateNickname(GetPlayerStat(Shooter,'name'),Shooter);
if not NDamageZ[Shooter] = 0 then NDamageZ[Shooter] := 0;
end;
end;
if Language[Victim] = 'PL' then begin
if ShowDamage = 'true' then WriteConsole(Victim,'Otrzymane obrarzenia: '+GetPlayerStat(Shooter,'Name')+' Dmg = '+floattostr(tmpDmg),Bad);
NDamageO[Victim] := Otrzymane;
if(GetPlayerStat(Victim,'Active')=true) then begin
UpdateNickname(GetPlayerStat(Victim,'name'),Victim);
if not NDamageO[Victim] = 0 then NDamageO[Victim] := 0;
end;
end;
end;
       Result:=Round(tmpDmg);
end;
« Last Edit: October 22, 2013, 09:25:20 am by dominikkk26 »

Offline kicikici

  • Soldier
  • **
  • Posts: 180
Re: OnPlayerDamage
« Reply #3 on: October 22, 2013, 11:28:15 am »
I would like to notice that it's a difference between
Code: [Select]
if not NDamageZ[Shooter] = 0 then NDamageZ[Shooter] := 0; and
Code: [Select]
if not (NDamageZ[Shooter] = 0) then NDamageZ[Shooter] := 0;.
I suggest replace
Code: [Select]
if not NDamageZ[Shooter] = 0 then NDamageZ[Shooter] := 0; this code:
Code: [Select]
NDamageZ[Shooter] := 0;
Classic banana

Offline dominikkk26

  • Camper
  • ***
  • Posts: 404
    • PMGsite
Re: OnPlayerDamage
« Reply #4 on: October 22, 2013, 04:01:34 pm »
WTF I would never expect that is just about the "(" ")".

Very Thanks!

Offline kicikici

  • Soldier
  • **
  • Posts: 180
Re: OnPlayerDamage
« Reply #5 on: October 23, 2013, 11:43:14 am »
No problem  :)
Classic banana