So I finally got my players to load the world, and we are moving right on to the next obstacle. I am trying to learn to control multiple players through loops and network messages.
moveplayer:
if startload = 6
for i = 1 to GetNetworkNumClients(NetworkID) //goes through all active players connected
if GetSpriteExists(player[i].sprite) = 0 //create my player's monkey if it doesnt exist
player[i].sprite = createsprite(monkey)
SetSpriteAnimation(player[i].sprite, 162, 114, 41)
playsprite(player[i].sprite)
if i <> 1 then player[i].it = 0
setspritephysicson(player[i].sprite, 2)
SetSpriteShape(player[i].sprite, 3)
setspritecolor(player[i].sprite, player[i].cRED, player[i].cGREEN, player[i].cBLUE, 255)
SetSpritePositionByOffset(player[i].sprite, 200, 200)
setspritephysicson(player[i].sprite, 2)
SetViewZoomMode(1)
SetViewZoom(.75)
endif
if i = GetNetworkMyClientID(NetworkID) //controlling my playerfor my player
if GetDirectionSpeed() > .2
player[i].speed = GetDirectionSpeed() * 100
player[i].speedx = (getdirectionx() * 10)
player[i].speedy = (GetDirectionY() * 10)
player[i].angle# = ATanFull(GetDirectionX(),GetDirectionY())
else
player[i].speed = 0
player[i].speedx = 0
player[i].speedy = 0
endif
player[i].x# = GetSpriteXByOffset(player[i].sprite)
player[i].y# = GetSpriteYByOffset(player[i].sprite)
SetSpritePositionByOffset(player[i].sprite, GetSpriteXByOffset(player[i].sprite)+ player[i].speedx, GetSpriteYByOffset(player[i].sprite) + player[i].speedy)
SetSpriteAngle(player[i].sprite, player[i].angle#)
SetSpriteSpeed(player[i].sprite, player[i].speed)
SetViewOffset(player[i].x# - (swidth / 2), player[i].y# - (sheight/2))
message = CreateNetworkMessage()
AddNetworkMessageinteger(message, player[i].x#)
AddNetworkMessageinteger(message, player[i].y#)
AddNetworkMessageInteger(message, player[i].angle#)
AddNetworkMessageFloat(message, player[i].speed)
AddNetworkMessageInteger(message, player[i].it)
SendNetworkMessage(NetworkID, 0, message)
endif
if i <> GetNetworkMyClientID(NetworkID)
if GetSpriteExists(player[i].sprite) = 1
message = GetNetworkMessage ( NetworkID )
while message <> 0
player[i].x# = GetNetworkMessageinteger ( message )
player[i].y# = GetNetworkMessageinteger ( message )
player[i].angle# = GetNetworkMessageInteger (message )
player[i].speed = GetNetworkMessageFloat(message)
player[i].it = GetNetworkMessageInteger( message)
setspritespeed(player[i].sprite, player[i].speed)
SetSpritePositionByOffset ( player[i].sprite, player[i].x#, player[i].y# )
if player[i].speed > .2
SetSpriteAngle(player[i].sprite, player[i].angle#)
endif
DeleteNetworkMessage ( message )
message = GetNetworkMessage ( NetworkID )
endwhile
endif
endif
It was working great, until players 3 and 4 joined. then there were just a bunch of ghosts running wild and players blinking. I think the messages received are going to all players, and not the respective players. Does anyone any idea of a good way to achieve this, or should i just make a giant batch of messages going through each player and send once? Thanks in advance for any help!
One smart fellow, he felt smart. Two smart fellows, both felt smart. Three smart fellows all felt smart...