Author Topic: OnPlayerRespawn and player coordanates --SOLVED--  (Read 973 times)

0 Members and 1 Guest are viewing this topic.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
OnPlayerRespawn and player coordanates --SOLVED--
« on: May 18, 2009, 03:18:55 am »
I am making an anti spawner script but I have run into a snag, when you call getplayerstat(-,'[x,y]') onplayerrespawn it gets the x/y from where you died. Is there any way to get around this? I know I could sleep() for like 1 MS but it is my understanding that this would cause instability.

EDIT: Just tried Sleep and it does not work.

Thank you.
« Last Edit: May 18, 2009, 07:24:16 pm by Hacktank »


Offline tk

  • Soldier
  • **
  • Posts: 235
Re: OnPlayerRespawn and player coordanates
« Reply #1 on: May 18, 2009, 03:38:45 am »
Quote
const
  Max_Players = 16;
var
  s: array [1..Max_Players] of boolean;

OnPlayerRespawn(id: byte);
begin
  s[id]:=true;
end;

AppOnIdle(ticks: cardinal);
var i: byte;
begin
  for i:=1 to Max_Players do
    if s[ i] then
    begin
      s[ i]:=false;
      //GetPlayerXY, etc...
    end;
end;
Not tested

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: OnPlayerRespawn and player coordanates
« Reply #2 on: May 18, 2009, 03:44:26 am »
Yes, I thought of that but one can move a good distance in a second, but if I dont have another viable solution by tommarow then ill use that method.


Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: OnPlayerRespawn and player coordanates
« Reply #3 on: May 18, 2009, 03:57:07 am »
if you're making an antispawner script, can't you check the coordinates in onplayerdamage? And figure out how long ago the player spawned by comparing gettickcount() at respawn and on next damage right after that (with a flag boolean, etc etc you know what i mean)

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: OnPlayerRespawn and player coordanates
« Reply #4 on: May 18, 2009, 02:44:46 pm »
That is one thing it does, but it also is supposed to not count the spawn if the player is far enough away from where they spawned.


Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: OnPlayerRespawn and player coordanates
« Reply #5 on: May 18, 2009, 06:47:59 pm »
Code: [Select]
var
  AfterRespawn: array[1..32] of boolean;

procedure OnPlayerRespawn(Id: byte);
begin
  AfterRespawn[Id] := true;
end;

procedure AfterPlayerRespawn(Id: byte);
begin
  // Whatever you wanted to do
end;

procedure AppOnIdle(Ticks: cardinal);
var
  i: byte;
begin
  for i := 1 to 32 do
    if (AfterRespawn[i]) then begin
      AfterRespawn[i] := false;
      if (GetPlayerStat(i, 'Active') = true) then
        AfterPlayerRespawn(i);
    end;
end;

procedure OnWeaponChange(Id, Primary, Secondary: byte);
begin
  if (AfterRespawn[Id]) then begin
    AfterRespawn[Id] := false;
    AfterPlayerRespawn(Id);
  end;
end;
OnWeaponChange is called right after a player respawns, but just in case, you have AppOnIdle in there.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: OnPlayerRespawn and player coordanates
« Reply #6 on: May 18, 2009, 07:24:01 pm »
Code: [Select]
var
  AfterRespawn: array[1..32] of boolean;

procedure OnPlayerRespawn(Id: byte);
begin
  AfterRespawn[Id] := true;
end;

procedure AfterPlayerRespawn(Id: byte);
begin
  // Whatever you wanted to do
end;

procedure AppOnIdle(Ticks: cardinal);
var
  i: byte;
begin
  for i := 1 to 32 do
    if (AfterRespawn[i]) then begin
      AfterRespawn[i] := false;
      if (GetPlayerStat(i, 'Active') = true) then
        AfterPlayerRespawn(i);
    end;
end;

procedure OnWeaponChange(Id, Primary, Secondary: byte);
begin
  if (AfterRespawn[Id]) then begin
    AfterRespawn[Id] := false;
    AfterPlayerRespawn(Id);
  end;
end;
OnWeaponChange is called right after a player respawns, but just in case, you have AppOnIdle in there.
Cool, thanks Dorkey. I will put it into 1.1 of my script later. SOLVED


Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: OnPlayerRespawn and player coordanates --SOLVED--
« Reply #7 on: May 19, 2009, 02:43:37 am »
isn't that exactly what tk suggested? |:`

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: OnPlayerRespawn and player coordanates --SOLVED--
« Reply #8 on: May 19, 2009, 05:23:42 am »
isn't that exactly what tk suggested? |:`
If you look closer, mine also uses OnWeaponChange event, whereas tk's does not.