Krafties Spells API

From Krafties
Jump to: navigation, search

Krafties - Spell Receiver API v1.0[edit]

~~ NOTE: You MUST obtain an API key from Krafties before being able to use any of the Krafties APIs! This key is unique to each individual creator and should not be shared.

~~ Please see http://krafties.com/wiki for more details on the API and API keys.


The Spell Receiver API allows player owned krafties to cast specific spells on any objects you create! The API allows you to then handle and respond to the spells when they are cast with ANY LSL code you put together via linked messages. At this point in time, when a spell is cast the API exposes the name of the spell that was cast, and the type of spell cast. These are all handled in a link_message event.



SETUP:


Step 1) Obtain your unique API Key. If you already have an API Key from a separate Krafties API, that will work for this one as well!


Step 2) Drop both the "Krafties-API_spellReceiver v1.0" and "KRAFTIES_API Config [SpellReceiver]" scripts into the object you wish to have Krafties spells cast on


Step 3) Open and configure the "Krafties_API Config [Spell Receiver]" script. All configuration variables are at the top of the script.

   a) API_KEY:
       - This is the key you get from Krafties that identifies you as a unique creator. Once you have obtained your key, copy/paste it into the script where it says UNIQUE_API_KEY_HERE.
   b) SPELL_DISPLAY_TYPES
       - This list determines what types of spells will show up in the menus of a player attempting to cast a spell on this object, if the player's creature has unlocked said spells. Alongside the predefined spell group identifiers, you can also include the names of specific spells or specific element types. Spell group identifiers follow:
           * SET_SPELL
               - Displays spells that show up when a player clicks their creature, selects "Battles", then selects "Set Spell"
           * OTHER_ACTIVE
               - Displays spells that show up when a player clicks on another player's active creature and then selects "Cast Spell"
           * WILD 
               - Displays spells that show up when a player clicks on a wild creature, then selects "Cast Spell"
           * SELF
               - Displays spells that show up when a player clicks on their own active creature, then selects "Cast Spell"
           * OPPONENT
               - Displays spells that show up when a player clicks on an opposing creature in PvP battle
           * TEAMMATE
               - Displays spells that show up when a player clicks in a teammate in PvP battle
           * ENCHANT
               - Displays spells that show up when a creature clicks an enchanting tablet, then selects "Cast Spell"
           * ALCHEMY
               - Displays spells that show up when a creature clicks an alchemy tablet, then selects "Cast Spell"


Step 4) Save the "Krafties_API Config [Spell Receiver]" script.


      • IF ALL WENT WELL, YOU NOW HAVE THE BASIC SPELL CASTING FEATURES SET UP. CLICKING THE OBJECT WILL GIVE YOU A MENU ALLOWING YOU TO CAST SPELLS ON IT IF YOU HAVE A SUITABLE ACTIVE KRAFTIE ATTACHED.
      • ADVANCED STEPS FOLLOW


You are now ready to handle spells being cast, either in the link_message event of the "KRAFTIES_API Config [SpellReceiver]" script itself or your own script residing in the same object. Note that if you do use your own script, you will want to remove the llSay() provided in the "KRAFTIES_API Config [SpellReceiver]" so as not to detract from the experience you create.

When a spell is cast, this function is called:

   - llMessageLinked(LINK_SET, 59377, spellName, spellType);

What this does parameter by parameter:

   - assuming link_message event structure of: link_message(integer senderNum, integer num, string message, key id)
       * LINK_SET: message is sent to ALL prims in the link set
       * 59377: message is broadcast with a number identifier of 59377 
           - FUN FACT: to 59377 resembles the word "SPELL"
           - In your link_message events, you'll want to check if (num == 59377) to verify it is a spell message
       * spellName: the message parameter holds the name of the spell cast
           - in script: string spellName = message;
       * spellType: the id parameter holds the element type of spell cast
           - In script: string spellType = (string)id;
               * Cast to string because actual type of id is key

EXAMPLE:

       - Fireplace that lights when any fire spell is cast on it
           * In config step:
               - list SPELL_DISPLAY_TYPES = ["Fire"];
           * IF FLAMETHROWER IS CAST:
               - Link message sent: llMessageLinked(LINK_SET, 59377, "Flamethrower", "Fire");