Jump to content

Food Dispenser.


JJValero Writer
 Share

You are about to reply to a thread that has been inactive for 2675 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Just what tittle says. This only work with food that dissapear when it is over.

 

// Do not deed with group this script or you will not be able to make it work.
// Unless if you remove owner detection in touch events.


// Modify this constants as your needs.
float TIME_TO_CHECK = 10.0; // Every how many seconds check if there are food.
vector RELATIVE_POS = <0.0, 0.0, 0.25>; // Position relative to rezzer.
integer WARNING_IF_LESS = 2;  // Send IM to owner if there are less items in inventory.


//-----------------------------------------------------------------------------
// Do not modify below this line. Unless you know what are you doing.

integer PARAM = 0;  // Param to pass to the object to rezz.
key gFoodRezzed;



rezzFood() {
    
    llRezObject(
        llGetInventoryName(INVENTORY_OBJECT, 0),
        llGetPos() + RELATIVE_POS,
        ZERO_VECTOR, 
        ZERO_ROTATION, 
        PARAM);
    
} // rezzFood


default {
    
    state_entry() {
        
        gFoodRezzed = NULL_KEY;
        if (llGetInventoryNumber(INVENTORY_OBJECT) == 0) {
            llOwnerSay("No food in inventory. Please, put food in inventory and clickme.");
            state stopped; 
        } else {
            state working;
        } // if

    } // state_entry

} // default

state stopped {
    
    state_entry() {

    } // state_entry
    
    on_rez(integer start_param) {
        
        llResetScript();
        
    } // on_rez
    
    touch_start(integer total_number) {
        
        if (llDetectedKey(0) != llGetOwner()) {
            return;    
        } // if
        
        if (llGetInventoryNumber(INVENTORY_OBJECT) == 0) {
            llOwnerSay("Please, put food in inventory and clickme again.");
        } else {
            state working;
        } // if
        
    } // touch_start
    
    // Bug around. This is needed.
    touch_end(integer total_number) {
    } // touch_end
    
} // stopped

state working {
    
    state_entry() {
        
        if (gFoodRezzed == NULL_KEY) {
            rezzFood();
        } else {
            llSetTimerEvent(TIME_TO_CHECK);
        } // if

    } // state_entry
    
    state_exit() {
        
        llSetTimerEvent(0.0);
        
    } // state_exit
    
    on_rez(integer start_param) {
        
        llResetScript();
        
    } // on_rez
    
    object_rez(key id) {
        
        gFoodRezzed = id;
        if (llGetInventoryNumber(INVENTORY_OBJECT) < WARNING_IF_LESS) {
            llInstantMessage(llGetOwner(), "Food is scarce.");
        } // if
        llSetTimerEvent(TIME_TO_CHECK);
        
    } // object_rez
    
    timer() {
        
        list lDetails = llGetObjectDetails(gFoodRezzed, [ OBJECT_POS ]);
        if (llGetListLength(lDetails) == 0) {
            llSetTimerEvent(0.0);
            if (llGetInventoryNumber(INVENTORY_OBJECT) == 0) {
                llInstantMessage(llGetOwner(), "The food is over.");
                state stopped;
            } else {
                rezzFood();
            } // if
        } // if
        
    } // timer
    
    touch_start(integer total_number) {

        if (llDetectedKey(0) != llGetOwner()) {
            return;    
        } // if
        
        llOwnerSay("Stopping. Touch me again to make horses happy.");
        state stopped;
        
    } // touch_start
    
    // Bug around. This is needed.
    touch_end(integer total_number) {
    } // touch_end
    
    
} // working
  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2675 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...