Jump to content
  • 0

Making an item that can only be used once per level


Riclo500

Question

I'd like to make an item that can only be used once, and then it can't be used again until you get to the next level. Either that, or a cool-down mechanic would be good too. For example, an item that gives the rage rune, but then it has a 5 minute cool down before it can be used again.

Are either one of these possible to create?

Share this post


Link to post

4 answers to this question

Recommended Posts

  • 0
13 hours ago, Riclo500 said:

I'd like to make an item that can only be used once, and then it can't be used again until you get to the next level. Either that, or a cool-down mechanic would be good too. For example, an item that gives the rage rune, but then it has a 5 minute cool down before it can be used again.

Are either one of these possible to create?

 

You could try to use an event handler to give an item to the player at the start of the map. Limit the item so that you can only hold one. Something like this code from the wiki:

 

class ItemGiveEventHandler : EventHandler
{
	override void NetworkProcess (ConsoleEvent e)
	{
		if (e.IsManual || e.Player < 0 || !PlayerInGame[e.Player] || !(players[e.Player].mo))
			return;

		let player = players [e.Player].mo;
		
		Array<string> command;
		e.Name.Split (command, ":");

		if(command.Size() == 2 && (command [0] ~== "giveitem"))
		{
			player.GiveInventory (command [1], 1);
		}
	}
}

https://zdoom.org/wiki/Events_and_handlers

Share this post


Link to post
  • 0
3 hours ago, Nihlith said:

 

You could try to use an event handler to give an item to the player at the start of the map. Limit the item so that you can only hold one. Something like this code from the wiki:

 


class ItemGiveEventHandler : EventHandler
{
	override void NetworkProcess (ConsoleEvent e)
	{
		if (e.IsManual || e.Player < 0 || !PlayerInGame[e.Player] || !(players[e.Player].mo))
			return;

		let player = players [e.Player].mo;
		
		Array<string> command;
		e.Name.Split (command, ":");

		if(command.Size() == 2 && (command [0] ~== "giveitem"))
		{
			player.GiveInventory (command [1], 1);
		}
	}
}

https://zdoom.org/wiki/Events_and_handlers


Hmm I really appreciate your help. I don't understand Zscript but I did manage to find a way to get it working through ACS and Decorate

 

actor FuryMedallion : CustomInventory
{
  //$Sprite MEDFA0
 +INVBAR
 -INVENTORY.INTERHUBSTRIP
  Inventory.DefMaxAmount 
  Inventory.MaxAmount 1
  Inventory.PickupFlash "PickupFlash"
  Inventory.icon "MEDFB0"
  Inventory.pickupmessage "You found the Fury Medallion"
  Inventory.RespawnTics 9999999999999999
  Scale 0.05
  states
  {
  Spawn:
    MEDF A -1 
    stop  
  Use:
    TNT1 A 0 A_JumpIfInventory("PowerFuryMedallionCooldown", 1, "Bad")
	TNT1 A 0 A_JumpIfInventory("FuryMedallionusagelimit", 1, "Good")
	TNT1 A 0 A_Print("Fury Medallion is recharging until the next level")
	Fail
	Good:
	TNT1 A 0 A_GiveInventory("PowerDoubleFiringSpeed",1)
	TNT1 A 0 A_TakeInventory("FuryMedallionusagelimit",1)
	TNT1 A 0 A_GiveInventory("FuryMedallionCooldown",1)
	Fail
	Bad:
	TNT1 A 0
	Fail
	}
}

Actor FuryMedallionusagelimit : ammo
{
Inventory.MaxAmount 2
}

ACTOR PowerFuryMedallionCooldown : Powerup
{
	Powerup.Duration 1050
}

ACTOR FuryMedallionCooldown : PowerupGiver
{
	Powerup.Type "PowerFuryMedallionCooldown"
	+AUTOACTIVATE
}

PowerFuryMedallionCooldown & FuryMedallionCooldown allow me to put a duration limit on how often it can be used, and then the FuryMedallionusagelimit item allows me to only use it twice, at least until the next level when the ACS kicks in:

 

script 700 ENTER
{
GiveInventory("FuryMedallionUsageLimit", 2);
}

 

Edited by Riclo500

Share this post


Link to post
  • 0

That's awesome, I'm glad you got it working. There's a lot of overlap between the coding languages. You could also alter your player pawn with a piece of code like:

Override Void BeginPlay()
	{
		Super.BeginPlay();
		GiveInventory ("FuryMedallion",1); 
	}

You can put it in after the Default block and before the States block, that way when the level starts it would just happen. That would be the way to do it if you are making a mod instead of a stand alone game.

Share this post


Link to post
  • 0
On 11/19/2023 at 9:07 PM, Riclo500 said:


Hmm I really appreciate your help. I don't understand Zscript but I did manage to find a way to get it working through ACS and Decorate

 

 

I was resistant to zscript and there are some incredible things that creative use of decorate can achieve, still, I am led to believe that the cool kids use zscript now and for the layman they work almost exactly the same, except with more functions. I think this zscript would do the same as your code:

Class FuryMedallion : CustomInventory
{
  Default
{
  //$Sprite MEDFA0
 +INVBAR;
 -INVENTORY.INTERHUBSTRIP;
  Inventory.DefMaxAmount;
  Inventory.MaxAmount 1;
  Inventory.PickupFlash "PickupFlash";
  Inventory.icon "MEDFB0";
  Inventory.pickupmessage "You found the Fury Medallion";
  Inventory.RespawnTics 9999999999999999;
  Scale 0.05;
}
  states
  {
  Spawn:
    MEDF A -1; 
    stop;
  Use:
    TNT1 A 0 A_JumpIfInventory("PowerFuryMedallionCooldown", 1, "Bad");
	TNT1 A 0 A_JumpIfInventory("FuryMedallionusagelimit", 1, "Good");
	TNT1 A 0 A_Print("Fury Medallion is recharging until the next level");
	Fail;
	Good:
	TNT1 A 0 A_GiveInventory("PowerDoubleFiringSpeed",1);
	TNT1 A 0 A_TakeInventory("FuryMedallionusagelimit",1);
	TNT1 A 0 A_GiveInventory("FuryMedallionCooldown",1);
	Fail;
	Bad:
	TNT1 A 0;
	Fail;
	}
}

Class FuryMedallionusagelimit : ammo
{
Inventory.MaxAmount 2;
}

Class PowerFuryMedallionCooldown : Powerup
{
	Powerup.Duration 1050;
}

Class FuryMedallionCooldown : PowerupGiver
{
	Powerup.Type "PowerFuryMedallionCooldown";
	+AUTOACTIVATE;
}

 If it doesn't work, gzdoom will tell you what the problem is with it. On one hand, if it aint broke don't fix it, but on the other hand you might find this interesting https://forum.zdoom.org/viewtopic.php?t=57300

 

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...