Download

How to make the server handle important decisions for the game

ok so i know that for multiplayer youre supposed to make the server authoritive and let it make all the important gameplay decisions.

so at the moment i have a reload weapon function, which all works perfectly. it checks that the player has ammo, the player reloads it then deducts the ammo and displays the new amount on the hud, so my question is how do i change the function or whatever to help prevent the player from cheating lets say reloading if they have no ammo.

so basically i want the server to check that the player has ammo remaining, has the right type of ammo, and then tell the player to reload. maybe a bool eg canPlayerReload so if true then the player has passed the server checks if false the player is trying to cheat dont let him reload.

here is my reload function

http://blueprintue.com/blueprint/55ip570j/

thanks

Player hits ‘R’ -> Have server check for ammo ->
-> true -> server reloads weapon -> client plays animation
-> false -> do nothing/show “out of ammo” widget

Just be sure to have the server handle everything relating to ammo. e.g, When a player shoots -> server checks to see if has ammo

thats what i tried. all the clients reload animation sync is fine but the hud doesnt work properly. at the moment i reload on the server and the hud ammo amount changes. if i reload on the clients the hud amount doesnt change. i think maybe do i need to have the ammo variables etc inside the player controller for it to work for each player??

and thats what i was asking how do i make the server check do i just add an authoritive node or do i make the function into an event that runs on the server??

Is what you linked all being ran on the server? You need to call visual changes on the client

Also, your player cast is only using index 0, or in other words the server…

on the owning client im getting them to call the event on the server.
ctlNe8A.png

0sGLQXM.png

this only works on the server none of the clients.

if i do it just normal like this

0xhoA6a.png

this works on all the clients

Check out the Multiplayer Shootout project, it has exactly what you need and you can learn a lot. It was a great resource when I was figuring out multiplayer

By the way, you don’t need Switch has Authority right after a “Run on Server” RPC event, as the event is already only being ran on the Authority (server) (someone correct me if I’m wrong)

thats what i was doing. the only difference i can see is he has the variables inside the character bp where as mine are in the weapon class where the function is, and he isnt doing any checks to see wether the player has ammo or anything.

The issue is that ReloadWeapon is not being called on the clients weapon.

You should create a multicast event on player that calls reload weapon, call that from server

You need to look closer at all the blueprints. Did you mean checking for ammo to update the widget, or for firing? Because he is getting the ammo count in both cases.

1ae9c3551835bc11ba56d8545f9d99e5cce68c0d.png
66b38703dec6387e8655a36c4c600c60a9746cc9.png

the setups are completly different.
he is using the variable rounds located in the character BP calling an event inside the character bp

MINE the variable is located in a child blueprint of a base weapon class and being called from a function within that class so its a bit more complicated. i could do it how he has it set up but when dealing with multiple weapons , each having different attributes etc it is better to have it all in a function and i want all stuff to do with weapons inside the weapons class otherwise if you do it how he has here basically everything would be inside the character bp.

The only extra complication would be getting the ammo, as he does in the widget. Server/client communication works the same, the location of variables in this case don’t matter.

The Multiplayer Shootout example is setup to show how multiplayer replication works, you don’t have to copy it, just understand it. Your problem is simple: you’re not calling the necessary events on the client. You should also take a look at the networking map on the Content Examples project

Here is how I did my Server Side reload handling. The only 2 variables that are replicated are CurrentAmmoInMag and CurrentTotalAmmo, if they weren’t replicated then my widgets wouldn’t update. The server has full control over weapons, the client can only make a request to fire or request to reload.

I need to get rid of the delays and set up timers

ZDcBRsI.png

296529f9e86dda8bb09c2cf3aee986d820ba81cb.png

strange this is almost the exact setup I had . All I did was move the event from the character bp into the base weapon blueprint like ln youre pictures and instead of calling the function directly I made a custom event to call the function and now it all works

thanks a lot dude

That may have been a client/server mismatch, I am still quite new to replication myself, it’s a PITA