Jump to content

Tokens on creatures


gsmanners

Recommended Posts

I know this is a silly question, but has anyone tried making tokens work on creatures? Now, creatures don't wear armor, so it's not unexpected.

 

In my mod, I stick the refID for the creature into a quest variable when I additem to the player, so all I have to do is then copy that value to a variable into the token. That works out fine, but if my tokens weren't temporary (5 seconds, in my case), I could imagine the player's inventory getting awfully cluttered.

 

Here the relevant code from my beta version of "The Deleter":

 

scn DeleterEffectScript

begin ScriptEffectStart
removeallitems DeleterContainer
if getdead == 0
	rewardxp 5
	kill
endif
setactoralpha 0
set DeleterQuest.targetForToken to GetSelf
player.additem DeleterToken 1 1
end

scn DeleterQuestScript

short doOnce
short isDE

ref targetForToken	; only used in DeleterEffect when adding a token

begin GameMode
if doOnce == 0
	player.additem WeapDeleter 1
	set doOnce to 1
endif
if player.getequipped WeapDeleter
	set isDE to 1
else
	if isDE
		DeleterContainer.activate player
	endif
	set isDE to 0
endif
end

scn DeleterTokenScript

short doOnce
ref target
float timer

begin OnAdd player
; this should be the right value, due to the timing involved
set target to DeleterQuest.targetForToken
end

begin GameMode
set timer to timer + GetSecondsPassed
if doOnce == 0 && timer >= 5
	set doOnce to 1; should be redundant, but probably necessary
	if target
		target.removeallitems DeleterContainer	; collect death items
		if target.getparentref == 0
			target.disable
			target.markfordelete
		else
			target.setactoralpha 255	; welcome back, Mr. I-Can't-Be-Deleted
		endif
	endif
	removeme
endif
end

Link to comment
Share on other sites

Although, as you have mentioned, creatures can't actually equip apparel, tokens should work just fine when placed in the inventory of a creature. However, because the tokens can't be equipped, they cannot be used to apply object effects so ScriptEffectStart blocks won't run. Instead, use an OnAdd block to run code when a token is added to an inventory.

 

Sorry if I've misinterpreted you, I'm not entirely sure that I understand what you're trying to do or what the problem is so I feel like I might easily have gotten it wrong.

 

Cipscis

Link to comment
Share on other sites

It's interesting if you actually try to add tokens to creatures. I think the GetContainer in OnAdd returned 0 and the GameMode code only ran for one tick. I don't remember correctly, but you certainly cannot do anything as elaborate as the timer code I have in the above code block.
Link to comment
Share on other sites

I've been helping with a project over the last week or so that involves using tokens to run a pseudo-random death sequence, and they work perfectly well on creatures.

 

GetContainer sometimes (rarely) takes more than one frame to return a meaningful value, so that might be why you had trouble with it in the OnAdd block. If you then tried to use an uninitialised (probably set to 0 by GetContainer) "ref" variable in your GameMode block that would halt the script after a single iteration.

 

Cipscis

Link to comment
Share on other sites

It's pretty damned inconvenient for GetContainer to not function on an OnAdd block. :ohmy: So, the solution is to wait for a value in GetContainer to show up in GameMode? Or would using a global/quest variable still be a better idea?

 

When a 0-ref halt occurs, that apparently leaves a non-functioning token in a creature's inventory, and any variables it uses will be stuck with their last instance value to anyone looking at it with ShowVars.

 

Here's another interesting thing about tokens. You can have more than one token with any number of visible variables on an NPC that you can scan with ShowVars, but you can't tell which variable is which. I guess you have to trust the tokens to sort their own individuality out logically.

Link to comment
Share on other sites

GetContainer nearly always will work just fine in an OnAdd block, but I've recently encountered some rare occasions on which it won't - I'm not quite sure why not either.

 

In order to prevent a script halt due to invalid use of a "ref" variable, it often pays to check if the variable has been properly set via a conditional statement. For example:

ref rContainer

Begin OnAdd

set rContainer to GetContainer

End

Begin GameMode

if rContainer
; Do stuff
else
	set rContainer to GetContainer
endif

End

If the script does halt, however, it seems that the game flags the script so that it maintains its current state (i.e. variables maintain the same values) but is not executed anymore.

 

There can be some problems with having multiple scripted tokens of the same type in the same inventory, but that's more due to the fact that functions like RemoveItem aren't particularly specific, and RemoveMe is a pretty quirky and unreliable function unless used very simply.

 

Cipscis

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...