Advanced Tutorial: Adding an Item which uses an Event and Script

This tutorial assumes that you already know the basics of adding an item. If you do not, please see Basic Tutorial: Adding an Item.

In this tutorial, we will create an item that uses the Examine Event to create a drinkable potion. For the example item, we'll create an "Elixir of Beauty" which raises a character's charisma score to 18 when the item is drank, and removes the elixir and give the PC an empty bottle.

    Adding Elixir of Beauty

  1. Here's how I've set up the Elixir of Beauty. Click the "No Event (0)" button to activate the Event Editor.
  2. Event Editor

  3. Open the tree under "Item Event Elixir" and select "No Event".
  4. From the Event Type list, choose "Utilities". The reason for choosing this event is that it can be used in both Combat and Camp modes.
  5. From the Event Trigger list, choose "Execute GPDL function". This will allow us
  6. Click Add to add the event.
  7. Utilities Event Data

  8. Leave this event alone - we are really using the event's trigger to achieve our goals.
  9. GPDL Script

  10. Open the Event tree, and select Utilities.
  11. Select GPDL Script to open the Script Editor
  12. Script Editor

  13. The script needs 3 parts - one to adjust the charisma store, one to take the Elixir when it is drank, and one to give the Empty Bottle item to the PC.
  14. This bit of the script sets the PC's charisma to 18. Note that the IF statement is used to make sure the Elixir is readied before it can be drank.
    $VAR char;
    char = $MyIndex();
    
    $IF ($GET_CHAR_Ready($Myself(), "WEAPON", 0) != "Elixir")
    	{
    		$RETURN;
    	};
    
    $SET_CHAR_CHA(char, 18);
    	
  15. This line of script takes away the Elixir
    $TAKE_CHAR_ITEM($Myself(), "Elixir");
    	
  16. The last line of script gives the PC an Empty Bottle item to show that the Elixir has been drank.
    $GIVE_CHAR_ITEM($Myself(), "Empty Bottle");
    	
  17. Test the script to make sure you've got all the necessary commas, parentheses, and semi-colons.
  18. Click "OK" and then "Close" to get back to the Item Properties dialog.
  19. Naming the Button

  20. We want the button for this event to reflect the item, so rename EXAMINE to DRINK.
  21. Click "OK" to close the dialog, click "OK" again to close the Item Editor and save your work.

With new database items, it is always a good idea to try them out while you are getting used to the ins and outs of Dungeon Craft and GPDL scripting. I recommend adding a Give Treasure event and using the test feature to have a character drink the Elixir of Beauty to make sure it works properly.

NOTE: An Utilities Event was used in this example because this event work sin combat and camp. If you want the item to only be usable outside of combat, try using the Text Statements Event. If you would like an item usable only in combat, I strongly recommend using the "USE" feature for items (in the Magical Properties dialog) or writing a conditional script testing for the presence of a combatant.

FURTHER USES: With scripting you can have the item cast spells - for example, you might want to create the "Mega Quoff of Health", a potion which casts the Cleric spell "Heal" on the drinker; no problem, just use the "$CastSpellOnTarget()" function and have the actor be the drinker of the potion, and the spell be the name as it appears in the Spell Editor, in this case, "Heal".
To have an item of this type effect the whole party, use a $WHILE loop to apply the desired effect to each indexed party member. You can do the opposite with this and have it effect everyone but the party, or have it effect all combatants, or all non-human combatants, etc.
Because there is not targetting with this ability, you must use functions to tell the script whom ta apply the effects.


Back to Design Tutorials

Back to Designer's Guide Index