banimod / etpro / ettv forums Forum Index banimod / etpro / ettv forums
Bani's Discussion Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

random script

 
Post new topic   Reply to topic    banimod / etpro / ettv forums Forum Index -> ET Modding
View previous topic :: View next topic  
Author Message
crazyfrag



Joined: 01 Oct 2004
Posts: 105

PostPosted: Tue Jun 02, 2009 11:07 am    Post subject: random script Reply with quote

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
Back to top
View user's profile Send private message MSN Messenger
Father



Joined: 22 Jul 2006
Posts: 106
Location: Czech Republic

PostPosted: Tue Jun 02, 2009 6:09 pm    Post subject: Reply with quote

If you need random choice you can use math.random().
_________________
If you don't do it, someone else will.
Back to top
View user's profile Send private message Visit poster's website
crazyfrag



Joined: 01 Oct 2004
Posts: 105

PostPosted: Wed Jun 03, 2009 10:56 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message MSN Messenger
McSteve



Joined: 12 Sep 2006
Posts: 112

PostPosted: Wed Jun 03, 2009 12:00 pm    Post subject: Reply with quote

If not then (n+1)?
_________________
GhosT:McSteve
Ghostworks Gaming Community
Back to top
View user's profile Send private message
crazyfrag



Joined: 01 Oct 2004
Posts: 105

PostPosted: Wed Jun 03, 2009 12:13 pm    Post subject: Reply with quote

??
Back to top
View user's profile Send private message MSN Messenger
crazyfrag



Joined: 01 Oct 2004
Posts: 105

PostPosted: Wed Jun 03, 2009 12:30 pm    Post subject: Reply with quote

?? 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
Back to top
View user's profile Send private message MSN Messenger
Father



Joined: 22 Jul 2006
Posts: 106
Location: Czech Republic

PostPosted: Wed Jun 03, 2009 6:49 pm    Post subject: Reply with quote

The easiest way:

Code:

.
.

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:
    local random_slot = your_table[math.random(number_of_elements_in_table)]

_________________
If you don't do it, someone else will.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    banimod / etpro / ettv forums Forum Index -> ET Modding All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group