Author Topic: [Request] Get Random Player in range xxx  (Read 1408 times)

0 Members and 1 Guest are viewing this topic.

Offline LORD KILLA

  • Camper
  • ***
  • Posts: 254
  • Happie
[Request] Get Random Player in range xxx
« on: July 04, 2009, 12:25:52 pm »
Hi all!
I am needing a function that returns a random player(as byte) in a specified range, i need that for some kinda autoshooting gun, but i have more shooters in one place and it would not look nice all shooting at one place(zombie) :-\
The guy who can help will be added to my Credits list on my zombie server ;)

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: [Request] Get Random Player in range xxx
« Reply #1 on: July 04, 2009, 12:35:22 pm »
http://forums.soldat.pl/index.php?topic=31798.0 could easily be modified to suit your needs. Just add in conditions you want to that iif in there.

Offline LORD KILLA

  • Camper
  • ***
  • Posts: 254
  • Happie
Re: [Request] Get Random Player in range xxx
« Reply #2 on: July 04, 2009, 12:39:31 pm »
Really very funny  :|
what i made (before i saw yours):
Code: [Select]
function RT (Player:byte;dst: single): byte;
var
dist: single;
begin
for i := 1 to 32 do begin
result[i] := 0;
if (GetPlayerStat(i, 'Active') = true) and (GetPlayerStat(i, 'team') = 2) and (RayCast(GetPlayerStat(i, 'x'), GetPlayerStat(i, 'y'), GetPlayerStat(player, 'x'), GetPlayerStat(player, 'y'), dist, dst) = true) then begin
lol := lol + 1;
result := i;
end;
end;
end;

procedure AppOnIdle(Ticks: integer);
begin
    for i := 1 to 32 do begin
        for j := 1 to 5 do begin
if DS[i].DS[j].Style = 1 then begin
tar := RT(i, 150);
realtar := tar[Random(1,GetArrayLength(tar))];
WriteLn('Target:' + inttostr(tar) + ' i:' + inttostr(i) + ' j:' + inttostr(j));
if realtar <> 0 then begin
Fire(GetPlayerStat(i, 'x'), GetPlayerStat(i, 'y'), GetPlayerStat(realtar, 'x'), GetPlayerStat(realtar, 'y'), 20, 40, 10, 20, i, 14);
end;
end else if DS[i].DS[j].Style = 2 then begin

end else if DS[i].DS[j].Style = 3 then begin

end else if DS[i].DS[j].Style = 4 then begin

end else if DS[i].DS[j].Style = 5 then begin

end;
end;
    end;
end;

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: [Request] Get Random Player in range xxx
« Reply #3 on: July 05, 2009, 02:44:35 pm »
a modified version of Avarax's NearestPlayer
Code: (Pascal) [Select]
function NearestHuman(X1,Y1: single; team,maxrange: integer; alive,human: boolean): integer;
var X2,Y2,temp: single;
    i: integer;
begin
  temp := maxrange;
  result := 0;
  for i := 1 to Max_ID do
    If (GetPlayerStat(i,'Active') = true) then
      if (GetPlayerStat(i,'Alive') = alive) and (GetPlayerStat(i,'Team') = team) and (GetPlayerStat(i,'Human') = human) then begin
        GetPlayerXY(i,X2,Y2);
        If (Distance(X1,Y1,X2,Y2) < temp) and (Distance(X1,Y1,X2,Y2) > 1) then begin
          temp := Distance(X1,Y1,X2,Y2);
          result := i;
        end;
      end;
end;
pass it "true" for "human" to get a player, "false" to get a bot


edit: put the tag to highlight syntax, aaawsum
« Last Edit: July 07, 2009, 08:06:21 am by danmer »

Offline LORD KILLA

  • Camper
  • ***
  • Posts: 254
  • Happie
Re: [Request] Get Random Player in range xxx
« Reply #4 on: July 06, 2009, 11:01:46 am »
ill try it out, thx

Edit: Dont works, still gets nearest palyer ...
« Last Edit: July 09, 2009, 09:45:13 am by LORD KILLA »

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: [Request] Get Random Player in range xxx
« Reply #5 on: July 11, 2009, 01:25:14 am »
Here you go, its not tested but it should work.

Code: [Select]
function RangePlayer(X1,Y1,X2,Y2,MinDist,MaxDist: single): byte;
// Returns a player ID that is within min and maxdist. if there isnt one it returns 0
var i: byte; cands: array of byte; dst: single;
begin
for i := 1 to 32 do if getplayerstat(i,'active')=true then begin
dst:=distance(X1,Y1,X2,Y2);
if (dst>=mindist) AND (dst<=maxdist) AND (getplayerstat(i,'alive')=true) then begin
setarraylength(cands,getarraylength(cands)+1);
cands[getarraylength(cands)-1] := i;
end
end
if getarraylength(cands)>1 then result := cands[random(0,getarraylength(cands)-1)] else result := 0
end;
« Last Edit: July 11, 2009, 01:27:08 am by Hacktank »


Offline LORD KILLA

  • Camper
  • ***
  • Posts: 254
  • Happie
Re: [Request] Get Random Player in range xxx
« Reply #6 on: July 12, 2009, 07:35:18 am »
I know, thats easy, i did it years ago, but get a RANDOM player?

Offline croat1gamer

  • Veteran
  • *****
  • Posts: 1327
  • OMG CHANGING AVATAR!!! ^ω^
Re: [Request] Get Random Player in range xxx
« Reply #7 on: July 12, 2009, 08:19:06 am »
Try this:
Code: [Select]
var a,b:integer;
begin
for a:= 1 to 1000000 do inc(b);
a:=random(10)+1; {this makes "a" a random number from 1 to 10}
writeln(a);
end.

Just implement it in the script.
Last year, I dreamt I was pissing at a restroom, but I missed the urinal and my penis exploded.

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: [Request] Get Random Player in range xxx
« Reply #8 on: July 12, 2009, 10:05:09 am »
I know, thats easy, i did it years ago, but get a RANDOM player?

have you even tried Hacktank's script? |:` It looks like exactly what you need

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: [Request] Get Random Player in range xxx
« Reply #9 on: July 12, 2009, 03:50:14 pm »
As danmer said, my function checks which players are within mindist and maxdist and picks a random one, and i just realized that it deesnt check teams. Team checking can easily be added tho.