Jump to content

OnCreation bug?


Recommended Posts

Hey guys,

I have this small problem with a creature. I gave her MINHP1.itm for quest purposes but when a certain state has been reached, I want to remove MINHP1

It's a VERY simple script and yet... it doesn't work.

So first the creature is created in dimension door during a cutscene

CreateCreatureDoor("mage18z",[738.419],S)

Then I try to remove MINHP1 with this, which is in the OVERRIDE script for mage18z completely at the top:

IF
	OnCreation()
	Global("TSFired","LOCALS",1)
THEN
	RESPONSE #100
		SetGlobal("test","GLOBAL",12)
		DestroyItem("MINHP1")  // No such index
END

MINHP1 never gets removed.

Now I've tried switching TSFired from local to global to check it in-game with console, and it says it's equal to 1 before mage18z gets created, so the condition should be ok.

Moreover, the test global I'm setting.... it's never set to 12, ever. Which means it never gets to the RESPONSE #100 in the first place!

Anyone knows what's going on? Maybe OnCreation() never runs because the creature was created in a cutscene?

Thanks!

Edited by Daxtreme
Link to comment

I’m not entirely sure why OnCreation() didn’t fire, but in any case it’s a bit fragile and I tend to avoid it. As a general rule, your code is more robust if, when a block is supposed to fire once, the condition enforcing that can be guaranteed to be set only when the thing the block is supposed to do happens.

In this case, a simple way to do it is to replace OnCreation() with HasItem(Myself,”MINHP1”) (assuming you don’t want to give it back later, that is!)

Link to comment

LOCALS are per-instance, so spawning a new version means no LOCALS carry over.

If you wanted to keep it in the creature's script, this would work:

IF
	HasItem("MINHP1",Myself)
	Global("TSFired","LOCALS",1)
THEN
	RESPONSE #100
		SetGlobal("test","GLOBAL",12)
		DestroyItem("MINHP1")  // No such index
END
Link to comment
7 hours ago, Daxtreme said:

Thanks, works flawlessly!

That might... but checking for a LOCALS and then setting a GLOBAL is definitely not the brightest of ideas. But like DavidW said... it's not even needed, as just checking the item itself does things well... or if the LOCALS triggers it, then you don't need to check for the item. As you should either check for the item... or the LOCALS and append that LOCALS... or use a GLOBAL. So an example would be:

IF
	Global("TSFired","LOCALS",1)
THEN
	RESPONSE #100
		SetGlobal("TSFired","LOCALS",2)
		DestroyItem("MINHP1")  // No such index
END

 

Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...