Hey guys I have been working on a little multiplayer fps. I got everything working except the mutiplayer part. So i am using multisync and i know hwo to create a conenction between the 2 computers. The part i need help with is actually having the players see each other movign around. Now with the native dpbro commands this would be easy but i dont undertsand how to do it with multisync. I read the multsync manual but it is very confusing.
Here is all of my code:
ReM Started by DGI : Owner Kuljot Dhami
mp5#=30
Input "Please Enter Your Name: ",playername$
cls
print "Ok ",playername$ : input "Press 1 if you would like to host or press 2 if you want to join: ",Choice$
if choice$="1"
Host=1
Print "You are hosting: ",playername$
input "Please Enter a Name for the Session: ",session$
result=net host(5)
endif
if choice$="2"
join=1
print "You Are Joining: ",playername
Input "Enter the I.P adress of your game ",IP$
result = net connect(ip$)
endif
load object "media\scud.x",10
scale object 10,1000,1000,1000
load image "media\scudlaun.dds",10
texture object 10,10
position object 10,2600,250,800
load object "tank.x",11
load image "tank2.dds",11
texture object 11,11
scale object 11,5000,5000,5000
position object 11,75,5,1778
load sound "media\click2.wav",5
Rem Project: level 2
Rem Created: 11/07/2009 20:41:09
Rem ***** Main Source File *****
rem set display mode 800,600,32
sync on : sync rate 65 : hide mouse
autocam off
rem backdrop off
makeLevel()
makePlayer()
global rtimer as integer
global stimer as integer
global vtimer as integer
rem player movement vector
global vx# as double float
global vy# as double float
global vz# as double float
global x# as double float
global oldy# as double float
global z# as double float
global runon# as double float : runon# = 60000000.0 : ` used for run instead of walk
global radius# as double float : radius# = 24.5 : ` size of player collision sphere
global fpsviewy# as double float
global gravity# as double float : gravity# = -.1
global slope# as double float : slope# = 0.5
global ground as integer : ground = 1
global jumptimer as integer : jumptimer = 0
load object "media/mp5.x",4
load sound "media\g1.wav",1
make object cube 103,5
make object cube 100,50
position object 100,1650,10,470
make object cube 101,50
position object 101, 40,10,60
make object cube 102,50
position object 102,100,10,100
scale object 4,9000,9000,9000
position object 4,110,10,160
load image "media\sas.dds",5
texture object 4,5
LOAD OBJECT "MP5.X",7
load object "mp5.x",8
position object 8,-904,20,1479
scale object 8,5000,5000,5000
position object 7,2653,249,727
ammo=80
clip=mp5#
scale object 7,5000,5000,5000
do
if object exist(7)=1
if object collision(2,7)=1 or object collision (2,8)=1
ammo=ammo+mp5#
delete object 7
sync
endif
endif
if ammo<1
reloadready=0
else
reloadready=1
endif
if clip<1
noammo=1
else
noammo=0
endif
text 0, 13, "There are "+str$(net get player amount())+" players connected."
result = net player joined()
if result >0
if object exist(23)=0
make object cube 23,100
position object 23,1000,24,100
endif
endif
TEXT 0,30,"Ammo: "+str$(Ammo)
TEXT 300,30,"clip: "+str$(clip)
ink rgb(255,0,0),1:set cursor 319,235:print "+" // punto de mira
movePlayer()
positionCameraToObject(2,0)
text 0,0,"FPS: "+str$(screen fps())
IF OBJECT COLLISION (2,4)=1
wield=1
wieldgunmp5()
endif
x=camera position x()
y=camera position y()
z=camera position z()
xt#=object position x(2)
yt#=object position y(2)
zt#=object position z(2)
if keystate(19)=1 and reloadready=1
reload=1
ammo=ammo-(mp5#-clip)
clip=mp5#
reload=0
endif
for i= 100 to 103
if intersect object(i,x,y,z,nx,ny,nz)>0
distancia#=intersect object(i,x,y,z+600,nx,ny,nz)
endif
next i
if noammo=1 and mouseclick()=1
if sound playing(1)=0
play sound 5
endif
endif
if mouseclick()=1 and sound playing(1)=0 and wield=1 and noammo=0
if mouseclick()=1
clip=clip-.20
move camera 2000
//camera position at the end of raycast
nx=camera position x()
ny=camera position y()
nz=camera position z()
endif
rem position object 1,camera position x(),camera position y(),camera position z()
play sound 1
endif
rem ----------------------------------------------------------------------------------------------------------------------------------
Rem shooting section
if ammo<0
ammo=0
endif
if keystate(15)=1
TEXT 0,40,"x Position: "+str$(xt#)
TEXT 0,50,"y Position: "+str$(yt#)
TEXT 0,60,"z Position: "+str$(zt#)
SYNC
endif
if mouseclick()=1
st=timer()
for i= 100 to 102
if intersect object(i,x,y,z,nx,ny,nz)>0
color object i,rgb(255,5,5)
PRINT "HIT OBJECT ",I-(100)
else color object i,rgb(255,255,255)
endif
next i
endif
`
SYNC
loop
function wieldgunmp5()
LOCK OBJECT ON 4
xrotate object 4,-25
wield=1
position object 4,2,-26.5,10
yrotate object 4,-3
endfunction
function makeLevel()
load object "media/map.x",1 : `load level
sc_setupComplexObject 1,1,2
position object 1,0,0,0 : `position level
sc_setupcomplexobject 11,0,2
endfunction
function makePlayer()
make object sphere 2,radius#
position object 2,23,0,32
sc_setupObject 2,0,1
hide object 2
rem player has no group
endfunction
function movePlayer()
rem rotate player with mouse
yrotate object 2,object angle y(2)+mousemovex()/3.0
xrotate object 2,object angle x(2)+mousemovey()/3.0
oldx# = object position x(2)
oldy# = object position y(2)
oldz# = object position z(2)
rem apply gravity, and user changes to movement
angy# = object angle y(2)
vx# = 0
vz# = 0
rem if player is jumping or falling then apply 'normal' gravity
rem if not attempt to keep the player stuck to the floor
if vy#=0 and jumptimer=0 then vy# = vy# + 10*gravity# else vy# = vy# + gravity#
if keystate(42)=1 then runon# = 20 else runon#= 5 : ` hold leftshift to run
if keystate(46)=1 then radius# = 15.0 else radius#= 24.5 : ` hold c to crouch
if keystate(32)=1 then vx# = vx# + cos(angy#)*runon# : vz# = vz# - sin(angy#)*runon#
if keystate(30)=1 then vx# = vx# - cos(angy#)*runon# : vz# = vz# + sin(angy#)*runon#
if keystate(31)=1 then vx# = vx# - sin(angy#)*runon# : vz# = vz# - cos(angy#)*runon#
if keystate(17)=1 then vx# = vx# + sin(angy#)*runon# : vz# = vz# + cos(angy#)*runon#
rem only jump if on ground, and a certain time after last jump
if ground=1
if spacekey()=1 and jumptimer=0 then vy# = vy# + 4.0 : jumptimer = 20
endif
rem this would be the player's final position without collision
x# = oldx#+vx#
y# = oldy#+vy#
z# = oldz#+vz#
rem first handle gravity - seperated from horizontal movement
rem to achieve a more realistic effect
rem Method: simple - cast a sphere vertically down, if it hits the level then
rem position the object there (sticky collision) then move
rem on to horizontal movement
rem more complex - if we were to only use the simple method the player would be
rem allowed to climb almost vertical slopes. Alternative is to
rem get the normalY direction to work out how flat the gorund
rem below the player is, 0-slope# is flatter, slope#-1 is steeper.
rem if it's flat, use sticky collision, if it's steep slide the
rem player down the slope. Changing slope# determines how steep the
rem player can climb. NOTE: this also effects stairs.
collide = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+vy#,oldz#,radius#,0)
if collide>0
rem how flat is this ground
ny# = sc_getCollisionNormalY()
if abs(ny#)>slope#
rem FLAT, stick
oldy# = sc_getStaticCollisionY()
else
rem STEEP, slide
x# = x# - oldx# : z# = z# - oldz#
oldx# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
oldz# = sc_getCollisionSlideZ()
x# = x# + oldx# : z# = z# + oldz#
endif
rem ny#<0 means the player has hit a ceiling rather than a floor
if ny#>slope#
rem only on ground if standing on flat ground
ground = 1
vy# = 0
else
ground = 0
rem if player has hit a flat ceiling then stop vy# movement
if ny#<-slope# then vy# = gravity#
endif
else
rem nothing below player, not on ground, add vertical speed to player
oldy# = oldy# + vy#
ground = 0
endif
rem jumptimer will decrease only when player is back on ground
rem creates a pause between two successive jumps
if ground = 1 and jumptimer>0 then dec jumptimer
rem handle horizontal movement as sliding
rem player only collides with group 1 (level) objs and moves freely through others
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,oldy#,z#,radius#,0)
if collide>0
rem if hit, reposition player, halt movement vector
x# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
vx# = 0
vz# = 0
rem possible code for giving the player a jumping help up stairs...
rem might be useful if slope# is set very high but stairs are still required
`dy# = oldy#-sc_getStaticCollisionY()
`if dy#<slope# and dy#>0 and ground=1 then vy# = 0.5
endif
rem position the player
position object 2,x#,oldy#,z#
rem position object 10,x#,oldy#,z# : ` position skysphere unrem if sky moves with player
sc_updateObject 2
endfunction
function positionCameraToObject(obj,thirdPerson)
fpsviewy#=object position y(2)+radius#: ` camera on top of sphere
position camera object position x(2),fpsviewy#,object position z(2)
rotate camera object angle x(2),object angle y(2),object angle z(2)
if thirdPerson=1
pitch camera down 10
move camera -30
endif
set camera range 1,50010 : ` gets rid of blue screen in distance
endfunction
if memblock exist(1) then delete memblock 1
The server and client will all be in 1 applciation. The program does detect the 2 computers conenctng to each other. Now i just need hlep with implanting the moving and seeign eacher other . If someone could give me examples of how to do this wiht multisync it would be great with explanations. thanks and my game with all media and code is attatched.
P.S. I made the map myself.
Gateway GT5628 Quad Core Desktop Intel Core 2 Q6600 2.4GHz Quad Core 3072MB RAM / 500GB 7200 SATA II Hard drive DVD RW 18X multi dual NVIDIA GeForce 8500GT ....