Jump to content

Trying to make a recipe output item execute a script


MikePayne307

Recommended Posts

I've been beavering about with a crafting mod for a while now (yep, another one :teehee: ) mostly for the learning experience.

I had the idea of making it so the player could learn from breaking down weapons as they appear to do in '76.

I've been trying to avoid adding heaps of notes to the inventory and thought of having schematics which would set variables before deleting themselves but I can't get the script execute correctly: it either deletes itself without setting any of the variables or adds itself to the inventory, but will work correctly if I drop it and pick it up again.

My script is pretty basic, being based on the ammo box scripts but I'm not sure what the issue is after trying various iterations of blocktypes and Scriptwait commands.

scn AASchematics9mmPistolItemSCRIPT

int killme

BEGIN OnAdd Player
	Set killme to 1
END

begin GameMode
	
	if (killme == 1)
			set AAUnlock.9mmPistol to 1
			set AAUnlock.9mmPistolScope to 1
			set AAUnlock.9mmPistolExtMag to 1
			ScriptWait 10
			;Remove this item from inventory
			removeme
	endif

end

Any help anyone can give me would be much appreciated. Is it even something that can be launched directly after a recipe menu?

Link to comment
Share on other sites

Thanks IntenseMute,

I tried altering as you suggested, but got the same result. I've just read, items added through crafting will not execute without first being dropped and picked back up, and may not be guaranteed to work if I shift them to another container, so would something like JIP's SetOnMenuCloseEventHandler be a better solution?

Edited by MikePayne307
Link to comment
Share on other sites

I haven't done anything like this, but my initial thought upon viewing your code was "set a flag and have another script perform the actual removal". Which would go along with your latest thought of using the "SetOnMenuCloseEventHandler". But I decided to wait and see if anyone with more direct experience (like IntenseMute) had a better suggestion. Now it seems worth mentioning.

 

-Dubious-

Link to comment
Share on other sites

Try this script, it gets called by the SetOnCraftingEventHandler function:

;This script gets called by the following event handler: SetOnCraftingEventHandler

ScriptName AASchematics9mmPistolItemSCRIPT

Ref ItemRef
Short ItemQuantity

BEGIN Function {ItemRef, ItemQuantity}

If ItemRef == AASchematics9mmPistolItem ; <-- Your schematic item here
	Set AAUnlock.9mmPistol To 1
	Set AAUnlock.9mmPistolScope To 1
	Set AAUnlock.9mmPistolExtMag To 1
	Player.RemoveItem ItemRef ItemQuantity
EndIf

END

Tested it myself and it works for me.

Link to comment
Share on other sites

Thanks guys.

The new method worked and also gave me the idea to be able to control what the player receives materials-wise when breaking down items based on character stats (Only 870 recipes to process) :D

I got a massive 22 second delay when using it in conjunction with JIP Improved recipe menu, though. The delay disappeared when I changed to an OnMenuClosed handler pointing to the recipe menu, but I can't find any documentation relating to that mod. Perhaps this is something I need to ask Jazzisparis himself about it?

 

EDIT: It appears I've fixed this by changing the script processing delay to match the one from JIP Improved recipe menu

Edited by MikePayne307
Link to comment
Share on other sites

  • Recently Browsing   0 members

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