[DECORATE] Giving and taking weapons, like demon runes?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Endie
Posts: 227
Joined: Thu Mar 16, 2017 7:34 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Somewhere in the void

[DECORATE] Giving and taking weapons, like demon runes?

Post by Endie »

Yep, like... i want to add a new powerup to my mod, when picked up, it gives the player a weapon, and when the powerup ends, it takes the weapon from the player.
I still learning about pickups, so i need some help here.
User avatar
ramon.dexter
Posts: 1529
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: [DECORATE] Giving and taking weapons, like demon runes?

Post by ramon.dexter »

I can imagine this could be done in zscript. Better said, I'll give you an example, when I got home from work.

edit: So, here is small example of zscript powerup. This powerup draws power over time, second by second. When depleted, removes itself form player, as so removes the effect.
You want to have this behaviour with the stock powerups? If so, the only possible option is zscript.

Code: Select all

class PowerLantern : PowerTorch //PowerLightAmp
{
	int lantern_tics; 

    override void attachtoowner(actor user) //here it resets the internal counter, spo when player picks this us, the counter is set correctly to zero
    {
        lantern_tics = 0;
        super.attachtoowner(user);  //so it deos the rest of built in functionality
    }

    override void doeffect()
    {
		Super.doEffect(); //so it deos the rest of built in functionality
		

              //under these lines is my own functinality added
		if(owner.countinv("NightEyeDevice") <= 1)  //control if the powerup source is depleted >> if so, removes itself from player
        {
            owner.takeinventory("LanternActive", 1);
            owner.takeinventory("nightEyeActiveToken", 1);
			self.destroy();
			return;
		}

        lantern_tics++;
        //make something every two seconds (2*35 tics)
        if(lantern_tics == 70)
        {
            owner.takeinventory("NightEyeDevice", 1);
            lantern_tics = 0;
        }

    }
	
	Default
	{
		powerup.Duration 0x7FFFFFFD;
		powerup.color "6fef67", 0.05;
		//inventory conf
		//==--------------------------
		Inventory.Icon "I_BLNK";
		//==--------------------------
	}
}
As you can see from this code, I have to modify the basic functionality of DoEffect() function to achieve desired effect. Such an advanced functionaly could be achievede only in zscript. Or, maybe, I can imagine some dirty solution in ASC, like loop checking whther player has the powerup, which is just dirty and resource heavy.
User avatar
Endie
Posts: 227
Joined: Thu Mar 16, 2017 7:34 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Somewhere in the void

Re: [DECORATE] Giving and taking weapons, like demon runes?

Post by Endie »

Oh, wow! this should help, thank you
User avatar
ramon.dexter
Posts: 1529
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: [DECORATE] Giving and taking weapons, like demon runes?

Post by ramon.dexter »

But keep in mind that if you want to modify the stock powerups, you should check the gzdoom.pk3 for zscript definitions of these. So you will be able to properly modify them.
User avatar
Endie
Posts: 227
Joined: Thu Mar 16, 2017 7:34 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Somewhere in the void

Re: [DECORATE] Giving and taking weapons, like demon runes?

Post by Endie »

Understood, but i have plans to create a new powerup, and your code will fit perfectly to my intentions, thanks again
User avatar
ramon.dexter
Posts: 1529
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: [DECORATE] Giving and taking weapons, like demon runes?

Post by ramon.dexter »

Yes, but my code is for powerup that could be turned on and off. Also, if you like this, I have to post the rest. Because withoutthe rest, it will not work.

So, here's rest of the code:

Code: Select all

class NightEyeDevice : CustomInventory //23048 <<- this is the inventory item, that player will pickup/buy; It has amount of 100, because it acts as a power source for the powerup itself - something like duke nukem did with it's powerups
{
	int nighEyeSwitch; //integer storing value for turning on and off

	Default
	{
		//$Category "Items"
		//$Color 9
		//$Title "Night-Eye Device"
		
		-Solid
		+inventory.invbar
		+inventory.AlwaysPickup
		
		radius 8;
		height 18;
		scale 0.5;
		Tag "$T_NGHTEYE";
		inventory.icon "I_NEDV";
		inventory.amount 100;
		inventory.maxamount 300; //so you can have this item three-times in inventory
		inventory.interhubamount 300;
		inventory.PickupMessage "$F_NGHTEYE";
	}
	
	States
	{
		Spawn:
			NEDV V -1;
			Stop;

		Use: 
			TNT1 A 0
			{
				if(invoker.nighEyeSwitch == 0) {return ResolveState("Activate");} //simple check based on the variable's value
				if(invoker.nighEyeSwitch == 1) {return ResolveState("Deactivate");}
				return ResolveState(null);
			}
			Stop;
		Activate:
			TNT1 A 0
			{
				invoker.nighEyeSwitch = 1; //when activated, set variable to one
				A_Giveinventory("LanternActive", 1); //and give plyer the powerup
				A_Giveinventory("nightEyeActiveToken", 1); //as well as anything else - this is simple token for HUD purposes
			}
			Stop;
		Deactivate:
			TNT1 A 0
			{
				invoker.nighEyeSwitch = 0; //deactivated = variable set to zero
				A_TakeInventory("PowerLantern", 1); //remove the powerup
				A_TakeInventory("LanternActive", 1); //as well as the powerup giver
				A_TakeInventory("nightEyeActiveToken", 1); //and the token - you dont need this token for this to function
			}
			Stop;
	}

}


//==--------------------------------------------------------------------------==
//mechanics
//==--------------------------------------------------------------------------==
class nightEyeActiveToken : Inventory //the mentioned token - simple inv item tham doesnt appear in invbar, and player can have only one at a time
{
	Default
	{
		-INVENTORY.INVBAR

		inventory.amount 1;
		inventory.maxamount 1;
		inventory.interhubamount 1;
	}

}
class PowerLantern : PowerTorch //PowerLightAmp <<- the powerup itself, also all the magic happens here :)
{
	int lantern_tics;  //simple counter

    override void attachtoowner(actor user)
    {
        lantern_tics = 0; //to reset the counter when player receives this powerup
        super.attachtoowner(user); // to do the rest of the function
    }

    override void doeffect()
    {
		Super.doEffect();
		
		if(owner.countinv("NightEyeDevice") <= 1)  //this check is to remove the powerup, when the source item is depleted, removes everyhting as well as destroyes itself - the self.destroy() is used because the item, that is calling the remove function, cannot remove itself. But it can commit suicide, which is practically the same.
        {
            owner.takeinventory("LanternActive", 1);
            owner.takeinventory("nightEyeActiveToken", 1);
			self.destroy();
			return;
		}

        lantern_tics++; //every tic add one to counter

        if(lantern_tics == 70) //when counter is 70 (2 seconds) do stuff
        {
            owner.takeinventory("NightEyeDevice", 1); //this removes the source item
            lantern_tics = 0; //and resets the counter so it can counter another 2 seconds
        }

    }
	
	Default
	{
		powerup.Duration 0x7FFFFFFD;
		powerup.color "6fef67", 0.05;
		//inventory conf
		//==--------------------------
		Inventory.Icon "I_BLNK";
		//==--------------------------
	}
}

class LanternActive : PowerupGiver
{
	Default
	{
		//flags
		//==--------------------------
		+INVENTORY.AUTOACTIVATE;
		+INVENTORY.FANCYPICKUPSOUND;
		//==--------------------------
		//powerup conf
		//==--------------------------
		powerup.Duration 0x7FFFFFFD;
		powerup.Type "PowerLantern";
		//==--------------------------
		//inventory conf
		//==--------------------------
		Inventory.MaxAmount 1;
		Inventory.UseSound "pickups/slowmo";
		//==--------------------------
	}
	
	States
	{
		Spawn:
			TNT1 A 0;
			Stop;
	}

}
Hope this helps you :)
Post Reply

Return to “Scripting”