x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Stuck on replicating Ammo Count data

Hey everyone, I've managed to use the First Person Blueprint template to get a basic shooter running. So far I've managed to replicate the players projectiles dealing damage on both client and server. However, when it comes down to the ammo count, it only shows up on the server.

I have replicated my variables and I have set events to Multicast or Run on Server as well as making sure they are reliable.

I've also attempted to use the whole "Switch has Authority" switch but I still have issues.

My current setup displays the ammo count as 8 for each weapon (which is what I intended as the starting ammo). My issue now lies in the successful depletion of ammo when firing the weapon. On the server/host this works just fine. The client is unable to deplete the ammo and is unable to fire the weapon.

alt text

(below) When fire is called, it checks if the player has the appropriate weapon equipped, then proceeds to check the current ammo. Respectively triggering it to release a projectile if the criteria is met.

When fire is called, it checks if the player has the appropriate weapon equipped, then proceeds to check the current ammo. Respectively triggering it to release a projectile if the criteria is met.

(below) Ammo is then supposed to be depleted by the value of 1 and then it will update the ammo of whatever weapon is selected

Ammo is then supposed to be depleted by the value of 1 and then it will update the ammo of whatever weapon is selected.

(below) This is where you cycle with the scroll wheel to choose the weapon you want to use.

This is where you cycle with the scroll wheel to choose the weapon you want to use.

(below) When the weapon is chosen, its ammo type is then loaded into a variable so that it can be depleted.

When the weapon is chosen, its ammo type is then loaded into a variable so that it can be depleted.

So there we have it in its current state, only firing and depleting ammo on the server/host side.

Product Version: UE 4.9
Tags:
more ▼

asked Nov 11 '15 at 12:05 PM in Blueprint Scripting

avatar image

Kagamusha
173 37 33 44

avatar image Enlo Dec 07 '15 at 09:48 AM

such a long question with nice screenshots but no response :(

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Screenshot 1: You don't need to differentiate between server and clients here, just call "Server Fire" all the time. When called on a server, the server-RPC executes too (see the RPC table )

Screenshot 2: No need to execute the Deplete Ammo on every client, since the Ammo value is a replicated variable anyway. So just execute this on the server and every client should get this update. Also, I think you are trying to do a multicast call from the client, which is dropped. Only the server can do this (see RPC table).

It's easy to get confused by replication, don't feel bad about it :) I think you confused RPC and replicated variables here and did way too much work.

I suggest you only do somethink like this:

  • the ammo counter is already replicated, so whenever the server changes it's values, every remote version of this player gets updated anyway

  • Now, only do input handling locally and immediately call the server from here (Run on server).

  • The server then checks and depletes the ammo (which, thanks to variable replication, automatically is replicated back to everyone's instance of this client's pawn)

  • now the server fires the projectile. If you set this projectile to be a replicated actor, you don't need to think about more replication at all, the projectile is then replicated to everyone!

  • if you don't like this, you send a "execute on all" from the server and spawn a private,local projectile. You could actually totally ignore replication of the projectile and just destroy it on impact without doing anything, since...

  • damage handling should only be done on the server (by checking the authority in the OnHit event)

  • The only thing upon impact to execute on everyone's computer is the animation, eg playing sound and animation

more ▼

answered Nov 11 '15 at 01:36 PM

avatar image

Enlo
859 23 9 40

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question