Author Topic: Problem with OnPlayerKill  (Read 1966 times)

0 Members and 3 Guests are viewing this topic.

Offline Runny

  • Major(1)
  • Posts: 11
Problem with OnPlayerKill
« on: December 23, 2009, 07:00:13 pm »
Hello!

As I've came back to Soldat, I've came back to scripting. I'm writing TTW-alike-mod. There are some professions, which you can change by using cmds. If player is alive, his profession will change as soon as he will die. I use OnPlayerKill event, to check wheter player was killed and wanted to change his profession - if he did, Program calls ChangeProfession function. It works in two ways - if player is dead it change his profession immediately, if he's alive it sends a variable, which is checked when OnPlayerEvent is called. I check if player is alive with GetPlayerStat(ID, 'alive'). And there's a problem. Player is actually alive when the OnPlayerKill event is called. Look at this code:
Code: [Select]
procedure OnPlayerKill(Killer, Victim: byte;Weapon: string);
begin
if GetPlayerStat(Victim,'alive') then Writeln('hehe');
end;
it prints 'hehe'. Is there a way, without using AppOnIdle, to solve my problem?

Hope you will understand me, I'm pretty tired

Merry Xmas ;)
« Last Edit: December 23, 2009, 07:02:21 pm by Runny »

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Problem with OnPlayerKill
« Reply #1 on: December 23, 2009, 11:50:36 pm »
Code: [Select]
procedure OnPlayerKill(Killer, Victim: byte;Weapon: string);
begin
Writeln('hehe');
end;


Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Problem with OnPlayerKill
« Reply #2 on: December 24, 2009, 12:22:33 am »
Victim is dead. GetPlayerStat is just behind when OnPlayerKill is called.
There is no need to check whether he's alive or not. He's dead.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Problem with OnPlayerKill
« Reply #3 on: December 24, 2009, 12:39:58 am »
Just a note: I had times which Victim is alive, and victim is dead when OnPlayerKill is called (had something to due with explosions) so it may become of use if you figure out specifically when its true or false.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Problem with OnPlayerKill
« Reply #4 on: December 24, 2009, 02:28:30 am »
Just a note: I had times which Victim is alive, and victim is dead when OnPlayerKill is called (had something to due with explosions) so it may become of use if you figure out specifically when its true or false.

Very interesting, this may solve my problem with M79/LAW. :D


Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Problem with OnPlayerKill
« Reply #5 on: December 24, 2009, 02:52:44 am »
Haha yes, that's an interesting thing. Found that while making Medic script(medics healed themselves after death because when player dies OnWeaponChange is called, the result was that every kill appeared as selfkill).
Use if GetPlayerStat(ID,'Health') > 0.
« Last Edit: December 24, 2009, 03:28:57 am by Gizd »

Offline Runny

  • Major(1)
  • Posts: 11
Re: Problem with OnPlayerKill
« Reply #6 on: December 24, 2009, 03:24:12 am »
Hm, I didn't describe my problem clear. Maybe I will just put a sketch-code instead:

Code: [Select]
procedure ChangeProfession(ID,option:byte);
begin

if GetPlayerStat(ID, 'alive') = false then
           begin
           Players[ID].profession := option;
           WriteConsole(ID,'Your profession has been changed!',$FF001122);
           end
else
           begin
           Players[ID].changeafterdead := true;
           Players[ID].changeto := option;
           WriteConsole(ID,'Your profession will be changed at the next respawn',$FF001122);
end;
end;

procedure OnPlayerKill(Killer, Victim: byte;Weapon: string);
begin
if Players[Victim].changeafterdead = true then begin
ChangeProfession(ID,Players[ID].changeto);
Players[Victim].changeafterdead := false;
Players[Victim].changeto := -1;
end;
end;

It's very shortened version of the code, but it shows my problem. Once player has joined the server, it keeps showing 'Your profession will be changed at the next respawn' msg, without changing the profession. You can change your profession successfully only when you are dead. OnPlayerKill is called properly, but then in ChangeProfession procedure, player's alive stat is always true...

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Problem with OnPlayerKill
« Reply #7 on: December 24, 2009, 03:29:20 am »
Use if GetPlayerStat(ID,'Health') > 0.
...instead of GetPlayerStat(ID,'Alive').

Offline Runny

  • Major(1)
  • Posts: 11
Re: Problem with OnPlayerKill
« Reply #8 on: December 24, 2009, 03:41:48 am »
Hmm, that's nice idea. Thanks :)

@edit:
It works. Thank you very much!
« Last Edit: December 24, 2009, 03:50:59 am by Runny »

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Problem with OnPlayerKill
« Reply #9 on: December 24, 2009, 07:14:30 pm »
Just a note: I had times which Victim is alive, and victim is dead when OnPlayerKill is called (had something to due with explosions) so it may become of use if you figure out specifically when its true or false.

Very interesting, this may solve my problem with M79/LAW. :D
Hm, I may have been thinking OnPlayerDamage, but it still might want to be looked into.. May also want to look into victim's health, it tends to be -400 OnPlayerDamage (but not always) for explosion (if I recall correctly).

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: Problem with OnPlayerKill
« Reply #10 on: December 25, 2009, 04:26:13 am »
You recalled it correctly, it was so interesting that I just go an tested it out with tons of bots :D
When the damage is negative its mostly -400 but not always.
Here a short part of the log i made with:
Quote
...
health: -139 Damage: 80
health: -400 Damage: 75
health: -219 Damage: 80
health: -400 Damage: 75
health: -400 Damage: 16566
health: -400 Damage: 82
health: -400 Damage: 292
health: -400 Damage: 82
health: -400 Damage: 139
health: -140 Damage: 80
health: -220 Damage: 48
health: -400 Damage: 82
health: -400 Damage: 18828
health: 150 Damage: 600
health: -400 Damage: 17908
health: 150 Damage: 48
health: -400 Damage: 18
health: -389 Damage: 23
health: -400 Damage: 46
health: -400 Damage: 72
health: 150 Damage: 50
health: 150 Damage: 55
health: -400 Damage: 20168
health: 150 Damage: 109
health: 150 Damage: 126
...



Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Problem with OnPlayerKill
« Reply #11 on: December 25, 2009, 09:30:51 pm »
@y0uRd34th: I think when its a direct explosion kill (M79 right in the face :D) its -400, but if its an indirect kill (such as explosion hitting a poly near a player) it is smaller.

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: Problem with OnPlayerKill
« Reply #12 on: December 26, 2009, 03:55:42 am »
Yes, but this wills till not solve scripters problem with the M79 explosion, but atleast this is an interesting tip.