overriding Weapon.TraceFire()

Discussions about Coding and Scripting
Post Reply
museeeii
Novice
Posts: 13
Joined: Tue Feb 07, 2017 12:42 am

overriding Weapon.TraceFire()

Post by museeeii »

I just want to override the TraceFire() function from Weapons.uc

I have done:

Code: Select all

class DecoupledWeapon extends Weapon;

function TraceFire( float Accuracy )
{
	Log("TraceFire Runs!");
	//Super.TraceFire(Accuracy);  // dont run this for now
}
and I am adding the mutator:

Code: Select all

class HelloWorld extends Mutator;

function bool CheckReplacement(Actor Other, out byte bSuperRelevant) {
	if ( Other.IsA('Weapon') && !Other.IsA('DecoupledWeapon')) {
		ReplaceWith( Other, "DecoupledWeapon.DecoupledWeapon" );
		return false;
		//Other.Class = Class'DecoupledWeapon.DecoupledWeapon';  // this gives an compiler error: Can't assign Const variables
	}
	return true;
}

All I want to do it to Log that message every time any object/weapon or whatever is running the function TraceFire()
If I return false in CheckReplacement then all players will have no weapons and no weapons will be in entire arena.
If I return true then no difference from a normal game and will no be logging the message. What-a-hell?

I read the tut from https://wiki.beyondunreal.com/Legacy:CheckReplacement but it doesnot work for UT99
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: overriding Weapon.TraceFire()

Post by sektor2111 »

museeeii wrote://Other.Class = Class'DecoupledWeapon.DecoupledWeapon'; // this gives an compiler error: Can't assign Const variables
Yes, because is a dumb thing, Class is defined you will not change class name "Enforcer" with "Spoon". You didn't get what CheckReplacement does.
museeeii wrote:If I return false in CheckReplacement then all players will have no weapons and no weapons will be in entire arena.
If I return true then no difference from a normal game and will no be logging the message. What-a-hell?

I read the tut from https://wiki.beyondunreal.com/Legacy:CheckReplacement but it doesnot work for UT99
I think "All players" will NOT fire a weapon in multiplayer because it's not a TournamentWeapon - unless you know what to do at this point. Else CheckReplacement doesn't have any issue so far in UT'99 - unless you play another game. However, you can load this weapon without replacing anything by giving new thing to player. I'm going to mention here the need for a MESH else you will not see anything in HUD and neither in game - everything being turned into an useless void.

Code: Select all

class DecoupledWeapon extends Weapon; //expands/extends an abstract class invisible into a... nothing so far
This is pretty much a nothing - What MESH does use this thing ? And... which ammo ?
By using a child of a ShockRifle (or another with TraceFire) which player is loading in ModifyPlayer nothing will hurt anything.
Option 2 - a sort of arena mutator by copying and modifying a current arena mutator.
For completing task this "Weapon" must be seen - it do requires some visuals assigned.
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: overriding Weapon.TraceFire()

Post by Barbie »

museeeii wrote:I just want to override the TraceFire() function from Weapons.uc [...]
All I want to do it to Log that message every time any object/weapon or whatever is running the function TraceFire()
So this means you have to replace the function - overriding code is another aspect.
Replacing code should be possible by XC_Engine or hacking the package where Weapon.uc resides (Engine.u). Ask the experts Higor or Sektor2111 for details.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
museeeii
Novice
Posts: 13
Joined: Tue Feb 07, 2017 12:42 am

Re: overriding Weapon.TraceFire()

Post by museeeii »

sektor2111 wrote:

Code: Select all

class DecoupledWeapon extends Weapon; //expands/extends an abstract class invisible into a... nothing so far
This is pretty much a nothing - What MESH does use this thing ? And... which ammo ?
I am aware that if I create a new weapon I should define all of its behavior in his class (or extending from an existing one). Then, If I would want to replace any weapon in the arena I should checkReplacement().
The class DecoupledWeapon its not intended to run as an object in the game, a weapon or actor. Its intended to run just as, lets say, an replacement for objects which are child of class Weapon. This way (I believe) that the Enforcer for example, would run the TraceFire() from DecoupledWeapon class instead from the Weapon class.
sektor2111 wrote:
museeeii wrote://Other.Class = Class'DecoupledWeapon.DecoupledWeapon'; // this gives an compiler error: Can't assign Const variables
Yes, because is a dumb thing, Class is defined you will not change class name "Enforcer" with "Spoon".
It may sound stupid but its what I am trying to do, but, instead of replacing the class definition by another one, I am trying to replace the object's base class. For instance: Object.Class == class'Weapon' should be changed to point to class'DecoupledWeapon.DecoupledWeapon', so Object.Class = class'DecoupledWeapon.DecoupledWeapon'.

But, after all, I dont know if I am thinking the right way. I thought it was easy like:

Code: Select all

Weapon.TraceFire = function() {
  // do things here
}
Do you guys have any idea how to do? Or do you think I am thinking too dumb
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: overriding Weapon.TraceFire()

Post by sektor2111 »

Only a normal weapon can override a parent class not a fake. TraceFire is being called when weapon is firing, I don't see any sort of firing code there,.. and weapon will not even show up because doesn't have "face" if I can uses this term. What you have there is more borked than that original quadshot.
Solution for such logs would be using a subclass visible weapon and one operational, not only a single function which I'm not sure if will ever be called because you don't have firing code.
museeeii wrote:This way (I believe) that the Enforcer for example, would run the TraceFire() from DecoupledWeapon class instead from the Weapon class.
False - if things would run this way, UT would be easily fixed by community in its firsts 3 years of life being error free at this moment. Your code sounds like: my car is called fish - so the car will swim because it's fish from now on - Unreal Engine 1 doesn't have such a support. But you can replace function with XCGE by using another abstract of weapon and writing replaced code there - it will run for all weapons using that function if they don't run their own code.

Note:
XCGE means XC_Engine by Higor.
museeeii
Novice
Posts: 13
Joined: Tue Feb 07, 2017 12:42 am

Re: overriding Weapon.TraceFire()

Post by museeeii »

sektor2111 wrote:Your code sounds like: my car is called fish - so the car will swim because it's fish from now on - Unreal Engine 1 doesn't have such a support
LOL. thats what I was thinking like. Sounded funny when you said
sektor2111 wrote:Only a normal weapon can override a parent class not a fake.
hmm, ok. So I will have to extend all weapons from UT and just override the TraceFire function, then replace it in checkReplacement. Got it. But, it would not work if the player started a match with some mod/mutator that added a new weapon. How to handle cases like this?
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: overriding Weapon.TraceFire()

Post by sektor2111 »

If you want to do this mutator for testing that Trace probably purpose is to work alone with Game-Type loaded (DM CTF etc)
Then if this thing runs alone with no special stuff you can write a simple mutator with... NO CODE - read well, No Code.

Code: Select all

class TestWepTrace expands Mutator;

DefaultProperties
{
     DefaultWeapon=class'DecoupledWeapon'
}
Mutator saying about another <defaultweapon> (mutated one), a default game will load this new thing as replacement for ImpactHammer. In other way you can subclass DM to another DM game child declaring at default properties this new weapon and then game loads this new "defaultweapon". For such cases you don't even need any code. But I repeat, weapon must be operational not a sort of abstract.

Interference with mutators
Probably you will not think at any compatibility, exist mutators removing everything which doesn't belong to themselves messing up stuff - so is good to know that NOT all Mutators are compatible each-other, to summarize blabbering through mutators is not a healthy way. InstaGib as example doesn't allow anything else than own stuff.
Post Reply