Gussmed Posted March 3, 2013 Share Posted March 3, 2013 I'm trying to create a workbench (and when that's working a reloading bench) that the player can place where he'd like. I can create the object, and have no trouble crafting things with the new workbench, which looks exactly like standard workbenches. The problem is that I'm having trouble with packing it up again. I could use the "stealth activate" approach that Portable Campsite uses, but I'd rather use an in-workbench option. That just seems less clumsy, and it's obvious to the player. What I'm doing right now is silently adding a dummy object to the player's inventory before calling player.ShowRecipeMenu WorkbenchRecipes. I have a recipe called "pack workbench" which is only visible if that dummy object ( FlagPortableWorkbench ) is in his inventory. My thought was that the Pack Workbench recipe would convert 1 FlagPortableWorkbench object to 1 FlagPackWorkbench object. The script then checks for the presence of the new dummy object and acts accordingly. Problem is, the recipe shows but says I have (0/1) ingredients for that recipe. So even though the dummy ingredient exists in the player's inventory, the workbench dialog won't let me use it. It's both there and not there simultaneously. I'm stumped as to how to do this gracefully. If I remove the Flag as an ingredient, the recipe works, but defaults to creating 100 of the Pack dummy object. That seems inelegant. I guess I could allow that, and delete 100 FlagPackWorkbench objects in the script, to make sure they're all gone no matter what the player specifies. I'd like a better way, though. Link to comment Share on other sites More sharing options...
Xaranth Posted March 3, 2013 Share Posted March 3, 2013 I think the simplest, most elegant way (The way I would do it, in other words), is simply to add a menu to your workbench. Create a message form that has the options 'Pack Workbench', 'Use Workbench', and 'Exit'. *Shrug* If you must do it your way (Or simply want to avoid the work), unset the 'Unplayable' flag on your ...er... flag item. :pinch: That's an awkward statement, isn't it? Then you should be able to use it in the recipe without an issue. Link to comment Share on other sites More sharing options...
Gussmed Posted March 3, 2013 Author Share Posted March 3, 2013 I'd rather use the Sneak method over a menu. The problem is that workbenches are something you frequently use several times in a row, and a menu popping up each time asking if you want to pack it up would get old fast. I'm a little unclear about your suggestion. What unplayable flag? It's not a quest item, if that's what you mean, it's an ordinary clutter object. The only thing preventing its use by the recipe seems to be a matter of timing. That is, if it were in the player's inventory before I started the script, it would work fine. The recipe seems to fail because the item isn't fully in the player's inventory yet, as near as I can tell. Link to comment Share on other sites More sharing options...
Xaranth Posted March 3, 2013 Share Posted March 3, 2013 Ahhh. Figured it was a token. Okay then, if that's the issue, simply change the script around a bit, use a gamemode block and flag and wait to bring up the workbench menu until player.getItemCount YourFlagItem > 0. Link to comment Share on other sites More sharing options...
Gussmed Posted March 3, 2013 Author Share Posted March 3, 2013 Oddly enough, that gave me the same problem. scn CraftingPortableWorkbenchScript Ref User Begin GameMode if player.GetItemCount FlagPortableWorkbench == 1 player.showrecipemenu WorkbenchRecipes player.RemoveItem FlagPortableWorkbench 1 endif end Begin OnActivate Set User to GetActionRef If GetActionRef != Player User.Activate Else player.AddItem FlagPortableWorkbench 1 ; add flag enabling pack up workbench action, automatically starts menu Endif End ... still results in the same behavior. I'm thinking there's something odd about the flag or the recipe, but I have no idea what. Link to comment Share on other sites More sharing options...
Gussmed Posted March 3, 2013 Author Share Posted March 3, 2013 Figured it out. It turns out that calling ShowRecipeMenu does not halt the script. So the menu starts, and the flag exists, so it displays the recipe.Meanwhile, the script deletes the flag.So when I select the recipe, the flag is now gone.If I remove the RemoveItem command, the recipe shows up correctly. I need to think about a workaround, something that will delete the flag on the menu closing. Link to comment Share on other sites More sharing options...
viennacalling Posted March 4, 2013 Share Posted March 4, 2013 How about making the recipe to pack up the workbench require no ingredients and output the FlagPortableWorkbench token. Then in the script swap that for the real workbench. scn CraftingPortableWorkbenchScript Ref User Ref FlagPortableWorkbenchCount Begin GameMode if player.GetItemCount FlagPortableWorkbench > 0 Set FlagPortableWorkbenchCount to player.GetItemCount FlagPortableWorkbench player.RemoveItem FlagPortableWorkbench FlagPortableWorkbenchCount player.AddItem FlagPackWorkbench 1 Disable MarkForDelete endif end Begin OnActivate Set User to GetActionRef If GetActionRef != Player User.Activate Else player.showrecipemenu WorkbenchRecipes Endif End Kind of sketchy, but functional. Link to comment Share on other sites More sharing options...
Gussmed Posted March 4, 2013 Author Share Posted March 4, 2013 (edited) How about making the recipe to pack up the workbench require no ingredients and output the FlagPortableWorkbench token I tried that. The problem is that if the recipe requires no ingredients, the "how many?" dialog for the recipe allows 100 copies. Which is an aesthetic problem, but one I prefer to avoid.Incidentally, the "FlagPortableWorkbench" item is the input material, the output material is FlagPackupWorkbench. The input material exists (1) to prevent the recipe from showing up on existing, immovable workbenches and (2) to limit the number of copies to 1 instead of 100. Edited March 4, 2013 by Gussmed Link to comment Share on other sites More sharing options...
Gussmed Posted March 4, 2013 Author Share Posted March 4, 2013 OK, some interesting things: A script attached to an object created via the Recipe menu is never called. Ever. Not even the GameMode block, let alone OnAdd or OnDrop. An object created via AddItem script command does get onAdd, MenuMode and GameMode blocks called. I still decided the primary Portable Workbench object script would end up doing all the work. Variables seem to start in a Not A Number state or something similar; "== 0" test fails, but printing the value gives 0. An object destroyed by the Recipe menu does not get OnDrop called. Nor does it get GameMode called after the menu closes. If you're curious, this is the code that worked: scn CraftingPortableWorkbenchScript ; Handle workbench recipes and disassembly of workbench Ref User int MenuActive ; create the menu. Begin OnActivate Set MenuActive to 0 ; clear Menu flag, since we haven't opened it yet. Set User to GetActionRef If GetActionRef != Player User.Activate Else set MenuActive to 1 ; remember that we opened the recipe menu when we hit GameMode next player.AddItem FlagPortableWorkbench 1 1 ; add flag enabling pack up workbench action player.showrecipemenu WorkbenchRecipes ; show the recipes Endif End ; handles all tasks when we return from the menu. Begin GameMode if MenuActive == 1 ; did we just leave the Recipe menu? set MenuActive to 0 ; don't do the menu exit twice player.RemoveItem FlagPortableWorkbench 1 1 ; get rid of the token used to enable the Pack Workbench option if player.GetItemCount FlagPackWorkbench != 0 ; did the player ask to pack the workbench? player.RemoveItem FlagPackWorkbench 1 1 ; clean up the token telling us to pack Player.AddItem PortableWorkbench 1 1 ; add a new workbench to player's inventory Disable ; destroy the world workbench MarkForDelete endif elseif MenuActive != 0 ; if MenuActive is some garbage value, set it to 0. set MenuActive to 0 endif end Link to comment Share on other sites More sharing options...
Recommended Posts