Tut | API - JasXSL/GoThongs GitHub Wiki

The GoT API lets an external script hook into your HUD and start listening to HUD events. The API uses a custom channel:

GotAPI$chan(playerUUID)

Here is an example state entry to set up the listener for the owner's HUD:

state_entry(){
    // Start listening to the API channel for the owner
    llListen(GotAPI$chan(llGetOwner()), "", "", "");
    // Set up a connection to start receiving messages
    GotAPI$bindThis(llGetOwner());
}

Next set up the listener like such:

listen(integer chan, string name, key id, string message){
    // Returns and ends the listener event if id was not owned by the same owner as this script
    idOwnerCheck
    
    // AA| means it's an API action
    if(llGetSubString(message, 0, 2) == "AA|"){
        // The rest of the message is a JSON array
        list data = llJson2List(llGetSubString(message, 3, -1));
        // The first value of the array is the action ID. Specified in got API.lsl
        integer action = llList2Integer(data, 0);
        // The rest of the array contains arguments passed along the actions
        data = llDeleteSubList(data, 0, 0);
        
        // actionIni is sent when the GoT HUD has been attached or reset. At this point no API connections will be bound. We set up to start receiving messages again. actionIni is sent as a llRegionSay, it is received regardless of if the mod is previously bound.
        if(action == GotAPI$actionIni){
            GotAPI$bindThis(id);
        }
        
        // actionEvent is received whenever an event has been raised within the GoT HUD. This will happen very frequently and is where you program your mod.
        else if(action == GotAPI$actionEvt){
            // This is basically just the onEvt event received as JSON array
            string script = llList2String(data, 0);         // Name of the script that raised event
            integer evt = llList2Integer(data, 1);          // ID of the event defined in above script's header file
            data = llJson2List(llList2String(data, 2));     // Data tied to the event
            
            // This is where you put your mod logic.
            
        }
        
    }
    
}