User:BUTTONpUSHER Jones/pet protocol/OBEY

From Second Life Wiki
Jump to navigation Jump to search
// OBEY function
// Any incoming commands are sent to this function. This script determines
// if the command will be obeyed based on values from the pet's behavior
// setup. If the command will be obeyed, it will be sent out to the other
// scripts in the pet.
// there are 5 parameters for the obey variable, each ranging from 0 to 1. 
// threat, neutral, prey, owner, other avatar
// if the parameter is 0, the pet will never obey a command from something
// in that class, if it's 1 the pet will always obey that command.

integer DEBUG = TRUE; // if TRUE, chat results to the owner.

obey1 ( string command, string this_pet, string other )
{
    // test if commander is a threat
    if ( llList2Float(other,fight) > this_pet.flee )
    {
        if (llList2Float(obey,1) > llFrand(1)) // calculate chance of obeying the command
        {
            if(DEBUG)llOwnerSay(":OBEY: case 1 passed. fix this logic? passed");
            llMessageLinked(command);
        }
        else
        {
            if(DEBUG)llOwnerSay(":OBEY: case 1 failed");
        }
    }
    // neutral
    if ( other.fight > this_pet.flee )
    {
        if (llList2Float(obey,2) > llFrand(1)) // calculate chance of obeying the command
        {
            if(DEBUG)llOwnerSay(":OBEY: case 2 passed. fix this logic? passed");
            llMessageLinked(command);
        }
        else
        {
            if(DEBUG)llOwnerSay(":OBEY: case 2 failed");
        }

    }
    // prey
    else if ( this_pet.fight > other.flee )
    {
        if (llList2Float(obey,3) > llFrand(1)) // calculate chance of obeying the command
        {
            if(DEBUG)llOwnerSay(":OBEY: this_pet.fight > other.flee passed");
            llMessageLinked(command);
        }
        else
        {
            if(DEBUG)llOwnerSay(":OBEY: this_pet.fight > other.flee failed");
        }
    }
    // owner
    else if ( other == gOwner )
    {
        if (llList2Float(obey,4) > llFrand(1)) // calculate chance of obeying the command
        {
            if(DEBUG)llOwnerSay(":OBEY: other == gOwner");
            llMessageLinked(command);
        }
        else
        {
            if(DEBUG)llOwnerSay(":OBEY: other == gOwner failed");
        }
    }
    //other
    else if ( other != gOwner )
    {
        if (llList2Float(obey,5) > llFrand(1)) // calculate chance of obeying the command
        {
            if(DEBUG)llOwnerSay(":OBEY: other != gOwner");
            llMessageLinked(command);
        }
        else
        {
            if(DEBUG)llOwnerSay(":OBEY: other != gOwner failed");
        }
    }
}

default
{
    state_entry()
    {
        llOwnerSay(":OBEY scripts started");
    }
}