Need help out of a code dilemma

Discussions about Coding and Scripting
Post Reply
gopostal

Need help out of a code dilemma

Post by gopostal »

Here's my problem. I have scripted checkreplacements for all the weapons called by monsterhunt. The code section looks like this:

Code: Select all

        if ( Other.IsA('Weapon') )
        {
		if ( Other.IsA('TournamentWeapon') )
			return true;

		if ( Other.IsA('UIWeapon') )
			return true;
		if ( Other.IsA('Stinger'))
		{
			ReplaceWith(Other, "MonsterHunt.OLStinger");
			return false;
		}

		if ( Other.IsA('Rifle'))
		{
			ReplaceWith( Other, "MonsterHunt.OLRifle" );
			Return false;
		}
	
		if ( Other.IsA('Razorjack') )
		{
			ReplaceWith(Other, "MonsterHunt.OLRazorjack");
			Return false;
		}

		if ( Other.IsA('Minigun'))
		{
			ReplaceWith( Other, "MonsterHunt.OLMinigun" );
			return false;
		}
	
		if ( Other.IsA('AutoMag'))
		{
			ReplaceWith( Other, "MonsterHunt.OLAutoMag" );
			return false;
		}

		if ( Other.IsA('Eightball'))
		{
			ReplaceWith( Other, "MonsterHunt.OLEightball" );
			return false;
		}
	
		if ( Other.IsA('FlakCannon') )
		{
			ReplaceWith( Other, "MonsterHunt.OLFlakCannon" );
			return false;
		}
		
		if ( Other.IsA('ASMD'))
		{
			ReplaceWith( Other, "MonsterHunt.OLASMD" );
			return false;
		}

		if ( Other.IsA('GesBioRifle') )
		{
			ReplaceWith( Other, "MonsterHunt.OLGESBioRifle" );
			return false;
		}

		if ( Other.IsA('dispersionpistol') )
		{
			ReplaceWith( Other, "MonsterHunt.OLDPistol" );
			return false;
		}

      	}
I had to do this because the unreal 1 weapon pickups in the normal MH maps wouldn't fire. Well, the replace works great but it creates another larger problem for me. The skaarj troopers that have unreal 1 weapons assigned to them by the map are now broken. All my code to stop them dropping weapons is ignored, as well as being able to skip them when F5'ing through the players. Skaarj Troopers with UT weapons do fine, and behave exactly like I want them to.

In short, how can I add in CheckReplacement something that will poll the inventory of the skaarj trooper and subclasses? If it finds an unreal1 weapon, it sets them to the UT equivalent (probably the easiest solution).

I hope I said this clearly enough.
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Need help out of a code dilemma

Post by Feralidragon »

Maybe this? (Check NEW CODE comment in the code itself)

Code: Select all

function bool ReplaceWith(actor Other, string aClassName)
{
    local Actor A;
    local class<Actor> aClass;

    if ( Other.IsA('Inventory') && (Other.Location == vect(0,0,0)) )
        return false;
    aClass = class<Actor>(DynamicLoadObject(aClassName, class'Class'));
    if ( aClass != None )
	{
        A = Spawn(aClass,Other.Owner,Other.tag,Other.Location, Other.Rotation);
		//NEW CODE
		if (A.IsA('Weapon') && ScriptedPawn(Other.Owner) != None)
			Weapon(A).bCanThrow = False;
	}
	
    if ( Other.IsA('Inventory') )
    {
        if ( Inventory(Other).MyMarker != None )
        {
            Inventory(Other).MyMarker.markedItem = Inventory(A);
            if ( Inventory(A) != None )
            {
                Inventory(A).MyMarker = Inventory(Other).MyMarker;
                A.SetLocation(A.Location 
                    + (A.CollisionHeight - Other.CollisionHeight) * vect(0,0,1));
            }
            Inventory(Other).MyMarker = None;
        }
        else if ( A.IsA('Inventory') )
        {
            Inventory(A).bHeldItem = true;
            Inventory(A).Respawntime = 0.0;
        }
    }
    if ( A != None )
    {
        A.event = Other.event;
        A.tag = Other.tag;
        return true;
    }
    return false;
}
gopostal

Re: Need help out of a code dilemma

Post by gopostal »

I completely appreciate the code reply, but sadly it doesn't work. What's happening is that when the weapon checkreplacement iterates through the map and replaces the skaarj weapon, it breaks the skaarj. If I exclude the checks, the skaarj works perfectly, and if I add a check in the weapon for skaarj, they also still work, but the weapon is no longer replaced on the various pickups. What I need is some nudge on how to declare IsA on the SkaarjTrooper and then swap their weapon ahead of the full actor check for unreal 1 weaponry. Since CheckReplacement happens so early on the map startup it's very hard to get in front of it.

Ferali, I'll email you the entire class so you may see.
gopostal

Re: Need help out of a code dilemma

Post by gopostal »

Fixed. I emailed Iniquitous and he sent this back:

Code: Select all

if (Other.isA('Weapon') && Other.Instigator != None && Other.Instigator.IsA('Skaarj'))
	{
		return true;
	}
Once I added that to the head of the checkreplace it functions perfectly (server tested). Whew! Thought I was in a pickle there.
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Need help out of a code dilemma

Post by Feralidragon »

gopostal wrote:Fixed. I emailed Iniquitous and he sent this back:

Code: Select all

if (Other.isA('Weapon') && Other.Instigator != None && Other.Instigator.IsA('Skaarj'))
	{
		return true;
	}
Once I added that to the head of the checkreplace it functions perfectly (server tested). Whew! Thought I was in a pickle there.
Then that way the Skaarj don't get their weapon replaced at all... Or you replace their weapons somewhere else?

Also, btw, just a sugestion: change Skaarj to ScriptedPawn instead, since it's more general. Otherwise if there's a custom pawn set in a map which has scriptedpawns with weapons, they might get the bug on them again like the Skaarj had previouslly, you never know.
gopostal

Re: Need help out of a code dilemma

Post by gopostal »

I had thought that Skaarj not getting the replacement would be bad but it seems that the function to actually fire the weapon is what is broken if you use stock unreal weapons in MH. For some reason the skaarj can fire them just fine, and since they don't drop them, it's not an issue. (Perhaps they simply call the projectile class)...

This issue such weird errors caused by it. The simple fact they lost their weapon to pick up a replaced one caused them to totally lose all the custom work I had done for them. I wish I knew why. I mean I'm glad it's sorted out but I'd sure love to understand it better.

Nice idea on the S.Pawn, I had not considered that but I will make the adjustment.
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

Re: Need help out of a code dilemma

Post by Rakiayn »

very nice :D.
I had the same problem. I solved it by. giving the replace function a small delay , so the skaarj have time to pickup there weapons. and then only replace weapons which are not picked up yet.
but I think this works better
gopostal

Re: Need help out of a code dilemma

Post by gopostal »

Mod is now done and released:
MonsterHunt2

Whew. That was a LOT of work lol. Let's see what happens now...
Post Reply