Hi !!
I'm coding now the multiplayer part:
This is what I tried
This is the client screenshot and it's code:
set window on
set window position 50,50
set window title "Client"
join net game 1,"CLIENT"
rem Initial settings
sync on : sync rate 100
backdrop off : hide mouse
rem Select font
set text font "arial" : set text size 16
set text to bold : set text transparent
rem Loading prompt
sync : center text screen width()/2,screen height()/2,"LOADING" : sync
rem Load all media for game
gosub _load_game
rem Setup all objects for game
gosub _setup_game
rem Game loop
do
rem Control game elements
gosub _control_player
gosub _control_gunandbullet
gosub _control_enemies
rem Update screen
sync
rem End loop
loop
rem End program
end
_control_player:
rem Control player direction
rotate camera camera angle x(0)+(mousemovey()/2.0),camera angle y(0)+(mousemovex()/2.0),0
rem Control player movement
cx#=camera angle x(0) : cy#=camera angle y(0)
if upkey()=1 then xrotate camera 0,0 : move camera 0,0.2 : xrotate camera 0,cx#
if downkey()=1 then xrotate camera 0,0 : move camera 0,-0.2 : xrotate camera 0,cx#
if leftkey()=1 then yrotate camera 0,cy#-90 : move camera 0.2 : yrotate camera 0,cy#
if rightkey()=1 then yrotate camera 0,cy#+90 : move camera 0.2 : yrotate camera 0,cy#
if wrapvalue(camera angle x(0))>40 and wrapvalue(camera angle x(0))<180 then xrotate camera 0,40
if wrapvalue(camera angle x(0))>180 and wrapvalue(camera angle x(0))<280 then xrotate camera 0,280
rem Position listener at player for 3D sound
position listener camera position x(),camera position y(),camera position z()
rotate listener camera angle x(),camera angle y(),camera angle z()
rem In case of restart
if restart=1
restart=0
set bsp collision off 1
rotate camera 0,0,0
position camera 2,2,2
set bsp camera collision 1,0,0.75,0
endif
return
_control_gunandbullet:
rem Control gun firing
if mouseclick()=1 and bullet=-50
bullet=100
rem play sound GunSnd
position object BulletObj,camera position x(0),camera position y(0),camera position z(0)
rotate object BulletObj,camera angle x(0),camera angle y(0),0
set bsp object collision 2,BulletObj,0.1,1
move object BulletObj,0.1
endif
rem Control life of bullet
if bullet>0
rem If bullet collides with BSP world
if bsp collision hit(2)=1 or bulletimpact=1
rem End bullet on wall
rem position sound ImpactSnd,object position x(BulletObj), object position y(BulletObj), object position z(BulletObj)
rem play sound ImpactSnd
bulletimpact=0
bullet=0
else
rem Move bullet
dec bullet
move object BulletObj,0.5
endif
rem Bullet dies
if bullet=0
set bsp collision off 2
endif
else
rem Gun recharge phase
if bullet>-50 then dec bullet
endif
return
_control_enemies:
return
_control_stats:
return
_setup_game:
rem Setup camera
set camera range 0.1,5000
autocam off
rem Setup gun for player
lock object on GunObj
scale object GunObj,2,2,4
rotate object GunObj,270,0,0
position object GunObj,0.5,-1,2
disable object zdepth GunObj
rem Create object for bullet
BulletObj=3 : load object "grenade.mdl",BulletObj
scale object BulletObj,0.5,0.5,0.5
rem Create simple sprite based crosshair
sprite 1,320-16,240-16,CrossHairImg
set sprite 1,0,1
rem Trigger player initialisation
restart=1
return
_load_game:
rem Load BSP world and sky model
load bsp "test.pk3","test.bsp"
set bsp camera collision 1,0,0.75,0
set bsp collision threshhold 1,0.001
rem Load model for gun
GunObj=2 : load object "modelsgungun.x",GunObj
rem Load all sounds
rem GunSnd=1 : load sound "soundsgun.wav",GunSnd
rem ImpactSnd=2 : load 3dsound "soundsimpact.wav",ImpactSnd
DieSnd=3 : load sound "soundsdie.wav",DieSnd
load object "scientist.mdl",111
append object "scientist.mdl",111,1
rotate object 111,-90,0,0
position object 111,0,1.5,0
scale object 111,4,5,2.5
Speed=5+rnd(20)
play object 111,1,100
set object speed 111, Speed
rem Load images
FireImg=1 : load image "imagesfire.bmp",FireImg
CrossHairImg=2 : load image "imagescrosshair.bmp",CrossHairImg
return
This is the host screenshot and it's code:
set window on
set window position 50,50
set window title "host"
create net game "test1","HOST",2,1
rem Initial settings
sync on : sync rate 100
backdrop off : hide mouse
rem Select font
set text font "arial" : set text size 16
set text to bold : set text transparent
rem Loading prompt
sync : center text screen width()/2,screen height()/2,"LOADING" : sync
rem Load all media for game
gosub _load_game
rem Setup all objects for game
gosub _setup_game
rem Game loop
do
rem Control game elements
back:
cls
text screen width()/2,30,"WAITING FOR CLIENT TO COME..."
if net player created()>0
goto nextstep
endif
if escapekey()>0
end
endif
goto back
nextstep:
gosub _control_player
gosub _control_gunandbullet
gosub _control_enemies
rem Update screen
sync
rem End loop
loop
rem End program
end
_control_player:
rem Control player direction
rotate camera camera angle x(0)+(mousemovey()/2.0),camera angle y(0)+(mousemovex()/2.0),0
rem Control player movement
cx#=camera angle x(0) : cy#=camera angle y(0)
if upkey()=1 then xrotate camera 0,0 : move camera 0,0.2 : xrotate camera 0,cx#
if downkey()=1 then xrotate camera 0,0 : move camera 0,-0.2 : xrotate camera 0,cx#
if leftkey()=1 then yrotate camera 0,cy#-90 : move camera 0.2 : yrotate camera 0,cy#
if rightkey()=1 then yrotate camera 0,cy#+90 : move camera 0.2 : yrotate camera 0,cy#
if wrapvalue(camera angle x(0))>40 and wrapvalue(camera angle x(0))<180 then xrotate camera 0,40
if wrapvalue(camera angle x(0))>180 and wrapvalue(camera angle x(0))<280 then xrotate camera 0,280
rem Position listener at player for 3D sound
position listener camera position x(),camera position y(),camera position z()
rotate listener camera angle x(),camera angle y(),camera angle z()
rem In case of restart
if restart=1
restart=0
set bsp collision off 1
rotate camera 0,0,0
position camera 2,2,2
set bsp camera collision 1,0,0.75,0
endif
return
_control_gunandbullet:
rem Control gun firing
if mouseclick()=1 and bullet=-50
bullet=100
rem play sound GunSnd
position object BulletObj,camera position x(0),camera position y(0),camera position z(0)
rotate object BulletObj,camera angle x(0),camera angle y(0),0
set bsp object collision 2,BulletObj,0.1,1
move object BulletObj,0.1
endif
rem Control life of bullet
if bullet>0
rem If bullet collides with BSP world
if bsp collision hit(2)=1 or bulletimpact=1
rem End bullet on wall
position sound ImpactSnd,object position x(BulletObj), object position y(BulletObj), object position z(BulletObj)
play sound ImpactSnd
bulletimpact=0
bullet=0
else
rem Move bullet
dec bullet
move object BulletObj,0.5
endif
rem Bullet dies
if bullet=0
set bsp collision off 2
endif
else
rem Gun recharge phase
if bullet>-50 then dec bullet
endif
return
_control_enemies:
return
_control_stats:
return
_setup_game:
rem Setup camera
set camera range 0.1,5000
autocam off
rem Setup gun for player
lock object on GunObj
scale object GunObj,2,2,4
rotate object GunObj,270,0,0
position object GunObj,0.5,-1,2
disable object zdepth GunObj
rem Create object for bullet
BulletObj=3 : load object "grenade.mdl",BulletObj
scale object BulletObj,0.5,0.5,0.5
rem Create simple sprite based crosshair
sprite 1,320-16,240-16,CrossHairImg
set sprite 1,0,1
rem Trigger player initialisation
restart=1
return
_load_game:
rem Load BSP world and sky model
load bsp "test.pk3","test.bsp"
set bsp camera collision 1,0,0.75,0
set bsp collision threshhold 1,0.001
rem Load model for gun
GunObj=2 : load object "modelsgungun.x",GunObj
rem Load all sounds
GunSnd=1 : load sound "soundsgun.wav",GunSnd
ImpactSnd=2 : load 3dsound "soundsimpact.wav",ImpactSnd
DieSnd=3 : load sound "soundsdie.wav",DieSnd
load object "hgrunt.mdl",111
append object "hgrunt.mdl",111,1
rotate object 111,-90,0,0
position object 111,4,1.5,0
scale object 111,4,5,2.5
Speed=5+rnd(20)
play object 111,1,100
set object speed 111, Speed
rem Load images
FireImg=1 : load image "imagesfire.bmp",FireImg
CrossHairImg=2 : load image "imagescrosshair.bmp",CrossHairImg
return
make memblock 1,64
myx=object position x(1)
myy=object position y(1)
myz=object position z(1)
myax=object angle x(1)
myay=object angle y(1)
myaZ=object angle Z(1)
write memblock float 1,4,myx
write memblock float 1,8,myy
write memblock float 1,12,myz
write memblock float 1,16,myax
write memblock float 1,20,myay
write memblock float 1,24,myaz
send net message memblock 0,1,1
if memblock exist(1)=1 then delete memblock 1
get net message
if NET MESSAGE TYPE()=4
net message memblock 1
OtherX = memblock float(1,4)
OtherY = memblock float(1,8)
OtherZ = memblock float(1,12)
OtherAX = memblock float(1,16)
OtherAY = memblock float(1,20)
OtherAZ = memblock float(1,24)
position object 2,OtherX,OtherY,OtherZ
rotate object 2,OtherAX,OtherAY,OtherAZ
endif
if memblock exist(1)=1 then delete memblock 1
if net player destroyed()>0
goto back
endif
Please help me making player see each other !! by sending postions !
thanks !!