Solved Enemy type that can get all items

Question that is answered or resolved.

kimono

Well-known member
Hi dear Openbor users, let me introduce you the futuristic hoover :
fbxQb5f.gif

Its mission is to clean the floor to all remaining items (food and gold mainly).
My question is : Can an enemy get gold by itemtouch and food (I know this is possible but can't find the command) ?
 
Last edited:
Solution
Hi dear Openbor users, let me introduce you the futuristic hoover :
fbxQb5f.gif

Its mission is to clean the floor to all remaining items (food and gold mainly).
My question is : Can an enemy get gold by itemtouch and food (I know this is possible but can't find the command) ?
@kimono

About the "get" method, I think that it can be solved by adding the subtype "touch" in all item entities, and then it can be taken by both player and enemy by touching.
About the "detection" method, food and weapons are automatically detectable by enemies, but it will not work for "score" items like "gold" or "cash" as DC said.

However, there's a trick to make "score" items detectable by enemies. All you need to do...
Enemies and NPCs that have a Get animation can (and will) seek out food or weapons to pick up. In the case of a weapon, they'll ignore weapons they can't use.

I don't know of any way to make them pick up other items without script.

DC
 
Hi dear Openbor users, let me introduce you the futuristic hoover :
fbxQb5f.gif

Its mission is to clean the floor to all remaining items (food and gold mainly).
My question is : Can an enemy get gold by itemtouch and food (I know this is possible but can't find the command) ?
@kimono

About the "get" method, I think that it can be solved by adding the subtype "touch" in all item entities, and then it can be taken by both player and enemy by touching.
About the "detection" method, food and weapons are automatically detectable by enemies, but it will not work for "score" items like "gold" or "cash" as DC said.

However, there's a trick to make "score" items detectable by enemies. All you need to do is to add a "health" value after the "score" property at the entity's header.

Code:
name            Gold
type            item
score            5000
health            200
nolife            1
facing             1
shadow            1
offscreenkill    50
ondrawscript    data/scripts/ondraw/items.c
animationscript    data/scripts/animation/default.c
script            data/scripts/updateentity/items.c

The engine will make it work like a normal "score" item because this property comes in first place. The "health" property will make this item detectable by enemies if their life is lower than the maximum, but will not fill life because this feature will remain disabled. I didn't test but I think that you can use "mp" instead of "health" too.

In short, this way the engine will make enemies look for gold items too thinking it's a food item, and will get them.

In addition, there's some functions related to items that aren't in the manual. They are "pickup" and "finditem". In case you don't want to add the subtype "touch", you can combine these two functions to force the entity to get items.

C:
void self    = getlocalvar("self");
void item    = finditem();

if(item){
    pickup(self, item);
    setidle(self, openborconstant("ANI_IDLE"));
}

The "finditem" works like "findtarget" and will return the closest item detected. The "pickup" will force the item to be taken no matter the distance, but it will only work for "valid" items that are on the screen.

Tip: You can use the "finditem" to detect other properties, like animation or position, and then use the "pickup" function only if a previous defined rule is reached.

Once the script works, the entity will play the "get" animation but you can use any other if you want. The "setidle" function also works in this case.

One more thing, you can use "spawn" and "pickup" in the same code, this way you can simulate an item "get" function. I'm using this trick in SORX to allow weapons to be picked up on the air, once the player gets the weapon name, it will be spawned again and will run the "pickup" function immediately.
 
Solution
@Kratus and @xyz555: I solved the problem thanks to Kratus and his marvelous trick :) . I put the following script in the hoover anim spawn:
Code:
@script
    void self = getlocalvar("self");
    int Health = getentityproperty(self, "health");
    if(frame==1){
      changeentityproperty(self, "health", Health-1);
    }
@end_script
The hoover has 1 less healthpoint so it will begin to search some fake healing items. Considering that I've got a npc ally in this level, the hoover won't stay quiet and will continue to search and get items. This is very funny to see him running over these items. Thank you very much for the help and I will release a game update soon for those who want to try this mechanism ;) .
 
@kimono, If you want to mark something solved, please use the Solved prefix. Don't type "Solved" into the title. I fixed the thread so you can see what I mean.

DC
 
The hoover enemy works very well but I wish that the anim get is played everytime it touches and get the item. Here's its anim get:
Code:
anim    get
    loop    1
    delay    3
    offset    71 57
    bbox 0 -4 100 61
    frame    data/chars/hoover/get1.png
    frame    data/chars/hoover/get2.png
    frame    data/chars/hoover/get3.png
    frame    data/chars/hoover/get4.png
    frame    data/chars/hoover/get5.png
    frame    data/chars/hoover/get6.png
 
The hoover enemy works very well but I wish that the anim get is played everytime it touches and get the item. Here's its anim get:
Code:
anim    get
    loop    1
    delay    3
    offset    71 57
    bbox 0 -4 100 61
    frame    data/chars/hoover/get1.png
    frame    data/chars/hoover/get2.png
    frame    data/chars/hoover/get3.png
    frame    data/chars/hoover/get4.png
    frame    data/chars/hoover/get5.png
    frame    data/chars/hoover/get6.png
In this case, I suggest you to remove the "setidle" line from the script I posted before.
I saw a "loop" in your "get" animation, maybe it will cause the character to stay forever.
 
@Kratus: Thanks for you eagle eye quick look on loop 1 in anim get ;) . I tried to integer this script like this but it doesn't seem to work:

Code:
anim    spawn
    delay    10
    offset    71 57
    sound    data/voice/hoover_spawn.wav
@script
    void self = getlocalvar("self");
    int Health = getentityproperty(self, "health");
     void item    = finditem();
    if(frame==1){
      changeentityproperty(self, "health", Health-1);
    }    
    if(item){
    pickup(self, item);
    }   
@end_script    
    frame    data/chars/hoover/stand1.png
    frame    data/chars/hoover/stand2.png
    frame    data/chars/hoover/stand3.png
    frame    data/chars/hoover/stand4.png
    frame    data/chars/hoover/stand5.png
    frame    data/chars/hoover/stand6.png

The 1.2 update game file:
 
I tried to integer this script like this but it doesn't seem to work
@kimono

Sorry, it's my fault. I forgot to add the "self" in my previous code, same as in the "findtarget" function.
Another thing I forgot to say, in my tests the function "finditem" worked only for enemy/npc entities, not for players.

C:
void item = finditem(self);
 
Ok so I reorganized the script like this but it's an item touch function so no get animation is played during this action:
Code:
anim    spawn
    delay    10
    offset    71 57
    sound    data/voice/hoover_spawn.wav
@script
    void self = getlocalvar("self");
    void item = finditem(self);    
    int Health = getentityproperty(self, "health");
    if(frame==1){
     changeentityproperty(self, "health", Health-1);
    }    
    if(item){
    pickup(self, item);
    }   
@end_script    
    frame    data/chars/hoover/stand1.png
    frame    data/chars/hoover/stand2.png
    frame    data/chars/hoover/stand3.png
    frame    data/chars/hoover/stand4.png
    frame    data/chars/hoover/stand5.png
    frame    data/chars/hoover/stand6.png
How can I force to play the anim get after picking an item after touching it?
 
I tried several things like:
Code:
    if(item){
    pickup(self, item);
    performattack(getlocalvar("self"), openborconstant("ANI_FOLLOW1"));    
    } 

anim    follow1
    delay    10
    offset    71 57
    bbox 0 -4 100 61
    frame    data/chars/hoover/get1.png
    frame    data/chars/hoover/get2.png
    frame    data/chars/hoover/get3.png
    frame    data/chars/hoover/get4.png
    frame    data/chars/hoover/get5.png
    frame    data/chars/hoover/get6.png

The animation still doesn't want to play after picking an item :/ . I'm sorry to disturb you about that.
 
I didn't do too many tests with subtype touch, but now I remember that you will need to invert the order for touch items.
Did some tests now on SORX with both performattack and executeanimation, worked well.

C:
if(item){
    performattack(self, openborconstant("ANI_GET"), 1);
    pickup(self, item);
}
 
Thanks Kratus for this script solution at anim idle and walk:
Code:
@script
    void self = getlocalvar("self");
    void item = finditem(self);   
    int Health = getentityproperty(self, "health");
    if(item){
        changeentityproperty(self, "health", Health-1);
        pickup(self, item);
        executeanimation(self, openborconstant("ANI_GET"), 1);
    }
@end_script
 
I didn't do too many tests with subtype touch, but now I remember that you will need to invert the order for touch items.
Did some tests now on SORX with both performattack and executeanimation, worked well.

Just a quick explanation on this:

Trying to acquire an item entity on pick up always fails because of the way items are handled internally. Weapon items are moved to a hidden location (this is explained in depth elsewhere), but all other item types are destroyed immediately. In other words, by the time your script runs there's no item to find.

As you've noted, the solution is to acquire the item in your script before it's collected instead of after.

DC
 
Back
Top Bottom