ID:261252
 
I want to make a multi player game, but I have no clue where to start. I only want two people to be in one game at a time, so how do I keep other people from joining after two people are already in? I know I have to make a var, but I don't know how to use it. I was thinking I could assign a var to the world, so when somone logs in, it changes to one, then when somone else logs in, it equals two, then when the world var equals two, it wont let other people join. Am I going about this wrong? If not, how do I give the world a var? And if so, what do I do?

Thank you,

-The Wizard of how-
________________
You're looking at this in the exact right way you make a world var by doing something like this:

var/something = 0//notice this is not attached to any other piece of code.
The Wizard of How wrote:
I want to make a multi player game, but I have no clue where to start. I only want two people to be in one game at a time, so how do I keep other people from joining after two people are already in? I know I have to make a var, but I don't know how to use it. I was thinking I could assign a var to the world, so when somone logs in, it changes to one, then when somone else logs in, it equals two, then when the world var equals two, it wont let other people join. Am I going about this wrong? If not, how do I give the world a var? And if so, what do I do?

Thank you,

-The Wizard of how-
________________

You've basically got the right idea, except that you don't actually assign the var under /world (which would be /world/var)--you just put it under /var. So your code might look something like this:
/world
//this is where the world's properties go

/var
//this is where you have global variables

/mob
//this is where you have your mob stuff

and so on. As for manipulating the variable, you'd probably want to use the client New() and (possibly) Del() procs, depending on how you want to set things up.
In response to Nadrew
I can make it so when somone logs in, the var equals 1, but I dont know how to make it add one when somone else logs in. Here's what I have;

mob
Login()
usr.loc = locate("MultiPlayer")
var/Multi = 1
if(Multi == 1)
icon = 'mob2.dmi'
//After that, I'm trying to make it so when somone else logs in, the var equals two, but I have no idea where to start. Can somone help?
In response to The Wizard of How
The Wizard of How wrote:
I can make it so when somone logs in, the var equals 1, but I dont know how to make it add one when somone else logs in. Here's what I have;

mob
Login()
usr.loc = locate("MultiPlayer")
var/Multi = 1
if(Multi == 1)
icon = 'mob2.dmi'
//After that, I'm trying to make it so when somone else logs in, the var equals two, but I have no idea where to start. Can somone help?

Actually...I think it would work better if you initialized the variable at 0 and then added one to it each time a player logged in... Also...I think it should be a world or mob variable rather than a variable of the Login() proc...

Like so...

mob
var
Multi = 0

Login()
usr.loc = locate("MultiPlayer")
Multi += 1 //(or "Multi++"...they accomplish the same task)
if(Multi == 1)
icon = 'mob2.dmi'
if(Multi == 2)
//Whatever code you devise that prevents the next player from joining the game


Please note that I too am still just in the learning stage...so my advice may not be the best/most reliable... But this should work...
In response to SuperSaiyanGokuX
Code wise not sure, you sound like you have a handle on it. But I'm notice there must be some code out there from the GM code I've seen arond where you can kick someone from your game. If Getoutofhere var = 2 then DumpNewppl()
That kind of thing, and it check this under
Login()

LJR