simple multiplayer FPS

Blitz3D Forums/Blitz3D Beginners Area/simple multiplayer FPS

Ok, I understand the basics of both multiplayer and first-person-shooters. My question is, how do I combine them?

How do you send the positions of bullets ext.?

A realy simple example of this would be greatly appreciated!!!

There aren't too much in the way of simple examples, as it's not a particular simple concept. However, if you're into learning from other people's well-commented code (and if you're not, you should be), then here's an excellent example from the exceedingly generous Jeremy Alessi.

http://www.blitzbasic.com/codearcs/codearcs.php?code=1142

Thanks, I am sure that will help me out eventually, but right now I think that that is a littlebit too advanced for me. I know that this is not a simple consept, but surely there is more simple example out there, mabe one that just uses startnetgame instead of gnet?

Oh, and I tried that example and it says "Failed to Create Server" when I try to create my own game. When I try to join a game, it just sits there and doesn't do anything.

Why do the bullets not match up with the target if you aim different directions in this little example of mine?

http://www.freewebs.com/blitznerd/FPS/FPS.zip

Granted, that didn't work quite as well as it used to. Was a fun lil game too - not sure what changed, but the problems I'm having seem to be GNet-related... like the files it's looking for on the blitzbasic.com server are... in different places to where they were, or malformed... or something. Still, knowing that it worked fine means it's not unuseful for poring over to learn how to combine an FPS with netcode.

The thing is, there are plenty of examples around on how to do working netcode, and how to do FPSes. If you know how to do the FPS stuff, then adapting one of the 2D netcode methods should be (relatively) a doddle. If you aren't too comfortable with coding a 3D FPS but know all about netcode, then you have bigger fish to fry before you need to worry about adding network multiplayer.

Back to the code supplied though: I know it works (as I said, I've played it more than once), so if you just ignore all the GNet stuff (which only involves adding and listing servers from the remove masterserver, and none of the nitty gritty) then you'll find a great deal in there about how to "send the positions of bullets" etc.

You can also check out the netcode example that comes with BlitzPlay Lite (available here) - but again, you're going to have to study source code. This one doesn't involve GNet at all. Nor does the example netcode that comes with Blitz3D itself (in the command reference).

I have a sneaking suspicion though that there are probably a couple of things you could work on before you tackle implementing network multiplayer in an FPS.

Clicking on that link opens a copy of this thread (?)

I know, I don't know how to do links in this forum.??
If you copy and paste the url into your browser it should work.

This code runs very slow on my network. It has fine frames per second on both computers, but it takes about two minutes to register what happened on one computer on the other.
Does anybody know why it is so slow?
How can I make it faster?
StartNetGame()
name=Input("Name:")
id=CreateNetPlayer(name)
Graphics3D 640,480
SetBuffer BackBuffer()
target=LoadImage("target.bmp")
light=CreateLight()

ground=LoadTerrain("ground.bmp")
ScaleEntity ground,2,50,2
PositionEntity ground,-256,-75,-256
groundtex=LoadTexture("groundtex.bmp")
ScaleTexture groundtex,10,10
EntityTexture ground,groundtex
EntityType ground,2

guy=CreateCube()
PositionEntity guy,100,0,100
ScaleEntity guy,1,2,1
EntityRadius guy,1,4
EntityType guy,1
camera=CreateCamera(guy)
PositionEntity camera,EntityX(guy),EntityY(guy)+.5,EntityZ(guy)-1,1
PointEntity camera,guy
CameraClsColor camera,0,100,255
gravity#=0
health=100

otherguy=CreateCube()

Type youbullet
	Field mesh
	Field time
End Type

Collisions 1,2,2,2
Collisions 3,2,2,1
Collisions 3,6,1,1
Collisions 5,1,1,1

MoveMouse 200,200
While Not KeyDown(1)
mxs#=MouseXSpeed()
mys#=MouseYSpeed()
MoveMouse 200,200
TurnEntity guy,0,-mxs,0
TurnEntity camera,mys,0,0
If EntityCollided(guy,2)
	gravity=-.2
	If KeyDown(17) Then MoveEntity guy,0,0,.5
	If KeyDown(31) Then MoveEntity guy,0,0,-.5
	If KeyDown(32) Then MoveEntity guy,.5,0,0
	If KeyDown(30) Then MoveEntity guy,-.5,0,0
	TranslateEntity guy,0,gravity,0
Else
	gravity=gravity+(-1-gravity)/50
	TranslateEntity guy,0,gravity,0
EndIf
If MouseHit(1)
	b.youbullet=New youbullet
	b\mesh=CreateSphere()
	ScaleMesh b\mesh,.1,.1,.1
	b\time=300
	PositionEntity b\mesh,EntityX(camera,1),EntityY(camera,1),EntityZ(camera,1),1
	RotateEntity b\mesh,EntityPitch(camera,1),EntityYaw(camera,1),EntityRoll(camera,1),1
	EntityType b\mesh,3
	EntityRadius b\mesh,.1
EndIf

For b.youbullet=Each youbullet
	MoveEntity b\mesh,0,0,1
	TranslateEntity b\mesh,0,-.01,0
	If EntityCollided(b\mesh,2) Then b\time=0
	b\time=b\time-1
	If b\time<0
		FreeEntity b\mesh
		Delete b
	EndIf
Next
sendx$=LSet(EntityX(guy),10)
sendy$=LSet(EntityY(guy),10)
sendz$=LSet(EntityZ(guy),10)
sendpi$=LSet(EntityPitch(guy),10)
sendya$=LSet(EntityYaw(guy),10)
sendro$=LSet(EntityRoll(guy),10)
SendNetMsg(1,sendx+sendy+sendz+sendpi+sendya+sendro,id,0,0)
If RecvNetMsg()
	msg$=NetMsgData()
	PositionEntity otherguy,Left(msg,10),Mid(msg,11,20),Mid(msg,21,40)
	RotateEntity otherguy,Mid(msg,31,10),Mid(msg,41,10),Right(msg,10)
EndIf

If health<0 Then CameraClsColor camera,255,0,0

UpdateWorld
RenderWorld
Text 0,0,health
DrawImage target,(GraphicsWidth()/2)-32,(GraphicsHeight()/2)-32
Flip
Wend
End


Try adding Delay 1 at the start of your main loop.

Why does that help?

Ok, I tried that, and it goes a bit faster, but the network still slows down about 9 seconds per minute that the game runs. Any other usefull tricks?

I think that I am going to switch from DirectPlay to UDP. I have looked through some code and things and I think that I understand the basics of how to use UDP. There is one thing I am not sure about, is there a way to brodcast a UDP message? If not, then how do I get all of the participating players IP addresses?

A simpe fps exampe like the one that follows (that doesn't work, it is just to show you what I am after) would help me a LOT!!!
sendudpstream=CreateUDPStream()
recvudpstream=CreateUDPStream()

;set graphics

;load stuff

;main loop

message$=blablabla ; your message
WriteLine sendudpstream,message
SendUDPMsg sendudpstream,destip

recvmessage=RecvUDPMsg(recvudpstream)

;interpret the message

;end


hmmm this seams to work..


http://server.voidrpg.com/network test2.rar