Ally Soldier AI Help?

Making a sort of army tycoon with a twist, when enemies meet, you get an alert and play as a soldier in the fight.
I need help with cloning objects without breaking the script, as each ally and each enemy have item weapons, which when they fall, the weapon drops for a player, enemy npc or ally npc to pick up.

Or another soldier carrying a medkit can heal the fallen soldier.
My issue is mainly how the clones will detect cloned objects, as I'm worried they'll only look for the original items, or when picking up items, will send the items to the template soldier that sits in the void, with the original weapons by his side.


My issue is mainly how the clones will detect cloned objects, as I'm worried they'll only look for the original items, or when picking up items, will send the items to the template soldier that sits in the void, with the original weapons by his side.

Generally, you don't want to use object names in a function.

You can use something like:

FilterByAttribute (ScopeVisibleForRoom (room), "prototype", soldier)

to get a list of all clones of "soldier" in a given "room".

If you're having NPCs do something, you will generally be going over a list with foreach. In which case you always use the loop variable, not the actual object name.

If you're thinking about verbs, or other scripts which are part of a particular object, you can use the special variable this to refer to the current clone. this always refers to the object whose script is running. (So in a verb, this is the specific clone that the player can see)

When the player takes over a different character using ChangePOV or similar, always use game.pov to refer to the current player object.

If you have any more specific problems, I think a lot of people would be happy to help.


may i please have a simpler explanation?


When searching for cloned objects, do NOT use the name.
Filterbyattribute
Returns a new object list containing only the objects in the given list for which the named attribute has the given value (which can be of any type).
https://docs.textadventures.co.uk/quest/functions/filterbyattribute.html
Foreach
foreach (iterator variable, list) { script }
Run a script for each item in a list. If the list is a dictionary, the loop iterates over the dictionary keys.
https://docs.textadventures.co.uk/quest/scripts/foreach.html
A loop variable is just a variable that loops... It repeats itself.
"this" is a very special stand in for a noun.

SpawnMonster (this)
player.parent = this.to
this.hitpoints = this.hitpoints - game.pov.attack

Are all instances of "this".
He's right, use game.pov when you can.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums