Jump to content


Photo

Sending sprite to the server?


  • Please log in to reply
3 replies to this topic

#1 Psalms23

Psalms23

    GMC Member

  • New Member
  • 163 posts

Posted 11 March 2012 - 10:52 AM

Here's the engine: http://www.host-a.ne...xample_v3.1.zip

I'm using a platform example which I believe is based on "Brod's platform example". It's an online platformer with 39dll.

One thing I'm stuck on is sending an instance's current sprite to the server, so the server can send that information to all the clients and they can see each player's current sprite.

I know it's not effective to put this in the step event, so I want to put it in the event of the player selecting a new sprite (for example when he clicks a new sprite, I want to execute a script to update his sprite on the server and send it back to all the clients.)

I'm not sure which script to execute. Anyone got a script or tip on this?

Thanks

Edit: added the engine: http://www.host-a.ne...xample_v3.1.zip

Press "1" "2" or "3" to change your player's sprite... But how can I update this change on the other client's screens?

Edited by Psalms23, 11 March 2012 - 11:08 AM.

  • 0

#2 Norrox

Norrox

    GMC Member

  • GMC Member
  • 140 posts
  • Version:Unknown

Posted 11 March 2012 - 12:53 PM

i dont know what kind of client / server setup you are using becaus im to lazy to check :P
but here is an theory
player creation
send message containing
playersprite = 1

server forwarding the creation to all other players

players create an object and checks the following
if playersprite == 1 then use this black sprite
else if playersprite == 2 then use this red sprite
else if playerspruite == 3 then use this blue sprite


ah well hope you understand what i mean ;P

edit:
same goes for the updating of the sprite

Edited by Norrox, 11 March 2012 - 12:54 PM.

  • 0

#3 Psalms23

Psalms23

    GMC Member

  • New Member
  • 163 posts

Posted 11 March 2012 - 02:12 PM

Thanks for the feedback.. so should something like this go in the "begin step" section of the server events?
if playersprite == 1
{
clearbuffer()
writebyte(var_sprite)
writestring(sprite=1)
send_client("all")
}

  • 0

#4 Norrox

Norrox

    GMC Member

  • GMC Member
  • 140 posts
  • Version:Unknown

Posted 11 March 2012 - 07:58 PM

Thanks for the feedback.. so should something like this go in the "begin step" section of the server events?

if playersprite == 1
{
clearbuffer()
writebyte(var_sprite)
writestring(sprite=1)
send_client("all")
}


you dont need to check playersprite on the server.
in the message the client send to the server when it's being created you send the integer value of playersprite to the server
when the server recieves it ( i guess there is a loop in the server that checks all the messages it receives )
the same message that receives that info whuld be the one that sends the new player create message to all the clients so in that message

server step event
lots of server code.....
switch message_id
{
	case 1: //the message id is 1
	{
		clearbuffer()		writebyte(2) // this will be the ID number of the message
		writebyte(1) // this is the sprite that will be used
		send_client("all")
	break;
	}
}
lots of server code....



client step event

lots of client code.....
switch message_id
{
	case 2: //the message id is 2
	{
		var spr;
		spr = readbyte();
		if spr == 1
		{
			use this sprite
		}
		if spr == 2
		{
			use this sprite
		}
	break;
	}
}
lots of client code....

this is in no way a complete code, it is just so you can understand better how it MAY work, there is still alot needed to be coded for player arrays that store the players ID's and
can be called upon to identify the players and more.... hope u understand :D
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users