Author Topic: Simple question  (Read 746 times)

0 Members and 1 Guest are viewing this topic.

Offline VinceBros

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 275
Simple question
« on: May 19, 2009, 02:25:11 pm »
Ho-Hai Script0rz...
I was making a script and i need a procedure...
Which is when player drops the flag !
Is there a procedure like OnFlagDropped ? Something like this ?
Yes , No ?
Thanks =]

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Simple question
« Reply #1 on: May 19, 2009, 02:50:33 pm »
No, but what I would end up doing would be to apponidle, check if who has the flag; if that is not the player who had it before (whether it is from somebody to nobody or somebody to somebody else), then you can call your own event.


Offline VinceBros

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 275
Re: Simple question
« Reply #2 on: May 19, 2009, 07:52:41 pm »
Thanks Curt =D
...
But can you just tell me like a lil' something so i can start. Like how to do something like this =]
I tried alot and now i'm stucked ^^'

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Simple question
« Reply #3 on: May 19, 2009, 08:22:46 pm »
Code: [Select]
var hasflag: array[1..32] of boolean;

procedure ActivateServer();
var i: byte;
begin
for i := 1 to 32 do begin
   hasflag[i] := false
   end;
end;

procedure OnFlagDrop(ID: byte);
begin
//stuff here
end;

procedure AppOnIdle(Ticks: integer);
var i: byte;
begin
for i := 1 to 32 do begin
    if getplayerstat(i,'active') = true then begin
       if getplayerstat(i,'flagger') = true then hasflag[i] := true;
       if (getplayerstat(i,'flagger') = false) AND (hasflag[i] = true) then begin
          hasflag[i] := false
          OnFlagDrop(i);
          end;
       if getplayerstat(i,'flagger') = false then hasflag[i] := false;
       end;
    end
end;
(Not Tested)

Ther's your start. :)

EDIT: Eh. Dorkey's is better lol.
« Last Edit: May 19, 2009, 08:29:05 pm by Hacktank »


Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Simple question
« Reply #4 on: May 19, 2009, 08:26:52 pm »
Code: [Select]
var
  FlagHolders: array[1..2] of byte;

procedure OnFlagDropped(const Id, Flag: byte);
begin
// your OnFlagDropped event
end;

procedure AppOnIdle(Ticks: cardinal);
begin // or could do for i := 1 to 2 do but not too necessary when you want to call only 2 functions per each of the 2 iterations
  if (GetPlayerStat(FlagHolders[1], 'Flagger') = false) then begin // if the old alpha flag holder no longer has the flag
    OnFlagDropped(FlagHolders[1], 1);
    FlagHolders[1] := 0; // clear the alpha flag holder
  end;
  if (GetPlayerStat(FlagHolders[2], 'Flagger') = false) then begin
    OnFlagDropped(FlagHolders[2], 2);
    FlagHolders[2] := 0;
  end;
// other contents
end;

procedure OnFlagGrab(Id, TeamFlag: byte; GrabbedInBase: boolean);
begin // note OnFlagDropped will be called first if a person drops the flag, and picks it back up within a second (or less); if you need to use this function, put your stuff after this code
  if (FlagHolders[TeamFlag] <> 0) then // if there was an old flag holder (can be the same person)
    OnFlagDropped(FlagHolder[TeamFlag], TeamFlag);
  FlagHolder[TeamFlag] := Id; // set the new flag holder for the given team flag
// other contents
end;
Not tested. I may have missed something or scued it a bit.
Share your results.

EDIT:
Hacktank posted before I did, but imo my code has less loopyness and variables, therefore better (not bragging), if his works, it shouldn't be bad to use (considering it only has 1 loopy 1-32).
also I changed GetPlayerStat(Id, 'Flag') to GetPlayerStat(Id, 'Flagger')

EDIT2:
lol he commented back :P Thanks.

EDIT3:
note that OnFlagDrop isn't necessary accurate to the second... it can be at most 1 second off.
« Last Edit: May 19, 2009, 08:35:37 pm by DorkeyDear »

Offline VinceBros

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 275
Re: Simple question
« Reply #5 on: May 20, 2009, 03:30:27 pm »
Wow, thanks alot :O !
This will help me alot in my mode :D !
Thank to you both : Curt and HackTank =]