Difference between revisions of "Krafties Energy API"

From Krafties
Jump to navigation Jump to search
(Created page with " Quick Start 1. Drag the script and config notecard into your object or prim "KraftiesEnergyAPI" script "Krafties Energy API Config" notcard 2. Edit the config notec...")
 
 
(20 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
[[Category:Krafties API]]
 +
{{Technical}}
 +
==Quick Start==
  
Quick Start
+
#Drag the script and config notecard into your object or prim
 +
#*"krafties-API_BASE [Energy]" script
 +
#*"Krafties Energy API Config" notcard
 +
#Edit the config notecard for the energy amounts payable to you.
 +
#*You can use up to 12 amounts separated by commas. <code>0</code> = Any custom amount and allows players to say the amount they wish to give.
 +
#*:Example:    <code><nowiki>ENERGY_PRICE=0,10,100,1000</nowiki></code>
  
1. Drag the script and config notecard into your object or prim
+
===Response===
"KraftiesEnergyAPI" script
+
 
"Krafties Energy API Config" notcard
+
Succesfull transactions will fire a linked message which can be parsed:
       
+
:<code><nowiki>llMessageLinked(LINK_THIS, 0, "ENERGY_GIVEN|"+fromKey+"|"+toKey+"|"+(string)amount, "");</nowiki></code>
2. Edit the config notecard for the energy amounts payable to you.
+
 
You can use upto 12 amounts seperated by commas. 0 = Any custom amount and allows players to say the amount they wish to give.
+
===An Example Script===
Example:   ENERGY_PRICE=0,10,100,1000
+
 
 +
This is an example script, which would be placed into an object alongside the Energy API script and config notecard. This example gives the first object found in the Energy API object's inventory when someone interacts with it and transfers energy through the object. It essentially acts as a simple, barebones vendor.
 +
 
 +
NOTE: You'll have to set the energy amount button in the config notecard to match the PRICE variable!
 +
<pre><nowiki>
 +
integer PRICE = 100;
 +
 
 +
default {
 +
    link_message(integer senderNum, integer num, string message, key id) {
 +
        // Message is sent in form: llMessageLinked(LINK_THIS, 0, "ENERGY_GIVEN|"+fromKey+"|"+toKey+"|"+(string)amount, "");
 +
        list parts = llParseString2List(message, ["|"], []);
 +
        string operation = llList2String(parts, 0);
 
          
 
          
 +
        if (operation == "ENERGY_GIVEN") {
 +
            key fromKey = llList2Key(parts, 1);
 +
            key toKey = llList2Key(parts, 2);
 +
            integer energyAmount = llList2Integer(parts, 3);
 +
           
 +
            if (energyAmount == PRICE) {
 +
                llGiveInventory(fromKey, llGetInventoryName(INVENTORY_OBJECT, 0)); // Give the first object found in contents to the energy sender
 +
            }
 +
        }
 +
    }
 +
}
 +
</nowiki></pre>
  
Response
+
==Notes==
Succesfully transactions will fire a linked message which can be parsed:
+
*Only transferable energy can be given
llMessageLinked(LINK_THIS, 0, "ENERGY_GIVEN|"+fromKey+"|"+toKey+"|"+(string)amount, "");
 

Latest revision as of 01:02, 11 March 2019

Quick Start[edit]

  1. Drag the script and config notecard into your object or prim
    • "krafties-API_BASE [Energy]" script
    • "Krafties Energy API Config" notcard
  2. Edit the config notecard for the energy amounts payable to you.
    • You can use up to 12 amounts separated by commas. 0 = Any custom amount and allows players to say the amount they wish to give.
      Example: ENERGY_PRICE=0,10,100,1000

Response[edit]

Succesfull transactions will fire a linked message which can be parsed:

llMessageLinked(LINK_THIS, 0, "ENERGY_GIVEN|"+fromKey+"|"+toKey+"|"+(string)amount, "");

An Example Script[edit]

This is an example script, which would be placed into an object alongside the Energy API script and config notecard. This example gives the first object found in the Energy API object's inventory when someone interacts with it and transfers energy through the object. It essentially acts as a simple, barebones vendor.

NOTE: You'll have to set the energy amount button in the config notecard to match the PRICE variable!

integer PRICE = 100;

default {
    link_message(integer senderNum, integer num, string message, key id) {
        // Message is sent in form: llMessageLinked(LINK_THIS, 0, "ENERGY_GIVEN|"+fromKey+"|"+toKey+"|"+(string)amount, "");
        list parts = llParseString2List(message, ["|"], []);
        string operation = llList2String(parts, 0);
        
        if (operation == "ENERGY_GIVEN") {
            key fromKey = llList2Key(parts, 1);
            key toKey = llList2Key(parts, 2);
            integer energyAmount = llList2Integer(parts, 3);
            
            if (energyAmount == PRICE) {
                llGiveInventory(fromKey, llGetInventoryName(INVENTORY_OBJECT, 0)); // Give the first object found in contents to the energy sender
            }
        }
    }
}

Notes[edit]

  • Only transferable energy can be given