ID:1304770
 
(See the best response by FIREking.)
Problem description:So i want to be able to create multiple areas for my tournament system/duel system. So say if two people are in that area no one else can enter then it would search for the next area till it found an empty area. Would i say have to make a list for area area with a max number of people allowed in that list 2? Or would that be inefficient and stupid?

Code:
area/tournament/arena1

area/tournament/arena2


There's a number of ways to do this. None any more especially efficient than the last-
it's basically a matter of needs and preference.

You can use areas or you could not, you could closed off the arenas and change location of participants or allow them to walk in.

It's basically what feel you want the system to have.
Basicly i wanted it to come from a verb not from walking into a certain area.

for example

mob/verb/challenge()
var/arena
for(var/mob/M in players)
//challenge player
if(M.accepted)
if(!arena1inuse)
//set arena location arena1 location not sure how i would do this
M.loc = locate(arena)
else if(!arena2inuse)
//same as above
M.loc = locate(arena)


mob/var/tmp/accepted = 0


This all seems inefficient to me. But I'm not sure. Could be going about this totally wrong like I said.

I assume I could use Entered() to set if it was inuse or not but not too sure on that either.
area/tournament/arena1
var/tmp/list/participants = list()
var/tmp/max_participants = 2
Entered(mob/m)
if(ismob(m))
if(participants.len >= max_participants)
m << "max participants"
else
var/answer = input("Do you want to enter the arena?") as text in list("Yes", "No")
if(!answer || answer == "No") return
participants += m
if(participants.len >= max_participants)
max_participants_reached()
proc/max_participants_reached()
world << "you could make a match or a count down timer start here"
Thankyou FIREking this was most helpful. Could i possibly make the lists global vars so I could check max participants from the challenge?
In response to Rickoshay
Best response
Rickoshay wrote:
Thankyou FIREking this was most helpful. Could i possibly make the lists global vars so I could check max participants from the challenge?

Yeah, just move it out of the /area/tournament/arena1 define and all the code will still work but you'll need to empty the list when the participants leave

area/tournament/arena1
Exited(mob/m)
participants -= m //safe to do this without checking because if they aren't in the list nothing happens


Keep in mind this means you need to be a good programmer and never set loc directly, because that won't call Move() which won't call turf.Exit() which calls area.Exit() by default. So if there's anything that could cause the loc of the participants to be set directly while they're in a tournament, you'd need to prepare for that case scenario. A sloppy way would be a failsafe...

area/tournament
New()
..()
spawn check_participants()
proc/check_participants()
for(var/mob/m in participants)
if(!(locate(m) in src))
participants -= m
spawn(1000) check_participants()
Could i create an a part of the area map that have to walk to leave that area?

An example image here of what i mean http://gyazo.com/c66a6da35b7e14e37149c48cf577e6e1

Just got that second part after i posted this. Surprisingly that actually made sense to me. Once again thankyou so much.
When i took participants out of arena1 for some reason participants.len stopped working, any idea as to why? Sorry for being so much trouble.
In response to Rickoshay
Rickoshay wrote:
Could i create an a part of the area map that have to walk to leave that area?

An example image here of what i mean http://gyazo.com/c66a6da35b7e14e37149c48cf577e6e1

Just got that second part after i posted this. Surprisingly that actually made sense to me. Once again thankyou so much.

yeah just make an arena1_exit and set it to remove the participant on Entered() of that arena1_exit
In response to Rickoshay
Rickoshay wrote:
When i took participants out of arena1 for some reason participants.len stopped working, any idea as to why? Sorry for being so much trouble.

you need to make sure its the same name. Also make sure its defined as a list.
In response to FIREking
FIREking wrote:
you need to make sure its the same name. Also make sure its defined as a list.

Bit blind there, I missed out the list. Thank you so much for the advice. Think i've learnt more from you in the 10 minutes then I have in about 10 days.

No problem, good luck.