CheckInventory woes (fixed)

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
User avatar
Nirvana
Posts: 156
Joined: Thu May 01, 2008 8:15 am

CheckInventory woes (fixed)

Post by Nirvana »

Basically I have script which causes a few monsters to spawn when you cross a linedef, but only if you have the Red Keycard. Unfortunately, if you cross the linedef before picking up the card the script seems to get terminated and then running across it with the card wont even activate it.

I've tried a heap of ways to fix it and have referred to the Wiki for help to no avail, I'm sure it is a really simple fix...

Code: Select all

Script 9 (void)
{
	if (CheckInventory("Redcard"))
{
Spawnspot("NAMIDARKIMP",9, 4, 180);
while (ThingCount(T_NONE, 4) > 0) delay(30);
Spawnspot("NAMIDARKIMP",9, 4, 180);
}
}
Last edited by Nirvana on Thu Jul 30, 2009 5:43 am, edited 1 time in total.
CaptainToenail
Posts: 3975
Joined: Fri Jul 06, 2007 9:16 am

Re: CheckInventory woes

Post by CaptainToenail »

Could you put an 'Else' part in there that restarts the script?
User avatar
Remmirath
Posts: 2562
Joined: Sun Dec 23, 2007 3:53 am
Graphics Processor: nVidia with Vulkan support
Location: My house
Contact:

Re: CheckInventory woes

Post by Remmirath »

Just put Else like this:

Code: Select all

Else
{
}
User avatar
Nirvana
Posts: 156
Joined: Thu May 01, 2008 8:15 am

Re: CheckInventory woes

Post by Nirvana »

Yeah, I tried that but it still seems to terminate when you run over it...I'm stumped :(

Code: Select all

Script 9 (void)
{
	if (CheckInventory("Redcard"))
{
Spawnspot("NAMIDARKIMP",9, 4, 180);
while (ThingCount(T_NONE, 4) > 0) delay(30);
Spawnspot("NAMIDARKIMP",9, 4, 180);
} else {
}
}
User avatar
Remmirath
Posts: 2562
Joined: Sun Dec 23, 2007 3:53 am
Graphics Processor: nVidia with Vulkan support
Location: My house
Contact:

Re: CheckInventory woes

Post by Remmirath »

Try to put some delay here:

Code: Select all

Script 9 (void)
{
   if (CheckInventory("Redcard"))
{
Spawnspot("NAMIDARKIMP",9, 4, 180);
while (ThingCount(T_NONE, 4) > 0) delay(30);
Spawnspot("NAMIDARKIMP",9, 4, 180);
} else {
delay(1);
}
}
User avatar
Ichor
Posts: 1784
Joined: Wed Jul 23, 2003 9:22 pm

Re: CheckInventory woes

Post by Ichor »

Just a wacky thought, but is that linedef repeatable?
User avatar
Nirvana
Posts: 156
Joined: Thu May 01, 2008 8:15 am

Re: CheckInventory woes

Post by Nirvana »

Nope, it still didn't work.

See I need to make it be able to repeat the Else part of the code but make it so that if you have the RedKeyCard it only performs the If action once. Therefore I can't make it a repeatable action linedef, because then if you have the card you can make an infinite number of enemies spawn, which I don't want.
User avatar
Jimmy
 
 
Posts: 4728
Joined: Mon Apr 10, 2006 1:49 pm
Preferred Pronouns: He/Him
Contact:

Re: CheckInventory woes

Post by Jimmy »

You could instead set that linedef to have the Line_SetIdentification special, give it a line id of say, 50, then give the red keycard thing an ACS_Execute special that triggers a script to set the special of line 50 to trigger the monster spawning script.
User avatar
Ichor
Posts: 1784
Joined: Wed Jul 23, 2003 9:22 pm

Re: CheckInventory woes

Post by Ichor »

Well, once the red key part of the script is triggered, you could just turn off the line:

SetLineSpecial(linetag, 0 /* No Special */, 0, 0, 0, 0, 0)

Either that or maybe change a variable so that the script won't activate again once you pass the line with the red key.
User avatar
Nirvana
Posts: 156
Joined: Thu May 01, 2008 8:15 am

Re: CheckInventory woes

Post by Nirvana »

jimmy91 wrote:You could instead set that linedef to have the Line_SetIdentification special, give it a line id of say, 50, then give the red keycard thing an ACS_Execute special that triggers a script to set the special of line 50 to trigger the monster spawning script.
This worked a treat, but essentially this hasn't fixed the error, it just means that the line has no special set until you pick up the key, right? I would like to see if my original code is fixable, because it would be a bit simpler...
User avatar
Nirvana
Posts: 156
Joined: Thu May 01, 2008 8:15 am

Re: CheckInventory woes

Post by Nirvana »

On a side note, is there a way to make monsters spawn in an alerted state? So they wander around, a la normal enemy teleporters?
User avatar
Jimmy
 
 
Posts: 4728
Joined: Mon Apr 10, 2006 1:49 pm
Preferred Pronouns: He/Him
Contact:

Re: CheckInventory woes

Post by Jimmy »

If the monster spawning script is triggered by the player, you can use [wiki]Thing_Hate[/wiki].

Code: Select all

Thing_Hate(monster tid, player tid [or 0], hate type);
I think you'll just want Thing_Hate(4,0,0); in this case.

EDIT: Sorry, (4,0,4);.
User avatar
Remmirath
Posts: 2562
Joined: Sun Dec 23, 2007 3:53 am
Graphics Processor: nVidia with Vulkan support
Location: My house
Contact:

Re: CheckInventory woes

Post by Remmirath »

This problem is really strange; i mean, i've used this kind of scripts a lot of times, and they've never given me any type of error. Does the script terminate with a Runway Error?
User avatar
Isle
Posts: 687
Joined: Fri Nov 21, 2003 1:30 am
Location: Arizona, USA

Re: CheckInventory woes

Post by Isle »

you could use a map variable

Code: Select all

int RedKeyLine;

Script 9 (void)
{
   if (CheckInventory("Redcard") && RedKeyLine)
   {
      RedKeyLine = 1;
      Spawnspot("NAMIDARKIMP",9, 4, 180);
      while (ThingCount(T_NONE, 4) > 0) delay(30);
      Spawnspot("NAMIDARKIMP",9, 4, 180);
   }
}
User avatar
Nirvana
Posts: 156
Joined: Thu May 01, 2008 8:15 am

Re: CheckInventory woes

Post by Nirvana »

Isle wrote:you could use a map variable

Code: Select all

int RedKeyLine;

Script 9 (void)
{
   if (CheckInventory("Redcard") && RedKeyLine)
   {
      RedKeyLine = 1;
      Spawnspot("NAMIDARKIMP",9, 4, 180);
      while (ThingCount(T_NONE, 4) > 0) delay(30);
      Spawnspot("NAMIDARKIMP",9, 4, 180);
   }
}
Could you explain this code before I implement it? I always like to know exactly what the code is doing and why rather than just copy and pasting...

Also @Morpheus, it doesn't cause a runaway error. What seems to happen is that when you run over the linedef without the key it tries to activate the script, but can't because you don't have the Red key and then terminates it because it isn't repeatable. I can't make it repeatable because then you can spawn enemies ad infinitum and that would just be stupid, but my If code doesn't seem to work :(

I mean, essentially I can just make a code where you pick up the red key and it spawns monsters, but this code has become a conundrum and I would really like to know how to get it to work for future reference. I just don't understand why the if/else statement isn't working where I have a previous if/else statement using the Red Keycard that works perfectly...it makes no sense...

EDIT: Just to clarify, by terminate I mean, when you run over the line without the key, even if you come back with the keycard and run over the line, it wont run the script (whereas if you idclip over the line and then give yourself the keycard and run over it, it runs the script...
Locked

Return to “Editing (Archive)”