I always have to be difficult, here's my code. If you happen to notice why my messages aren't being sent or received ... or why they may not be translating correctly.
Rem Project: Multiplayer Testing
Rem Created: 2/11/2003 6:26:29 PM
Rem Creator: Tyler Drinkard
Rem ***** Main Source File *****
set display mode 800,600,16
hide mouse
#include "Camera.dba"
sync on
sync rate 40
load image "GrassTex.jpg",1
load image "GrassTex.jpg",2
load object "trunk.x",1
texture object 1,1
playerx#=0
playery#=5
playerz#=-10
make object sphere 2,5
make matrix 1, 100, 100, 10, 10
randomize matrix 1, 5
prepare matrix texture 1,2,1,1
fog on
fog distance 150
fog color RGB(200,200,200)
backdrop on
color backdrop RGB(200,200,200)
set camera range 1,155
set ambient light 100
`loop through matrix tiles
for xTile=0 to 9
for zTile=0 to 9
`set the matrix tile texture
`the texture is a random value
set matrix tile 1,xTile,zTile,1
next zTile
next xTile
update matrix 1
position object 2, playerx#,playery#,playerz#
xPos#=0
yPos#=5
zPos#=-10
xAng#=0
yAng#=0
zAng#=0
playerXang#=0
playerYang#=0
playerZang#=0
REM LOAD TREES
remstart
for trees=3 to 20
clone object 1, trees
texture object trees,1
TreeX# = Object position X (trees)
TreeZ# = Object position Z (trees)
TreeY# = get ground height (1,TreeX#,TreeZ#)
position object trees, rnd(1000), TreeY#, rnd(1000)
next trees
remend
Rem Camera Mode - First Person
CameraMode=0
gosub main_menu
main_menu:
`load menu image
load image "Menu.jpg",1000
set text size 12
blue=RGB(0,128,255)
white=RGB(255,255,255)
selectedItem=1
do
cls
paste image 1000,0,0
`print menu items
if selectedItem=1 then ink blue,0 else ink white,0
text 250,350,"Join Game"
if selectedItem=2 then ink blue,0 else ink white,0
text 350,350,"Host Game"
if selectedItem=3 then ink blue,0 else ink white,0
text 450,350,"Exit Game"
`select menu items
if leftkey()=1 and hold=0 then dec selectedItem : hold=1
if rightkey()=1 and hold=0 then inc selectedItem : hold=1
if leftkey()=0 and rightkey()=0 then hold=0
if selectedItem>3 then selectedItem=1
if selectedItem<1 then selectedITem=3
`decide what is selected
if returnkey()=1
`play game
if selectedItem=1
goto join
delete image 1000
endif
`display instructions
if selectedItem=2
goto host
delete image 1000
endif
`quit the game
if selectedItem=3
end
endif
endif
sync
loop
return
rem --------------------------- HOST COMMANDS ----------------------
host:
cls
set camera view 0,0,1,1
rem sample code to setup a net connection
perform checklist for net connections
nettotal=checklist quantity()
for a = 1 to nettotal
rem find the connection for TCP/IP internet
if checklist string$(a)="Internet TCP/IP Connection For DirectPlay" then netsel=a
next a
empty checklist
sync
input "Enter IP Address to broadcast(including periods): ";add$
print "Connecting ..."
sync
rem add$ is the IP address, example "127.0.0.1"
set net connection netsel,"omitted"
`add$
_playername:
input "Enter player name: ";playername$
if playername$ = "" then gosub _playername
create net game "T",playername$,4
empty checklist
do
packet$=playername$+"*"+str$(camera position x())+"*"+str$(camera position y())+"*"+str$(camera position z())+"*"+str$(camera angle x())+"*"+str$(camera angle y())+"*"+str$(camera angle z())
set camera view 0,0,800,600
gosub camera_control
rem get a list of all players
oldquant# = 1
perform checklist for net players
for i = 1 to checklist quantity()
name$=checklist string$(i)
text 10,10+(i*20),name$
next i
send net message string 0,packet$
rem search for new messages
keepgoing:
get net message
message$=net message string$()
rem ENTER WHATEVER YOU WANT TO DO WITH THE MESSAGE$ VARIABLE HERE
rem for this example, I'll just paste it to the screen
remstart
if message$>""
gotmessage$=message$
text 10,100,gotmessage$
remend
rem then check for any remaining messages
if net message exists()=1 then goto keepgoing
dim packet_split$(10)
dim packet_split#(10)
splitpos=1
for i=1 to len(message$)
if mid$(message$,i) = "*"
inc splitpos
packet_split$(splitpos)=""
else
packet_split$(splitpos)=packet_split$(splitpos) + mid$(message$,i)
endif
next i
packet_split#(2)=Val(packet_split$(2))
packet_split#(3)=Val(packet_split$(3))
packet_split#(4)=Val(packet_split$(4))
empty checklist
perform checklist for net players
if checklist quantity() > 1
if object exist(99)
position object 99, packet_split#(2),packet_split#(3),packet_split#(4)
else
make object sphere 99, 3
endif
endif
sync
loop
return
rem ---------------------------------- JOIN COMMANDS ---------------------------
join:
cls
set camera view 0,0,1,1
rem sample code to setup a net connection
perform checklist for net connections
nettotal=checklist quantity()
for a = 1 to nettotal
rem find the connection for TCP/IP internet
if checklist string$(a)="Internet TCP/IP Connection For DirectPlay" then netsel=a
next a
empty checklist
sync
input "Enter IP Address to connect to(including periods): ";add$
print "Connecting..."
sync
perform checklist for net sessions
rem add$ is the IP address, example "127.0.0.1"
set net connection netsel,"omitted"
`add$
playername:
input "Enter player name: "; playername$
if playername$ = "" then gosub playername
join net game 1, playername$
empty checklist
do
packet$=playername$+"*"+str$(camera position x())+"*"+str$(camera position y())+"*"+str$(camera position z())+"*"+str$(camera angle x())+"*"+str$(camera angle y())+"*"+str$(camera angle z())+"*"+ping$
set camera view 0,0,800,600
gosub camera_control
rem get a list of all players
oldquant# = 1
perform checklist for net players
for i = 1 to checklist quantity()
name$=checklist string$(i)
text 10,10+(i*20),name$
next i
send net message string 0,packet$
rem search for new messages
keepgoing:
get net message
message$=net message string$()
rem ENTER WHATEVER YOU WANT TO DO WITH THE MESSAGE$ VARIABLE HERE
rem for this example, I'll just paste it to the screen
remstart
if message$>""
gotmessage$=message$
text 10,100,gotmessage$
remend
rem then check for any remaining messages
if net message exists()=1 then goto keepgoing
dim packet_split$(10)
dim packet_split#(10)
splitpos=1
for i=1 to len(message$)
if mid$(message$,i) = "*"
inc splitpos
packet_split$(splitpos)=""
else
packet_split$(splitpos)=packet_split$(splitpos) + mid$(message$,i)
endif
next i
packet_split#(2)=Val(packet_split$(2))
packet_split#(3)=Val(packet_split$(3))
packet_split#(4)=Val(packet_split$(4))
empty checklist
perform checklist for net players
if checklist quantity() > 1
if object exist(99)
position object 99, packet_split#(2),packet_split#(3),packet_split#(4)
else
make object sphere 99,3
endif
endif
sync
loop
return
There are lines that are commented that look messy, but they are left overs from experiments. I'm working on a massive experimental project, that I plan on cleaning up later, but for now, I apologize and thank you.
Basic layout goes like this
o-Main Menu
-Host (gosub)
-Join (gosub)
Each sets up variables and connects first, then they send the messages (packet$) and last, translate recieved packages (message$)
I hope that helps you to understand a little ... Much thanks!
P.S. This is what the alphabet would look like if Q and R were eliminated.