random script

Discussions about ET modding (sdk code, player/weapon modeling)

Moderators: Forum moderators, developers

Post Reply
crazyfrag
Posts: 105
Joined: Fri Oct 01, 2004 1:17 pm

random script

Post by crazyfrag »

is it possible to randomly choose a player that is on a server ? and how do i do this?

ty 4 ur help
regards crazy
User avatar
Father
Posts: 107
Joined: Sat Jul 22, 2006 1:30 pm
Location: Czech Republic
Contact:

Post by Father »

If you need random choice you can use math.random().
If you don't do it, someone else will.
crazyfrag
Posts: 105
Joined: Fri Oct 01, 2004 1:17 pm

Post by crazyfrag »

and how do i chooose the random player?

if i have privateslots (4 for example) how does he know from what number to what numer he is generating? if i have 4 guys on a server they may have slot numbers like 5 9 12 17 so if he chooses 10 theres no player...

i must return the mod if the slotnumber is not inuse and let him choose another number
how do i do this?
McSteve
Posts: 113
Joined: Tue Sep 12, 2006 7:41 am

Post by McSteve »

If not then (n+1)?
GhosT:McSteve
Ghostworks Gaming Community
crazyfrag
Posts: 105
Joined: Fri Oct 01, 2004 1:17 pm

Post by crazyfrag »

??
crazyfrag
Posts: 105
Joined: Fri Oct 01, 2004 1:17 pm

Post by crazyfrag »

?? u mean for 16 slot server


function randomslot(slotinuse)
slots= tonumber(et.trap_Cvar_Get( sv_maxclients) - 1)

slotinuse = math.random(0,slots)
if not et.gentity_get(slotinuse,"inuse") then
slotinuse = slotinuse + 1

return slotinuse
end
end
User avatar
Father
Posts: 107
Joined: Sat Jul 22, 2006 1:30 pm
Location: Czech Republic
Contact:

Post by Father »

The easiest way:

Code: Select all

.
.

local random_slot
repeat
  random_slot = math.random(0,slots)
until not et.gentity_get(random_slot,"inuse")

.
.

Better way:
  1. get numbers of slots in use
  2. put these numbers in table
  3. to get random:

    Code: Select all

    local random_slot = your_table[math.random(number_of_elements_in_table)]
If you don't do it, someone else will.
Post Reply