ok, thank you! That helps a lot. Now i've (re) discovered BlitzPlay and I know its old and unsupported but so far so is Blitz3d.
BlitzPlay has met my needs and is working pretty well.
code:
Function GUI()
host=Input ("Host (1) or Join(0)")
FlushKeys
myname$=Input$ ("UserName= ")
FlushKeys
If host=1 Then ;HOST
My_Port=2222
If Not BP_HostSession(myname$,10,1,2222,10) ;maxplayer 10 !!!
RuntimeError "Could not Host game"
EndIf
SetupPlayer(myname$,My_Port)
Else If host=0 ;CLIENT
Print "Host Port=2222"
ip$=Input$ ("Host IP ?")
My_Port=Input$ ("Which port (3000,4000) ?")
Cls
Print "Connecting..."
Select BP_JoinSession(myname$,My_Port,ip$,2222)
Case BP_NOREPLY
RuntimeError "No Reply from host"
Case BP_IAMBANNED
RuntimeError "You have been banned from joining"
Case BP_GAMEISFULL
RuntimeError "Game is full"
Case BP_PORTNOTAVAILABLE
RuntimeError "Port: "+My_Port+" is not available"
Case BP_USERABORT
RuntimeError "Connection Attempt aborted"
End Select
;joining..
Print "Established Connection...."
SetupPlayer(myname$,My_Port)
EndIf
End Function
and the update network section:
frames=WaitTimer(tmr)
For k=1 To frames
BP_UpdateNetwork()
HandleMessages()
p.pl=First pl
x=EntityX(p\cam)
y=EntityY(p\cam)
z=EntityZ(p\cam)
UpdateGame() ;update everthing else
p.pl=First pl
msgtosend$="X"+EntityX(p\cam)
BP_UDPMessage(0,1,msgtosend$)
msgtosend$="Y"+EntityY(p\cam)
BP_UDPMessage(0,1,msgtosend$)
msgtosend$="Z"+EntityZ(p\cam)
BP_UDPMessage(0,1,msgtosend$)
Next
and the code in whole:
;weapon particles
Include "Particles/FireBullet.bb"
Include "Particles/Explosion_Rock.bb"
Include "Particles/World_Fire.bb"
Include "Particles/Explo_Wood.bb"
;Main includes
Include "Includes/LoadWorld.bb"
Include "includes/toolui_include.bb"
Include "includes/PyroParticleSystem.bb"
Include "Includes/CubeMap.bb"
Include "Includes\BPliteV1.14.bb"
TInit
my_game$="StealthRoom"
Global tmr=CreateTimer(40) ;fps timer
Global svrgame,wrtstrm,host,svrstrm,svrclnt,newx,newy,newz ;internet
EndGraphics
Type Info
Field txt$
End Type
;Stealthroom Framework
Graphics3D 800,600,32,2
SetBuffer BackBuffer()
;rhwn=WB3D_InitializeGUI(SystemProperty("RuntimeWindow"))
;B3D_HideGadget(rhwn)
TDesign 3
Global level,tmp_fireB,tmp_ex_norm,b_fire_snd,tmp_fire_torch,jump,tmp_fireC,sky
Const gravity#=5
;collisions
Const COL_FIREB=5
Collisions COL_FIREB,COLLISIONTYPE_BRUSH,2,1
SetupLoadWorld()
Type pl
Field cam,num,com,sel_wep$,list,lockmouse,h_prog,mark
Field ID,name$,port
End Type
Type wep_mark
Field spr,kind$
End Type
Type wep
Field ent
End Type
Type expl
Field emt,kind$,par
End Type
Type destr
Field hits,ent
End Type
;Weapon Types----
Type fire_b
Field emt,par
End Type
Type fire_c
Field emt,par
End Type
GUI()
FlushKeys
LoadSounds()
LoadLevel("maps\test3.b3d")
sky=LoadSky("night")
p.pl=First pl
x=EntityX(p\cam)
y=EntityY(p\cam)
z=EntityZ(p\cam)
Stop
p.pl=First pl
PositionEntity p\cam,0,4000,0
p.pl=First pl
x=EntityX(p\cam)
y=EntityY(p\cam)
z=EntityZ(p\cam)
Stop
While Not KeyDown(1)
UpdateNetwork()
p.pl=First pl
x=EntityX(p\cam)
y=EntityY(p\cam)
z=EntityZ(p\cam)
Stop
Cls
TUI
UpdateCubeMaps()
p.pl=First pl:PyroUpdate(p\cam)
UpdateWorld
RenderWorld
Color 255,255,255
Text 0,0,"Jumping: "+jump
Text 200,200,newx
Text 200,250,newy
Text 200,300,newz
Flip
Wend
PyroClear()
DeleteAllCubeMapObjects()
BP_EndSession()
End
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;FUNCTIONS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function LoadLevel(lev$)
AmbientLight 255,255,255
level=LoadWorld(lev$)
EntityPickMode level,2
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function UpdatePlayer(num)
For p.pl=Each pl
If p\num=num Then
If p\ID=BP_My_ID Then
;Camera controls
TranslateEntity p\cam,0,-gravity#,0
If p\lockmouse=1 Then
mx#=CurveValue(MouseXSpeed()*mousespeed,mx,camerasmoothness)
my#=CurveValue(MouseYSpeed()*mousespeed,my,camerasmoothness)
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
pitch#=EntityPitch(p\cam)
yaw#=EntityYaw(p\cam)
pitch=pitch+my
yaw=yaw-mx
If pitch>89 pitch=89
If pitch<-89 pitch=-89
RotateEntity p\cam,0,yaw,0
TurnEntity p\cam,pitch,0,0
EndIf
cx#=(KeyDown(32)-KeyDown(30))*cameraspeed
cz#=(KeyDown(17)-KeyDown(31))*cameraspeed
MoveEntity p\cam,cx,0,cz
If KeyHit(57) Then
If p\lockmouse=1 Then p\lockmouse=0:Return
If p\lockmouse=0 Then p\lockmouse=1:Return
EndIf
If jump=1 Then
For jumpcol=1 To CountCollisions(p\cam)
jumpcol_ent=CollisionEntity(p\cam,jumpcol)
If GetEntityType(jumpcol_ent)=COLLISIONTYPE_BRUSH Then
jump=0
EndIf
Next
TranslateEntity p\cam,0,cameraspeed*3,0
EndIf
If KeyHit(18) Then
If jump=0 Then jump=1
EndIf
UpdatePlayerWeapon(p\num)
UpdateCastedWeapons()
UpdateStaticWeapons()
EndIf
EndIf
Next
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function UpdatePlayerWeapon(num)
For p.pl=Each pl
If p\ID=BP_My_ID Then
If p\num=num Then
Select TItemGet$(TGadgetGet$(p\com,t_selected))
Case "Fire Bullet"
If MouseHit(1) Then
PlaySound b_fire_snd
f.fire_b=New fire_b
; f\par=
f\emt=PyroEmitterNew(CreateFireBullet())
RotateEntity f\emt,EntityPitch(p\cam),EntityYaw(p\cam),EntityZ(p\cam)
PositionEntity f\emt,EntityX(p\cam),EntityY(p\cam),EntityZ(p\cam)
EntityType f\emt,COL_FIREB
EndIf
Case "Fire Column"
If MouseHit(1) Then
PlaySound b_fire_snd
fc.fire_c=New fire_c
fc\emt=CreateCube()
RotateEntity fc\emt,EntityPitch(p\cam),EntityYaw(p\cam),EntityZ(p\cam)
PositionEntity fc\emt,EntityX(p\cam),EntityY(p\cam),EntityZ(p\cam)
;SetEmitter(fc\emt,tmp_fireC) ----------------------------------------------------
;EntityType fc\emt,COL_FIREB
EndIf
End Select
EndIf
EndIf
Next
UpdateHeldWeapon()
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
Function UpdateLevel()
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function SetupPlayer(name$,port)
p.pl=New pl
p\cam=CreateCamera()
CameraRange p\cam,1,40000
p\num=1
p\lockmouse=1
EntityType p\cam,COLLISIONTYPE_PLAYER
EntityRadius p\cam,32
;create combo weapon box
p\com=TComboBox(0,10,10,130,25)
p\list=TListNew()
TItemNew(p\list,"--Magic--")
TItemNew(p\list,"Fire Bullet")
TItemNew(p\list,"Fire Column")
TItemNew(p\list,"new item")
TItemNew(p\list,"new item")
TItemNew(p\list,"--Weapons--")
TGadgetSet(p\com,t_list,p\list)
TGadgetSet(p\com,t_value,1)
p\h_prog=TProgress(0,10,GraphicsHeight()-50,150,30)
TGadgetSet p\h_prog,t_value,.5
p\name$=name$
p\port=port
p\ID=BP_My_ID
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function UpdateCastedWeapons()
For f.fire_b=Each fire_b
MoveEntity f\emt,0,0,5
For colfireb=1 To CountCollisions(f\emt)
colfireb_ent=CollisionEntity(f\emt,colfireb)
For d.destr=Each destr
If colfireb_ent=d\ent Then
FreeEntity d\ent
CreateExplosion("wood",f\emt)
PyroEmitterDelete(f\emt,True):Delete f:Return
EndIf
Next
If GetEntityType(colfireb_ent)=COLLISIONTYPE_BRUSH
CreateExplosion("rock",f\emt)
PyroEmitterDelete(f\emt,True):Delete f:Return
EndIf
Next
Next
;;;;;;;;;;
For fc.fire_c=Each fire_c
TurnEntity fc\emt,0,5,0
Next
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function CreateExplosion(kind$,ent)
e.expl=New expl
e\kind$=kind$
Select e\kind$
Case "rock"
e\emt=PyroEmitterNew(CreateExplo_Rock())
Case "wood"
e\emt=PyroEmitterNew(CreateExplo_wood())
End Select
PositionEntity e\emt,EntityX(ent),EntityY(ent),EntityZ(ent)
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function UpdateExplosions() ;FIRST COMMAND CALLED
For e.expl=Each expl
PyroEmitterDelete(e\emt,False)
Delete e
Return
Next
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function LoadSounds()
;weapon sounds
b_fire_snd=LoadSound("Media/scifi002.wav")
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function UpdateStaticWeapons()
For w.wep_mark=Each wep_mark
TurnEntity w\spr,0,20,0
For p.pl=Each pl
If CameraPick(p\cam,MouseX(),MouseY())=w\spr
If MouseHit(1) Then PickupWeapon(w\kind$):DeleteCubeMapObject(w\spr):FreeEntity w\spr:Delete w
EndIf
Next
Next
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function PickupWeapon(kind$)
Select kind$
Case "stick"
For p.pl=Each pl
we.wep=New wep
we\ent=LoadAnimMesh("media/stick.b3d") ;anim 0 - all
ExtractAnimSeq we\ent,1,9 ;anim 1 - attack
ExtractAnimSeq we\ent,10,16 ;anim 2 - block
RotateEntity we\ent,EntityPitch(p\cam),EntityYaw(p\cam),EntityRoll(p\cam)
PositionEntity we\ent,EntityX(p\cam)+2,EntityY(p\cam),EntityZ(p\cam)+20
EntityParent we\ent,p\cam
ScaleEntity we\ent,1,1,1
tempb=LoadMaterialBrush("media/brush_wood.b3d")
PaintEntity we\ent,tempb
FreeBrush tempb
Next
End Select
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function UpdateHeldWeapon()
For we.wep=Each wep
If MouseHit(2)
Animate we\ent,3,1,1
EndIf
If MouseHit(3)
Animate we\ent,3,1,2
EndIf
Next
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function LoadMaterialBrush(file$,flags=0,u_scale=1,v_scale=1)
p=Instr(file,".")
ext$=Lower(Right(file,Len(file)-p))
Select ext
Case "jpg","jpeg","bmp","png","tga"
t=LoadTexture(file,flags)
If t
ScaleTexture t,u_scale,v_scale
b=CreateBrush()
BrushTexture b,t
FreeTexture t
Return b
EndIf
Case "b3d"
m=LoadMesh(file)
If m
If CountSurfaces(m)
surf=GetSurface(m,1)
b=GetSurfaceBrush(surf)
FreeEntity m
Return b
EndIf
Else
RuntimeError ".b3d Brush does not Exist!"
EndIf
End Select
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function LoadSky(kind$)
Select kind$
Case "day"
skymesh=LoadMesh("skies/skydome.b3d")
ScaleEntity skymesh,5000,5000,5000
skytex=LoadTexture("skies/domes/SB_dome_1.png")
EntityTexture skymesh,skytex
Case "night"
skymesh=LoadMesh("skies/skydome.b3d")
ScaleEntity skymesh,5000,5000,5000
skytex=LoadTexture("skies/domes/SB_dome_2.png")
EntityTexture skymesh,skytex
Case "galaxy01"
skymesh=LoadMesh("skies/galaxy.b3d")
ScaleEntity skymesh,5000,5000,5000
skytex=LoadTexture("skies/galaxys/galaxy_1.png")
EntityTexture skymesh,skytex
End Select
Return skymesh
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function GUI()
host=Input ("Host (1) or Join(0)")
FlushKeys
myname$=Input$ ("UserName= ")
FlushKeys
If host=1 Then ;HOST
My_Port=2222
If Not BP_HostSession(myname$,10,1,2222,10) ;maxplayer 10 !!!
RuntimeError "Could not Host game"
EndIf
SetupPlayer(myname$,My_Port)
Else If host=0 ;CLIENT
Print "Host Port=2222"
ip$=Input$ ("Host IP ?")
My_Port=Input$ ("Which port (3000,4000) ?")
Cls
Print "Connecting..."
Select BP_JoinSession(myname$,My_Port,ip$,2222)
Case BP_NOREPLY
RuntimeError "No Reply from host"
Case BP_IAMBANNED
RuntimeError "You have been banned from joining"
Case BP_GAMEISFULL
RuntimeError "Game is full"
Case BP_PORTNOTAVAILABLE
RuntimeError "Port: "+My_Port+" is not available"
Case BP_USERABORT
RuntimeError "Connection Attempt aborted"
End Select
;joining..
Print "Established Connection...."
SetupPlayer(myname$,My_Port)
EndIf
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function Chat()
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function UpdateNetWork()
frames=WaitTimer(tmr)
For k=1 To frames
BP_UpdateNetwork()
HandleMessages()
p.pl=First pl
x=EntityX(p\cam)
y=EntityY(p\cam)
z=EntityZ(p\cam)
UpdateGame() ;update everthing else
p.pl=First pl
msgtosend$="X"+EntityX(p\cam)
BP_UDPMessage(0,1,msgtosend$)
msgtosend$="Y"+EntityY(p\cam)
BP_UDPMessage(0,1,msgtosend$)
msgtosend$="Z"+EntityZ(p\cam)
BP_UDPMessage(0,1,msgtosend$)
Next
End Function
Function UpdateGame()
UpdateExplosions()
For p.pl=Each pl:UpdatePlayer(p\num):Next
UpdateLevel()
End Function
Function HandleMessages()
For msg.MsgInfo=Each MsgInfo
Select msg\msgtype
Case 255 ;new player
SetupExternalPlayer(msg\msgData,msg\msgFrom)
Case 254 ;player left
p.pl=Find_pdata(msg\msgFrom)
If p=Null Then Delete p
Case 253 ;host disconnects
For p.pl=Each pl
If p\ID<>BP_My_ID Then Delete p
Next
RuntimeError "Host Ended the game"
Case 252 ;someone got kicked
p.pl=Find_pdata(msg\msgfrom)
If p\ID=BP_My_ID Then
If msg\msgData=False Then RuntimeError "You have been kicked" Else RuntimeError "You have been banned"
For p.pl=Each pl
If p\ID<>BP_My_ID Then
Delete p
EndIf
Next
Else ;if it wasn't you
If msg\msgData=False Then Print "**"+p\name+" has been kicked!" Else Print("**"+p\name+" has been banned")
Delete p
EndIf
Case 1 ;position packet
coor$=msg\msgData
If Left(coor$,1)="X" Then newx=Replace(coor$,"X","")
If Left(coor$,1)="Y" Then newy=Replace(coor$,"Y","")
If Left(coor$,1)="Z" Then newz=Replace(coor$,"Z","")
p.pl=Find_pdata(msg\msgFrom)
If Not p\ID=BP_My_ID Then PositionEntity p\cam,newx,newy,newz
End Select
Delete msg
Next
End Function
Function SetupExternalPlayer(name$,ID)
p.pl=New pl
p\cam=CreateCube() ;The "Cam" is actually the marker for the other player
ScaleEntity p\cam,15,30,15
p\num=1
p\lockmouse=1
EntityType p\cam,COLLISIONTYPE_PLAYER
EntityRadius p\cam,32
p\name$=name$
p\ID=ID
End Function
Function Find_pdata.pl (ID)
For p.pl = Each pl
If p\ID = ID Then Return p
Next
End Function
It works fine for a while but after the client connects and go through about 5+ packet transfers it sets the location of the client player to 0,0,0. I think it may have lost connection with the client and assumed zero coordinates. This also happens automatically connected via multiple instances and 127.0.0.1.
Thanks for all your help!