OK now i made a game where the host should be able to move a car and the other players just can watch him.
but if i test it with my freinds. They get into the server. At me there are many lags. And they get an error.
Anyone knows a solution?
Server:
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM Start
REM Check Account
Check_Account:
Open to Read 1,"Data_1.Memory"
read string 1,Playername_data$
Close File 1
If Playername_data$=""
Gosub Create_Account
Else
Playername$=Playername_data$
Gosub Create_Server
Endif
Return
REM Create Account
Create_Account:
Print "The program dosen´t found an account on your harddisc."
Print "So you have to create a new one."
Input "Just Type your Nickname here: ",Playername$
if file exist("Data_1.Memory")=1 then delete file "Data_1.Memory"
Open to Write 2,"Data_1.Memory"
Write String 2,Playername$
Close File 2
Print "The account has been created Succesfully. Press any Key to Continue"
Wait Key
Gosub Check_Account
REM Create Server
Create_Server:
Cls
result_create = net host(6)
if result_create=1
Gosub Game
Else
Print "The Game wasn`t able to create a server."
Print "Please press any key to quit."
Wait Key
End
Endif
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM Game
Game:
autocam off
Load Object "../media/car.x",10
Scale Object 10,2000,2000,2000
Yrotate Object 10,180
fix object pivot 10
loop object 10
Position Camera 0,500,0
Point camera 0,0,0
Do
Handle_Network()
Handle_Movement()
Send_Byte()
Loop
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
Function Handle_Network()
PlayerJoined = Net Player Joined()
if PlayerJoined > 0
Text 0,0, "Net player joined: "+str$(PlayerJoined)
Make Object Cube PlayerJoined+10,1
endif
PlayerLeft = Net Player Left()
if PlayerLeft > 0
Text 0,0, "Net player left: "+str$(PlayerLeft)
Delete Object PlayerLeft+10
endif
Endfunction
Function Handle_Movement()
If upkey()=1
Move Object 10,0.25
Endif
if leftkey()=1
Yrotate Object 10,object angle y(10)-0.25
Endif
if rightkey()=1
Yrotate Object 10,object angle y(10)+0.25
Endif
Endfunction
Function Send_Byte()
net put float Object Position x(10)
net put float Object Position z(10)
net put byte Object Angle y(10)
for x = 1 to 6
net send x
Next x
Endfunction
Client:
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM Start
REM Check Account
Check_Account:
Open to Read 1,"Data_1.Memory"
read string 1,Playername_data$
Close File 1
If Playername_data$=""
Gosub Create_Account
Else
Playername$=Playername_data$
Gosub Join_Server
Endif
Return
REM Create Account
Create_Account:
Print "The program dosen´t found an account on your harddisc."
Print "So you have to create a new one."
Input "Just Type your Nickname here: ",Playername$
if file exist("Data_1.Memory")=1 then delete file "Data_1.Memory"
Open to Write 2,"Data_1.Memory"
Write String 2,Playername$
Close File 2
Print "The account has been created Succesfully. Press any Key to Continue"
Wait Key
Gosub Check_Account
REM Join Server
Join_Server:
Input "Please enter the server IP: ",ip$
Cls
result_join = net connect(ip$)
if join_create=1
Gosub Game
Else
Print "There isn´t running a server on this IP."
Print "Please press any key to repeat the last step."
wait key
gosub Join_Server
End
Endif
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM Game
Game:
autocam off
Load Object "../media/car.x",10
Scale Object 10,2000,2000,2000
Yrotate Object 10,180
fix object pivot 10
Position Camera 0,500,0
Point camera 0,0,0
Do
Handle_Network()
Get_Byte()
Loop
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
Function Handle_Network()
PlayerJoined = Net Player Joined()
if PlayerJoined > 0
Text 0,0, "Net player joined: "+str$(PlayerJoined)
Make Object Cube PlayerJoined+10,1
endif
PlayerLeft = Net Player Left()
if PlayerLeft > 0
Text 0,0, "Net player left: "+str$(PlayerLeft)
Delete Object PlayerLeft+10
endif
Endfunction
Function Handle_Movement()
If upkey()=1
Move Object 10,0.25
Endif
if leftkey()=1
Yrotate Object 10,object angle y(10)-0.25
Endif
if rightkey()=1
Yrotate Object 10,object angle y(10)+0.25
Endif
Endfunction
Function Get_Byte()
If net get message()
P1x = net get float()
p1z = net get float()
p1angle = net get byte()
Endif
position Object 10,P1x,0,P1z
Yrotate Object 10,P1angle
Endfunction