How do I Create and destroy Multiplayer Objects for all Peer

Get help using Construct 2

Post » Fri Apr 17, 2015 7:11 pm

How do you handle creating and destroying objects for all peers? I've read that the host must create the object and destroy the object, I've tried this many different ways and no success.
B
10
S
1
Posts: 57
Reputation: 639

Post » Sat Apr 18, 2015 6:43 am

It depends on your method informing the peers of when objects need to be created.

For instance, using the sync object.
If you sync an object, and it gets created on the host, then it will automatically get created on the peers too.
If the host destroys this object, it will be destroyed on all connected peers too.

Using an in game event, for instance, a player joins.
When a peer connects, you could use that moment to create an object for that given peer (or something in the level, whatever your fancy), without the need of synching the object, seeing as all connected peers will have the same "peer connected" moment.
To have the object destroyed you would have to inform all connected peers through the host telling them a certain object needs destroying: see next examples

Using the synched input state: a peer shoots and informs everyone.
A peer presses a button to fire, setting a certain input state and this is relayed to the host by means of either a direct message, or based on the user input.
The host receives the input state from the peer, and based on this creates the bullet at the peer.
The input state goes for all peers, and all peer should create the bullet at the given peer based on the input state.
As for destroying, should the bullet hit some target, the target could set an input state of destroyed=1
All connected peers seeing the input state of the player who was hit, but the host destroys the object, and it gets destroyed on the other peers too. (synched object effect)


Using a message: relatively simple but effective
when a peer presses a button, it can simply send a message to a host, which relays it to the rest of the peers.


For example:

The host would process the following message from a peer AND broadcast it

tag "shoot"
message "bullet-100-100-360-400-peerid"

(bullet-x-y-angle-speed-peerid)

on tag shoot
tokenat(Multiplayer.Message, 0, "-") = "bullet"

create bullet at int(tokenat(Multiplayer.Message, 1, "-")) , int(tokenat(Multiplayer.Message, 2, "-")) on layer X
bullet set angle int(tokenat(Multiplayer.Message, 3, "-"))
bullet set speed int(tokenat(Multiplayer.Message, 4, "-"))
set bullet.peerid = tokenat(Multiplayer.Message, 5, "-")
Who dares wins
B
56
S
16
G
21
Posts: 1,875
Reputation: 19,406

Post » Sun Apr 19, 2015 6:20 am

Image

this is my current code for this problem, Something is still wrong because the peer can destroy the monster on the host screen but will not destroy on its own screen
B
10
S
1
Posts: 57
Reputation: 639


Return to How do I....?

Who is online

Users browsing this forum: Particle games and 7 guests