Preventing a player from bearing arms

Place to get help with not working mods / modding interface.
Post Reply
User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 727
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Preventing a player from bearing arms

Post by DRY411S »

How could I stop a player from arming themselves? I've noted the events for when a player has changed their gun or ammo inventories, but the events seem to occur after the changes, I.e. After they have added a gun or ammo.

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 727
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Preventing a player from bearing arms

Post by DRY411S »

Hmm, I'm guessing I can get the player's gun/ammo inventory when this event occurs and return it to their main inventory. I'll try that.


User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 727
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Preventing a player from bearing arms

Post by DRY411S »

Supercheese wrote:Here's an old approach of mine I used a while back: https://github.com/Suprcheese/Satellite ... #L102-L108
Thanks. I have something that works now. This code returns any gun that a player tries to arm themselves with back to their main inventory
code
Do you have any idea what event goes off when ammo is placed in a tank or car or artillery turret please?

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Preventing a player from bearing arms

Post by eradicator »

All factorio events fire after something happens.

A quick look at your code looks like it'll delete any guns that are still in the gun inventory if the player inventory is full. I.e. if a player with an already full inventory takes a gun out of a chest.
DRY411S wrote: Do you have any idea what event goes off when ammo is placed in a tank or car or artillery turret please?
No events are ever fired for changes to inventories other than the player inventory. You're only chance would be cursor_stack_changed i guess. But then again one can just build an inserter next to the tank and put the item on the ground for it to be grabbed :P

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Preventing a player from bearing arms

Post by orzelek »

Wouldn't it be easier to simply mod out weapons and guns out of vehicles?

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 727
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Preventing a player from bearing arms

Post by DRY411S »

eradicator wrote:<snip>

A quick look at your code looks like it'll delete any guns that are still in the gun inventory if the player inventory is full. I.e. if a player with an already full inventory takes a gun out of a chest.
Thanks. I'll check that edge case. I was expecting the gun to be tossed on the ground, like when players mine things when their inventory is full, or change armor to one where there are less inventory slots.
eradicator wrote: No events are ever fired for changes to inventories other than the player inventory. You're only chance would be cursor_stack_changed i guess. But then again one can just build an inserter next to the tank and put the item on the ground for it to be grabbed :P
OK. I'm thinking I'll try emptying the ammo from a vehicle's guns when the player enters it, (if they are the only occupant, or the passenger), or maybe see what affects removing the permission to change shooting stance has.

The emptying when they enter idea doesn't take care of what may happen if they then add ammo after they've entered the vehicle.

If none of those ideas work I may may need to redefine the 'bear arms' concept to be personal firearms only.
Last edited by DRY411S on Wed Apr 11, 2018 5:48 pm, edited 1 time in total.

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 727
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Preventing a player from bearing arms

Post by DRY411S »

orzelek wrote:Wouldn't it be easier to simply mod out weapons and guns out of vehicles?
Fair point, but this is for a role-based scenario concept, where only certain roles can fire weapons.

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 727
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Preventing a player from bearing arms

Post by DRY411S »

Edge case failed. Gun disappears into the ether as you suspected.

Now looking at at setting the player's shooting state to 'not shooting' and removing the permission to change it, as a workaround.

Melfish
Inserter
Inserter
Posts: 42
Joined: Mon Nov 17, 2014 1:20 pm
Contact:

Re: Preventing a player from bearing arms

Post by Melfish »

You could make a blank not working gun and set that as equipped.

You would still have to test if someone were to remove/replace it, but then that edge case shouldn't happen.
As an added bonus, shiftclicking will not equip a gun.

I would also check if gun inventory amount is part of the player prototype, if it is you could add a player entity without any gun slots.

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 727
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Preventing a player from bearing arms

Post by DRY411S »

eradicator wrote:A quick look at your code looks like it'll delete any guns that are still in the gun inventory if the player inventory is full. I.e. if a player with an already full inventory takes a gun out of a chest.
Been away from this for a while but now have a fix for that. The items get spilled on the ground.
New code

Post Reply

Return to “Modding help”