Adding a script to an ingredient

Revision as of 07:18, 14 October 2008 by imported>UDUN

I wanted to create a piece of poisoned cheese (clone of cheese wedge) with 4 alchemical effects neither of which would be deadly poison - but which when consumed by PC would be like a poisoned apple - bye bye.Problem is when ingredient is consumed its script will terminate. I overcame this by creating a mute quest holding variables. I don't see if it can be done with no quest. Probably checking for active effects then tracking them to the cheese but this is difficult - among other things because the ActiveEffectIndex doesn't seem to be chronological. Chm er and the script terminates.

Also of interest is the possibility to be extended to any actor, not only PC but also NPCs and creatures. Not sure if possible.

Create a clone of CheeseWedge and name it something like PoisonCheese. Add a quest (not start game enabled) (UdunPoisonedCheeseQuest) and attach one script to it (UdunPoisonedCheeseQuestScript) and one script to the PoisonedCheese you created (mine had formId 01004547, which I use directly). Here are the scripts. I tested them with OBSE v0015, but probably these final versions don't require OBSE.

object Script

scn PoisonedCheeseScript
;tested with OBSE v0015

Begin onAdd player
	set UdunPoisonedCheeseQuest.cheeses to UdunPoisonedCheeseQuest.cheeses + 1
	if GetQuestRunning UdunPoisonedCheeseQuest == 0 
		StartQuest UdunPoisonedCheeseQuest
		set UdunPoisonedCheeseQuest.fQuestDelayTime to 0.05	;0.01
	endif
end

Begin onDrop player
	set UdunPoisonedCheeseQuest.cheeses to UdunPoisonedCheeseQuest.cheeses - 1
	return
end	

Begin MenuMode 1035	;ingredients alchemy submenu
	set UdunPoisonedCheeseQuest.skippedframe to 3
end

quest Script

scn UdunPoisonedCheeseQuestScript
;tested with OBSE v0015

	short cheeses
	short skippedframe
	float fQuestDelayTime
	
begin MenuMode 1002	;inventory menu
	if (cheeses==0)
		StopQuest UdunPoisonedCheeseQuest
		return
	endif
	if skippedframe==3	;ingredients alchemy submenu was open
		set cheeses to player.GetItemCount 01004547
	endif
	if (player.GetItemCount 01004547 == cheeses) && skippedframe!=0
		set skippedframe to 0
	endif
	if (player.GetItemCount 01004547 != cheeses) && skippedframe==0
		set skippedframe to 2
                ;debugging purposes
                ;if one frame skipped is enough change to set skippedframe to 1
		return
	elseif (player.GetItemCount 01004547 != cheeses) && skippedframe>1
		set skippedframe to skippedframe - 1
		return
	elseif (player.GetItemCount 01004547 != cheeses) && skippedframe==1
		set cheeses to  player.GetItemCount 01004547
		player.addspell AbApplePoison
		set skippedframe to 0
	endif
end

UDUN 19:01, 13 October 2008 (EDT)