This is such a stupid topic because I have done this a million times before, but I seem to have forgotten how to implement it again.
I want this key to this door to have a single use. Once used, it is removed from the inventory entirely. If I am to do this, what do I need to do? I have done it before, and I don't even think I used zscript... but it was so long ago I honestly can't remember. So the player is supposed to find the key, use it on the linedef (which represents a door or gateway) and the key is supposed to be destroyed in the process so it cannot be used again.
I THINK I did it last time by adding it into the DECORATE of the key, but ... I cannot remember.
Single use key
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!)
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!)
-
- Posts: 145
- Joined: Fri Jun 03, 2022 11:31 am
- Graphics Processor: Not Listed
-
- Posts: 404
- Joined: Mon Dec 11, 2017 2:09 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Russia
-
- Posts: 145
- Joined: Fri Jun 03, 2022 11:31 am
- Graphics Processor: Not Listed
Re: Single use key
Yep! That was it, perfect. Thank you. I guess I did do it with ZScript last time. Thanks!

-
- Posts: 145
- Joined: Fri Jun 03, 2022 11:31 am
- Graphics Processor: Not Listed
Re: Single use key
Sorry to post in here again but I'm having another little issue. Now that I have this part sorted out, I have a new issue. Using the key now takes it away like it should, but what if I have a set of three doors that all require the same type of key? I want the player to use the key ONCE and have that ONE KEY taken away. But I want the player to have the option to find multiple keys of the same type to use on other doors of the same type. (also one use). But I just did a test, 3 of the same type of key in a room. Player collects all three. Uses ONE key, but then all keys are taken. Why is this happening? I only want it to take ONE of the keys, not all of them.
My code is as follows.
For some reason, it is taking all keys of the same colour instead of just one. How can I fix this issue?
My code is as follows.
Code: Select all
Script 174 (void)
{
if (!CheckInventory("blackkey")) //player must have at least 1 black key.
{
SetHudSize(600,400,TRUE); //set the hud to display the message.
HudMessageBold(s:"You need a black key to open this door."; HUDMSG_FADEOUT, 500, CR_GOLD, 300.0, 100.0, 8.0, 0.3); //tell player they CAN open the door, but only if they have a black key.
}
else
{
Autosave(); //save and open the door at the cost of a single black key.
Door_Open(3, 16, 0);
TakeInventory("BlackKey", 1); //take a black key away. <<<<<<<<<<<<<<<< shouldn't this work? I said here to take only ONE black key, hence the "1" after "BlackKey".
}
}
-
-
- Posts: 1849
- Joined: Sun Jul 21, 2019 8:54 am
Re: Single use key
Please show the code for your key.
I assume what is happening is that keys will always pick up, but they will only hold one copy of themselves in the player's inventory.
You might want to inherit your black key from a generic inventory item and set the MaxAmount to something higher.
I assume what is happening is that keys will always pick up, but they will only hold one copy of themselves in the player's inventory.
You might want to inherit your black key from a generic inventory item and set the MaxAmount to something higher.
-
- Posts: 145
- Joined: Fri Jun 03, 2022 11:31 am
- Graphics Processor: Not Listed
Re: Single use key
Ah yeah I thought it was probably the keys code itself. Here it is. What should I do to fix this?
Code: Select all
ACTOR BlackKey : Key 9365
{
//$Category Keys
//$Title Black Key
//$Sprite BLKKA0
Inventory.PickupMessage "$GOTBLKK"
Inventory.Icon "SVKEYS0"
Scale 0.05
Radius 8
Height 8
+wallsprite
States
{
Spawn:
BLKK AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 1 A_SetAngle(angle+3.0,SPF_INTERPOLATE)
BLKK A 3 Bright A_SetAngle(angle+3.0,SPF_INTERPOLATE)
BLKK A 3 A_SetAngle(angle+3.0,SPF_INTERPOLATE)
BLKK A 3 Bright A_SetAngle(angle+3.0,SPF_INTERPOLATE)
Loop
}
}
-
-
- Posts: 1849
- Joined: Sun Jul 21, 2019 8:54 am
Re: Single use key
Because of how keys work, setting MaxAmount and -INVENTORY.ALWAYSPICKUP won't work.
You will never get more than 1 key and you will keep picking them up regardless if you hit the maximum amount or not.
Though seeing as you only check it in ACS, you can make your key a simple inventory item:
Doing this will allow you to set how many keys the player can pick up and keep in their inventory.
You will never get more than 1 key and you will keep picking them up regardless if you hit the maximum amount or not.
Though seeing as you only check it in ACS, you can make your key a simple inventory item:
Code: Select all
ACTOR BlackKey : Inventory 9365
{
//$Category Keys
//$Title Black Key
//$Sprite BLKKA0
Inventory.MaxAmount 3 //Set the max amount to 3
Inventory.PickupSound "misc/k_pkup" //Set the pickup sound to that of a key
Inventory.PickupMessage "$GOTBLKK"
Inventory.Icon "SVKEYS0"
Scale 0.05
Radius 8
Height 8
+wallsprite
States
{
Spawn:
BLKK AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 1 A_SetAngle(angle+3.0,SPF_INTERPOLATE)
BLKK A 3 Bright A_SetAngle(angle+3.0,SPF_INTERPOLATE)
BLKK A 3 A_SetAngle(angle+3.0,SPF_INTERPOLATE)
BLKK A 3 Bright A_SetAngle(angle+3.0,SPF_INTERPOLATE)
Loop
}
}
-
- Posts: 145
- Joined: Fri Jun 03, 2022 11:31 am
- Graphics Processor: Not Listed
Re: Single use key
Thank you so much, this works perfectly now. Life saver.Jarewill wrote: ↑Mon May 22, 2023 2:30 pm Because of how keys work, setting MaxAmount and -INVENTORY.ALWAYSPICKUP won't work.
You will never get more than 1 key and you will keep picking them up regardless if you hit the maximum amount or not.
Though seeing as you only check it in ACS, you can make your key a simple inventory item:Doing this will allow you to set how many keys the player can pick up and keep in their inventory.Code: Select all
ACTOR BlackKey : Inventory 9365 { //$Category Keys //$Title Black Key //$Sprite BLKKA0 Inventory.MaxAmount 3 //Set the max amount to 3 Inventory.PickupSound "misc/k_pkup" //Set the pickup sound to that of a key Inventory.PickupMessage "$GOTBLKK" Inventory.Icon "SVKEYS0" Scale 0.05 Radius 8 Height 8 +wallsprite States { Spawn: BLKK AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 1 A_SetAngle(angle+3.0,SPF_INTERPOLATE) BLKK A 3 Bright A_SetAngle(angle+3.0,SPF_INTERPOLATE) BLKK A 3 A_SetAngle(angle+3.0,SPF_INTERPOLATE) BLKK A 3 Bright A_SetAngle(angle+3.0,SPF_INTERPOLATE) Loop } }
