Author Topic: How to make the Beggar take up itens automatically on the ground?  (Read 993 times)

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #15 on: March 10, 2014, 09:56:16 pm »


               You can force a series of actions to run without interruption:

Action...
Action...
ActionDoCommand(SetCommandable(TRUE));
SetCommandable(FALSE);

               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #16 on: March 10, 2014, 10:15:48 pm »


               

OK, the final OnUnacquireItem script working correctly ( with some changes):



void doPickupItem(object oItem)
{
    ActionMoveToObject(oItem, TRUE); // TRUE to RUN
    ActionPickUpItem(oItem);
    return;
}

void main()
{
//... Your UnacquiredScript

// Beggar Pick up item system
   object oItem = GetModuleItemLost();
   object oPC = GetModuleItemLostBy();
    object oActualPossessor = GetItemPossessor(oItem);

    if (!GetIsObjectValid(oActualPossessor))
    {
        object oBeggar = GetNearestObjectByTag("YourTAGBeggar", oPC);
        if (GetIsObjectValid(oBeggar))
        {
            SetAILevel(oBeggar, AI_LEVEL_VERY_LOW);
            AssignCommand(oBeggar, ClearAllActions());
            DelayCommand(5.0, AssignCommand(oBeggar, doPickupItem(oItem))); // don't remove this delay
            DelayCommand(18.0, SetAILevel(oBeggar, AI_LEVEL_DEFAULT));
            return;
        }
    }
}

Thanks to Pstemarie.



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #17 on: March 10, 2014, 10:21:55 pm »


               


You can force a series of actions to run without interruption:



Action...
Action...
ActionDoCommand(SetCommandable(TRUE));
SetCommandable(FALSE);



Proleric,


No, can't setting commandable because if stuck can't pick up item. 


 


Pstemarie,


 


OK, this is working well. And if the Beggar saw a item already dropped? The beggar is walking and saw a item on ground, he can't pick up this ):


 


EDITED: The Mad Poet has something intersting on your script code Fairy Trash: object oItem = GetNearestObject(OBJECT_TYPE_ITEM);


Can we use this to make Beggar pick up whatever item on the ground?



               
               

               


                     Modifié par WhiteTiger, 10 mars 2014 - 10:26 .
                     
                  


            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #18 on: March 10, 2014, 10:57:37 pm »


               
Sorry about the error in the original script - hadn't finished my coffee yet. Anyway, what I missed were the calls for SetCommandable to disable the ambient system while the Beggar was getting loot. Thanks for catching that, Proleric. Anyway here is a fully functional version of the script to cut into your module's UnAcquire event. I used the HotU event - x2_mod_def_unaqu.nss - as a base, so the variables conform to that.

 

Whenever a PC drops an item the Beggar moves to it, stoops and picks it up, then moves off. I reduced the time the animation plays to 2.0 seconds because 4 second seemed too long. I have also dropped multiple items and the action queue for the Beggar stacked - he went to the first item and picked it up, then the second item and picked that up, and so on.

 



//insert the following code into x2_mod_def_unaqu.nss
 
void doPickupItem(object oItem)
{
    ActionMoveToLocation(GetLocation(oItem));
    ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0, 2.0);
    ActionPickUpItem(oItem);
    ActionDoCommand(SetCommandable(TRUE));
    SetCommandable(FALSE);
}
 
void main ()
{
     //existing code
 

    // * Looting Beggar Custom Code
    if (!GetIsObjectValid(oOwner)) //confirm item was dropped - might be better way to do this
    {
        object oBeggar = GetNearestObjectByTag("LOOT_BEGGAR", oPC);
        if (GetIsObjectValid(oBeggar))
        {
            AssignCommand(oBeggar, ClearAllActions());
            AssignCommand(oBeggar, doPickupItem(oItem));
        }
    }     

}

For picking up items just laying around in the area, you need to do a similar script as this in the Beggar's OnPerception or OnHeartbeat event. I would recommend OnPerception if you can get that working right.



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #19 on: March 10, 2014, 11:08:31 pm »


               

Will OnPerception work for seeing an item?



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #20 on: March 10, 2014, 11:37:22 pm »


               

Pstemarie, 


 


1.It's unnecessary use ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0, 2.0); because the next action already have this included ActionPickUpItem(oItem);


 


So we do not have the delay. Why delay?


 


2.To be more realist, add 05 secs delay waiting before Beggar walk to pick up item.


 


I would like to check if the beggar acquired item or if the player was in front of him and blocked the action. Well, he could try to take the item back if it is not in your inventory.


 


henesua,


 


Proleric says (on the top) that OnPerception event is only for creatures and not for itens.



               
               

               


                     Modifié par WhiteTiger, 10 mars 2014 - 11:57 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #21 on: March 10, 2014, 11:49:06 pm »


               

you could do this in OnHeartbeat. A couple ways to insert the code in OnHeartbeat. In a default OnHeartbeat (not recommended unless this behavior is common), in a unique OnHeartbeat for the beggar (easiest), in a User Defined OnHeartbeat add on that you switch on for the beggar.


 


Which ever of those three options you decide to use for this special heartbeat code, the code itself would probably need to be a GetFirstObjectInShape  ---> GetNextObjectInShape loop looking for items, and responding to the first one it sees. I'd use a sphere shape with a tight radius.


 


 


Another option that may or may not be of interest to you is to generate a silent shout when an item is dropped in an area. And then in the Beggar's onconveration script provide a hook for responding to that shout. You would also want to tell the beggar to listen for this particular shout during the OnSpawn event. You'd need to fiddle with the item putting out a shout, or if that does not work creating a framework that tells the hearer of the shout the object reference of the item dropped.



               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #22 on: March 11, 2014, 01:27:41 am »


               


Will OnPerception work for seeing an item?




 


After further research, no, GetObjectSeen does not work for items - it only works for creatures. Therefore, you'd have to scan the area for items laying on the ground at regular intervals (i.e. via the creature's or module's Heartbeat) and then have the Beggar pick them up. Combined with the OnUnAcquire script from above, it should take care of cleaning an area.


               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #23 on: March 11, 2014, 01:34:04 am »


               


Pstemarie, 


 


1.It's unnecessary use ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0, 2.0); because the next action already have this included ActionPickUpItem(oItem);


 


So we do not have the delay. Why delay?


 


2.To be more realist, add 05 secs delay waiting before Beggar walk to pick up item.


 


I would like to check if the beggar acquired item or if the player was in front of him and blocked the action. Well, he could try to take the item back if it is not in your inventory.




 


I missed that - you can tell I don't use these specific actions that often. Anyway, the function now looks like this...



void doPickupItem(object oItem)
{
    ActionForceMoveToLocation(GetLocation(oItem));
    ActionPickUpItem(oItem);
    ActionDoCommand(SetCommandable(TRUE));
    SetCommandable(FALSE);
}

No need for a delay in the function because its now a forced action stack - ActionPickUpItem() will only execute AFTER ActionForceMoveToLocation() is finished - thanks to the addition of SetCommandable(). As for the rest - if the PC blocked the action, you seem pretty capable and I'm certain you'll figure that part out '<img'>



               
               

               
            

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #24 on: March 11, 2014, 01:53:09 am »


               

Solution: 


 


FloatingTextStringOnCreature(oPC, "Stop making this hard on me!", TRUE);


ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDeath(TRUE), oPC);


 


That'll teach 'em!



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #25 on: March 11, 2014, 03:59:07 am »


               

Yeah, add 05 seconds of delay to start all actions with Beggar.


PC drop the item. 


Beggar Artificial Intelligence is disabled.So We have 5 seconds delay  of nothing action. After this 5 seconds, the beggar start MoveToObjectItem and PickUpItem Action. To finish Give default AI again. It's more realistic.



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #26 on: March 12, 2014, 09:15:34 pm »


               

Well, now we have a perfect script for what we want. This works for any item that is on the ground and no matter how the item appeared on the ground.


 


Add this to Creature Beggar OnHeartBeat Event - specifically (save as a copy if you're using the original onheartbeat script).



//////////////////////////////////////////////////////////////
/////////////////////SCRIPT By WhiteTiger/////////////////////
//////////////////////////////////////////////////////////////

    //START Beggar - Pick Up Item System
            object oAllBeggar = OBJECT_SELF;
            if (GetObjectType(GetNearestObject(OBJECT_TYPE_ITEM)))
    {
        AssignCommand(oAllBeggar, ClearAllActions());
        AssignCommand(oAllBeggar, ActionPickUpItem(GetNearestObject(OBJECT_TYPE_ITEM)));
        return;
    }
    //END

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////

Thanks all.



               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #27 on: March 12, 2014, 11:53:58 pm »


               

If you have a lot of these beggars, that Heatbeat event is gonna eat up resources.



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #28 on: March 13, 2014, 12:08:19 am »


               

I recommend you change the code to the following:



    //START Beggar (OBJECT_SELF) - Pick Up Item System
    object oItem    = GetFirstObjectInShape(SHAPE_SPHERE, 12.5, GetLocation(OBJECT_SELF), TRUE, OBJECT_TYPE_ITEM);

    if(oItem!=OBJECT_INVALID)
    {
        ClearAllActions();
        ActionPickUpItem(oItem);
    return;
    }
    //END

In addition that code snippet should probably execute in a userdefined heartbeat event unless this Beggar heartbeat event script, only executes on beggars.



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to make the Beggar take up itens automatically on the ground?
« Reply #29 on: March 13, 2014, 12:29:12 am »


               

Pstemarie,


Are you saying about a lot of Beggars working in all game or area?