Possible to enable / disable weapon firing but know if player tries firing?

Discussions about Coding and Scripting
Post Reply
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Possible to enable / disable weapon firing but know if player tries firing?

Post by 1337GameDev »

I am curious if there is a way to disable players from firing weapons, but also knowing if they tried to fire a weapon?

Not sure if this would be a Mutator, inventory item, etc?

I don't want the user's selected weapon to disappear however, if possible.

Ideas?
User avatar
EvilGrins
Godlike
Posts: 9668
Joined: Thu Jun 30, 2011 8:12 pm
Personal rank: God of Fudge
Location: Palo Alto, CA
Contact:

Re: Possible to enable / disable weapon firing but know if player tries firing?

Post by EvilGrins »

Sounds like a mutator thing, though it would have to be something that replaced all weapons with no firing weapons.

There's a good mutator out there for a frying pan.
http://unreal-games.livejournal.com/
Image
medor wrote:Replace Skaarj with EvilGrins :mrgreen:
Smilies · viewtopic.php?f=8&t=13758
User avatar
ExpEM
Adept
Posts: 298
Joined: Wed Nov 09, 2016 1:48 am

Re: Possible to enable / disable weapon firing but know if player tries firing?

Post by ExpEM »

I'm at work atm so I can't look into it but check out the udamage code. Iirc, weapon notifies inventory when someone fires which is how udamage plays the extra firing sound, but I can't remember if inventory has the ability to teturn abort firing to weapon.

I'll look into it properly after work.
Signature goes here.
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: Possible to enable / disable weapon firing but know if player tries firing?

Post by 1337GameDev »

ExpEM wrote: Wed Apr 21, 2021 10:59 pm I'm at work atm so I can't look into it but check out the udamage code. Iirc, weapon notifies inventory when someone fires which is how udamage plays the extra firing sound, but I can't remember if inventory has the ability to teturn abort firing to weapon.

I'll look into it properly after work.
Thanks, I much appreciate you taking the time :)
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Possible to enable / disable weapon firing but know if player tries firing?

Post by Barbie »

See Wiki: How UT Weapons Work for a first approach.

UT weapons (not Unreal) call function FireEffect() on fire. That function is defined in class TournamentPickup so that inventory items like UDamage can use it.
In general I know only the polling method via timer() or tick() and checking Pawn.bFire and/or Pawn.bAltFire there to detect firing.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
ExpEM
Adept
Posts: 298
Joined: Wed Nov 09, 2016 1:48 am

Re: Possible to enable / disable weapon firing but know if player tries firing?

Post by ExpEM »

Barbie wrote: Thu Apr 22, 2021 1:20 am See Wiki: How UT Weapons Work for a first approach.

UT weapons (not Unreal) call function FireEffect() on fire. That function is defined in class TournamentPickup so that inventory items like UDamage can use it.
In general I know only the polling method via timer() or tick() and checking Pawn.bFire and/or Pawn.bAltFire there to detect firing.
Barbie is correct here, unfortunately there dosen't seem to be anything we can hook into short of either forcing a custom PlayerPawn and/or custom weapons. Which is entirely doable but very likely not worth the effort for whatever it is your trying to do.

I would choose the weapon route, subclass TournamentWeapon with your added hook, then subclass that with each weapon, you should be able to use more or less unmodified code for the weapons as long as you change the class names with a prefix.
The downside being that it wouldn't be compatible with other weapon mutators.

I'm not sure about the feasibly of custom PlayerPawns without using a custom gametype to force them (upak and jailbreak both use that method).

Using ModifyLogin In a mutator could do it.

Either way, like the weapon method you would have to make subclass's of your modified PlayerPawn of each player class.
Signature goes here.
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: Possible to enable / disable weapon firing but know if player tries firing?

Post by 1337GameDev »

ExpEM wrote: Thu Apr 22, 2021 3:38 am
Barbie wrote: Thu Apr 22, 2021 1:20 am See Wiki: How UT Weapons Work for a first approach.

UT weapons (not Unreal) call function FireEffect() on fire. That function is defined in class TournamentPickup so that inventory items like UDamage can use it.
In general I know only the polling method via timer() or tick() and checking Pawn.bFire and/or Pawn.bAltFire there to detect firing.
Barbie is correct here, unfortunately there dosen't seem to be anything we can hook into short of either forcing a custom PlayerPawn and/or custom weapons. Which is entirely doable but very likely not worth the effort for whatever it is your trying to do.

I would choose the weapon route, subclass TournamentWeapon with your added hook, then subclass that with each weapon, you should be able to use more or less unmodified code for the weapons as long as you change the class names with a prefix.
The downside being that it wouldn't be compatible with other weapon mutators.

I'm not sure about the feasibly of custom PlayerPawns without using a custom gametype to force them (upak and jailbreak both use that method).

Using ModifyLogin In a mutator could do it.

Either way, like the weapon method you would have to make subclass's of your modified PlayerPawn of each player class.
Hmm.... why do I need to subclass EVERY weapon?

I'm thinking i could create a TournamentWeapon class, and then store an instance of a selected weapon, and just pass through function calls to the weapon instance stored, and then set my "custom wepaon" as the pawn's selected weapon.

EG: a TournamentWeapon that's merely a "shim" to ANY other TournamentWeapon subclass, but can interrrupt / modify the weapon parameters and fire method calls...
Then if I want this to be "seamless" i set the current properties to that of the instance weapon, including model, state, etc and just pass along function calls appropriately when my "shim" isn't doing anything at that moment.

Only issue is that it'd fail checks for "Selectedweapon.class == 'Enforcer'" or etc, as my weapon won't be, and I can't shim or mock that check.

Ideas?

I also looked at UDamage, and it relies on TournamentWeapon.affector being supported, and it "shims" itself there. Interesting idea nonetheless.
User avatar
ExpEM
Adept
Posts: 298
Joined: Wed Nov 09, 2016 1:48 am

Re: Possible to enable / disable weapon firing but know if player tries firing?

Post by ExpEM »

Sorry it took so long to get back here, no home internet atm.
A shim weapon could work but it would make as many problems as it solves, special case weapons could be tricky, the eightball lock on ability and double enforcers for example would both need special treatment.
Emulating animations would be a right PITA too.

Don't let me put you off the idea though, if you can pull off a universal shim weapon then you would be opening up a whole new world of weapon modability to the community.
Signature goes here.
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: Possible to enable / disable weapon firing but know if player tries firing?

Post by 1337GameDev »

Honestly, I gave up on the shim idea.

I realized that weapons can have custom state for base TournamentWeapon class properties and it's too tough to keep them in sync (as I can't just use something like a c# accessor to fetch from the shimmed weapon instance).

I chose to instead make my own weapon, with no mesh / sounds, and store the previous selected weapon, and just put down / bring up my weapon via script.

Then just made it impossible to switch, drop, replace, etc my weapon when it's selected by a pawn.

There are logged warnings of no mesh, sounds or animation when bringing up / putting down by the pawn class. Had to copy this code into a helper class to emulate the base game process when selecting a new weapon to ensure any weapon callbacks are handled properly though (eg: from Pawn.SelectBestWeapon).
User avatar
PrinceOfFunky
Godlike
Posts: 1200
Joined: Mon Aug 31, 2015 10:31 pm

Re: Possible to enable / disable weapon firing but know if player tries firing?

Post by PrinceOfFunky »

There are two standard ways of doing this of which I'll tell just one and a custom one:

Standard: In Mutator.CheckReplacement if the actor is a projectile check the instigator and if that player shouldn't be enabled to fire then destroy the projectile.

Custom: I made AdvancedMutator, it can check if someone is trying to fire. (There's no tutorial on how to use it, there are just example mutators that use it)
"Your stuff is known to be buggy and unfinished/not properly tested"
Post Reply