Hi dear Openbor users, let me introduce you the futuristic hoover :
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.