How do I use turrets behavior in a multiplayer game

Just started using Construct 2? Post your questions here

Post » Wed Oct 12, 2016 1:18 am

Hi,
I'm trying to make a multiplayer game. BTW I'm not using the multiplayer object. I'm using websocket.
Each player can create turrets. When a turret is created it should get another turret as target.
If I try to use a single sprite object for everyone 's turret (they look identical but I can use a simple text to see who "owns" a turret) and the event:
Code: Select all
Turret -> Add Target -> Turret

Turret does not make difference from "my" turret and "enemy" turret (also the turret will self target).

I can solve this by using two sprites objects; let say my turrets use the sprite "Turret" and enemy's turrets use the sprite "Enemy_turret".
So I can do:
Code: Select all
Turret -> Add Target -> Enemy_turret
Enemy_turret -> Add Target -> Turret


In this way my turrets should only target Enemy's Turrets and viceversa.

But what if I want to have an undeterminated number (or a max of 5) of players?
Should I clone all those sprites, events and condition? Is there (I think surely there is) a better way to do it?

BTW I have an instance var in each turret with the player ID. But I can't find a way to use this as filter.
Thank you!!!
B
12
S
5
Posts: 42
Reputation: 990

Post » Wed Oct 12, 2016 7:43 pm

Well with the instance variable and the palyer ID, you have basically all precomponents for a filter. :)
You still need the EnemyTurret and the - let's call him - PlayerTurret- sprites.
The sprites all look the same, but for every player, the own player is the PlayerTurret and the enemies are EnemyTurrets (yes, all the same).

The way you can differentiate the different EnemyTurrets is by their instance var "PlayerID".
You can target a specific enemy turret by putting a "Pick by comparison" condition before the target selection.

This would look like this:
Code: Select all
Pick "EnemyTurret" by comparison: [whatever player id turret you want to target] =equal to= EnemyTurret.PlayerID
      PlayerTurret: Set EnemyTurret as target


What happens here is the following:
- the "pick" condition has the consequence that the PlayerTurret only sets the EnemyTurret as a target who has the PlayerID you specify in the "pick" comparison
- having two different sprites (which are essentially the same, but have different names and are no instances of the same object) will prevent the picking condition to exclude the PlayerTurret, so it can still target the enemy.

Now you just need the PlayerID of the turret you want to target. That's it.

Hope I could help. :)
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Thu Oct 13, 2016 8:49 am

Thank you for your aswer.
Anyway I had more problems using the turret behavior.
It should work if every player joins before the game starts. But if a player joins after others players it's a little more complicated. Because I send all existing turrets from the server to the new player so the client can create those. But I have to send the all turrets in the same order those were created. Because (I think) if there are two targets at the same distance, the turret acquire the first created one. And if I do not send turrets in the same order those were created, in a client the target can be different from anothe client.
Also my clients create objects at runtime that are not created on others clients. So uid and targetuid can differ from client to client (i.e. because while a new client creates turrets that it receives from the server it can create another object on the fly addng +1 to the next turret uid).
All those poblems surely have solutions. Anyway it's little too bit complicated.

I have found a workaround in this topic: viewtopic.php?f=147&t=166138&hilit=turrets+teams
It's not using the turret behavior but storing custom turret IDs and target IDs client and server side makes clients be synced.

Thanks again
B
12
S
5
Posts: 42
Reputation: 990

Post » Thu Oct 13, 2016 7:00 pm

You could also make the turret aiming server-sided.
So that the server decides which turret aims at which turret. The server would then send each turrets TargetID to each player and they would then simpy "render" the view.
Like that, the game would also be less vulnerable to be hacked.

You could even go further and even make the turrets angles and everyting server-sided.
This would solve the problems of players joining later since the client can update the number of players, turret angle etc. as often as he wants and can then send the data over to the players who then just have to "draw" the image.
(And make their game decisions of course)
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sat Oct 29, 2016 12:31 pm

I'm trying the server side approach (just the first part in wich the server send each turret a targetID).
It's workin in a 2 player game (player/enemy). I use:
Code: Select all
- pick turred by turretID
- pick enemyTurret by enemyturretID
- turret add target enemyturretID.


The problem when it comes a third player. He saw all other's turrets as enemy turret. I can't use:
Code: Select all
- pick enemyTurret by enemyturretID   <------
- pick enemyTurret by enemyturretID   <------
- enemyTurret add target enemyturretID.


I think because the the econd enemyTurret pick "overWrites" the first one. I think I should find a way to do something like

Code: Select all
- pick enemyTurret by enemyturretID   AS A
- pick enemyTurret by enemyturretID   AS B
- A add target B.


Making all server side as you suggest in the second part of your answer could be a solution. But in this way I will not use the turret behavior at all.
Maybe it's also better... I'm thinking about it.
B
12
S
5
Posts: 42
Reputation: 990


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests