Quote: "though it's probably most important
if i could see your multiplayer code,"
Well, the thing is, even in the smallest project there is a fair amount of code to look through to see the multiplayer stuff

. I'll try and explain how its done..
First you need to start the connection, as either
the host or the client. Seeing as without the host no one can play,
we choose to host. We set the net connection to the first
setting (TCP/IP) and enter our local IP. Remember that using
a loopback address most likely won't work.
set net connection 1, "0.0.0.0"
Now we need to create the game (we are hosting, so we
create the game). The game name isnt particularly important.
create net game "Teh mmorpg", "Playername", 10
The first parameter is the game name, the second is the player
name, and the third is the maximum amount of players you want
in the game.
Afterwards we must check to see if connecting worked, so we
use a function built into dbpro to see if the net game exists:
if net game exists()=0 then print "FAILED" else print "SUCCESS"
After we have successfully started the game, others can connect
to the game.
During the game we'll want to see if someone has connected, so we
can either use PERFORM CHECKLIST FOR NET PLAYERS OR we can
call a different function, NET PLAYER CREATED():
newPlayerFlag = NET PLAYER CREATED()
if newPlayerFlag>0 then makeNewPlayerObject()
If there is a new player added, the function will return its local
ID, else it returns 0. We could do this a different way, by storing
the amount of players in a global variable and comparing it with
the checklist quantity each loop, like so:
perform checklist for net players
if checklist quantity()>playerAmount
inc PlayerAmount
makeNewPlayerObject()
endif
Now, sending messages is quite an easy process depending on what
kind of data you want to send. If you want to send object positions,
then you'll need to use a memblock, like so:
if memblock exist(1)=0 then make memblock 1,12
write memblock float 1,0,object position x(1)
write memblock float 1,4,object position y(1)
write memblock float 1,8,object position z(1)
send net message memblock 0,1
The first parameter of SEND NET MESSAGE MEMBLOCK is the player
number, but if 0 will send to all players but the sender.
You can optionaly specify a guarentee packet flag, which ensures
the message will get to the player(s). Remember that when sending
messages, only send the amount per second that you can, otherwise
somewhere a buffer will overflow, causing unimaginable lag. Because
I am on dialup I send 2 messages per second, which works fine for
me. Also, rather than sending a message based on how many frames
have passed, its best to use TIMER() to make sure you send messages
at precise time so that in-game lag won't affect message sending.
Receiving messages is more or less easy if you know what your
doing. Now, you can use NET MESSAGE EXIST() to see if there
is a new message in the queue, but I don't. I'm not sure if
checking or not affects program speed or error oppitunities(sp?)
however. First I use GET NET MESSAGE which brings the oldest
message and puts it as the current message, then we check
the type of the message. If it is a type we can do something with,
then we do as we wish with the message then carry on with the
rest of the program. If the message doesn't exist then the type
will be returned as 0, so as far as I know, if you're carefull
you shouldn't run into any problems. Here is an example:
if net message type()=4
playerFrom = net message player from()
net message memblock 2
x# = memblock float(2,0)
y# = memblock float(2,4)
z# = memblock float(2,8)
`now do whatever you want with the values
endif
So thats a basic outline for creating a multiplayer enabled game.
Doing the client code is very similar, but you use JOIN NET GAME
rather than HOST NET GAME, and depending on how you handle data
you make other changes accordingly.
There are more complex things that you encounter in a 3+ way p2p
game, such as making sure data gets sent to the right players,
but it isn't very difficult to figure out. Tell me if I missed
anything or made a mistake.
Now thats a long post isn't it