How should I go about this gun system?

So I am currently working on a game, and Im starting to work on the gun system, the only thing Im wondering is which of these is the best option, Im trying to go for as optimized as possible, so with that being said, here are my current ideas.

  • A.
    If a player tries to shoot send an event to the server to tell it to fire a single shot, with automatic weapons wait a specified time after every shot before shooting again/sending an event to the server
  • B
    When a player attempts to shoot with a semi weapon it fires a event to the server to tell it to shoot once, in the case of an automatic, it fires a event to the server to tell it to start shooting, and then when you stop holding down the fire button, it sends an event to tell the server to stop shooting.

Now on the one hand, option A sends a lot more events, but in turn with option B, I’d have to guess every time it shoots in order to do effects and stuff.

So any ideas? Do either of these heavily effect performance? Or does it really just not matter and is up too preference? Thanks!

3 Likes

Generally I’d go with option A. Events are surprisingly robust and can handle a lot of throughput, but more importantly option B brings a lot of edge cases which might be difficult to handle. For example, what if the player dies while shooting, what if they change their weapons without letting go of mouse button 1, or what if they leave while shooting? You’d have to think of how to end the event even in an unclean way.

3 Likes

you shuld just be fireing a raycastresult to the server, not making the server actually handle firing since it’ll be delayed so much. I learned that whe making my owng un system

how I do it now (this is hitsn I usually do projectiles but decided to do hitscan
image
I just send the position, target, all the data to the server and the server will spawn bullet holes and kill humanoids. I do checks to make sure exploiters aren’t abusing it as easily

3 Likes

I was considering this, but I dont really like hitscan very much, it just feels wrong in my opinion, but in case I ever need to make hit scan, Ill make sure to remember this, thanks!

1 Like

no I didn’t mean uise hitscan I meant that send hit data to the server

so like

prjectile hit connect (project tile data)
        remote:send data (projectile hit data)
endd

only problam is it’s unsecure from exploiters but if you check ammo on server and stuff it’ll be more secure. plus the usual axploits are just aimbotting.

every game with a projectile gun system has used this method to send data from the client, execpt for some like doomspire but that’s a rocket

1 Like

Source?

1 Like

Arsenal, Breakify’s “Realistic” Gun Test Place, Emergency Response : Liberty County, Gunfight Arena, Phantom Forces, Every airsoft game, Deadline, and a lot more. These games compute projectiles on the client and send hit data to the server, most with anticheats in place.

Hitscan games use the same method just without projectiles.

1 Like

Source?

You still havent provided a source :sob:


I also have the concern that if someone shoots and they have high ping, then the projectiles and such will act weird, and may miss their targets, but on the plus said the stuff would be as you said, a lot less delayed.

If I was to do this, any ideas for an anticheat system to work with this? One thing I can do is just check if the hit players or enemies or whatever’s position is a certain distance away from where the bullet would’ve been shot or something like that, but idk what Im talking about really lol

what do you mean by souice

well yeah but it’s not ping it’s FPS it’s dependent on. if you use the server to cast projectiles, then a high ping player might wait around 1.5 or higher seconds for that projectile to appear.

Check the rate of fire, track ammo on the server along with client, some others too.

1 Like

a source is basically where you got this information from.

Ahh I see. This might actually be the way to go, thanks!

1 Like

it is in the games’ code I listed,
and because when I shoot a gun, I instantly see a projectile come out whether I have 9999 ping or not, and the projectile’s smooth

I like to use unique codes to make sure exploiters have a harder time getting the codes and a harder time making scripts in general for the game, and by unique codes I mean codes that aren’t really visible when compiling a scrpt

fair enough, Ill try this out! Thanks for the advice!

1 Like

by the way, any ideas for verifying if the hit enemies that I send to the server are reasonable? Like it makes sense that they were hit?

Now that you mention that I remember playing games when Id freeze, shoot loads of people, unfreeze and everyones dead, so I think you’re onto something lol

1 Like

yeah that happens a lot when people are lagging so bad that their projectiles will hit the enemies, and once the client regains connection with the server, it send the hit data and the enemy just die. I used to do this in ER:LC sts when I had bad connection. old gun system used hitscan and this might be possible with the new system. I know I’ve seen people using killaura on er lc tho which is funny

not exactly sure I never really do that much checks

Ok thanks!

If I need help or have questions Ill ask you! Ill leave this open for a bit more in case more people have more input

1 Like

If you want it to be exploiter-free and performant as you say, then the only way to do it is to have everything run on the server and using multi threading for calculation.

How you implement this is up to you. There is a library from the community resources that allocates tasks to run parallel automatically, maybe that will be of use to you.

True given that the client has stable internet connection when firing inputs to the server.

simple check:

if player.isAlive == true then
	-- fire shots here
end

The above check V2:

if player.isAlive == true then
	-- fire shots here
else
	-- stop firing/cleanup
end

Honestly you have a very linear approach to this and although option A is indeed a solution, there are many more solutions to one problem.

Firing a raycast to the server means that the client is able to manipulate that raycast.

Meaning the exploiter just has to fire that same raycast from anywhere as long as the hit result is an enemy.

yeah I pointed that factor out in later posts.
besides there are checks I do

Oh sorry, I have a bad habit of replying to posts before reading the whole thread. I see it now. But this should be good information to OP.

1 Like