Full Version : how to have npc detect nearby items?
xmlspawner >>Q&A >>how to have npc detect nearby items?


<< Prev | Next >>

Xerocrates- 10-10-2007
Hi, a little question:


where I can find the list of various Actions/condictions aviable on xmledit?


I would make a npc wandering for human body pieces, but i have no idea how say to him "if you see a <itemname> take them"


sorry for my very horrible english tongue.gif

hope you're undestand what i have write...


tnx for the help smile.gif

ArteGordon- 10-10-2007
They are the basically all of the same actions and conditions that can be used in spawner entries.

QUOTE

- value keywords: RND, RNDBOOL, RNDLIST, RNDSTRLIST, RANDNAME, INC, MUL, MOB, SERIAL, SKILL
- control keywords: WAITUNTIL, IF, WHILE, and GOTO
- action keywords: ADD, EQUIP, GIVE, TAKE, TAKEBYTYPE, CAST, SAY, MSG, SENDMSG, BCAST, RESURRECT, POISON, DAMAGE, MUSIC, EFFECT, MEFFECT, SOUND, GUMP, DESPAWN, DELETE, KILL, ANIMATE, OFFSET, BROWSER
- loot keywords: ARMOR, WEAPON, JEWELRY, JARMOR, JWEAPON, SARMOR, SHIELD, LOOT, LOOTPACK, POTION, SCROLL, NECROSCROLL, TAKEN, GIVEN, ITEM
- access keywords: GET, GETONTHIS, GETONPARENT, GETFROMFILE, GETONSPAWN, GETONCARRIED, GETONMOB, GETONTRIGMOB, GETONNEARBY, SET, SETONTHIS, SETONPARENT, SETONSPAWN, SETONSPAWNENTRY, SETONCARRIED, SETONMOB, SETONTRIGMOB, SETONNEARBY, PLAYERSINRANGE, TRIGSKILL, AMOUNTCARRIED


So to check for nearby items, you could use the GETONNEARBY keyword in a condition. To do things to nearby items you could use the SETONNEARBY keyword in an action.

To delete nearby body parts, use an action like

SETONNEARBY,3,*,head/DELETE

SETONNEARBY,range,name[,type][,searchcontainers][,proptest]/prop/value/prop/value...

But note that to trigger xmldialogs you need to have players nearby so it wouldnt work if the npc was alone. Of course, the default AI also doesnt run unless there are players nearby (unless you change the playerrangesensitive setting).

Xerocrates- 10-10-2007
tnx smile.gif

Xerocrates- 10-11-2007
I culdn't make work that...


GETONNEARBY,5,*,Head

the mob doesn't see the condiction true...

What's wrong?

ArteGordon- 10-11-2007
a condition requires that you test a property, like this

GETONNEARBY,5,*,Head,visible=true

QUOTE

- added the 'GETONNEARBY,range,name[,type][,searchcontainers],property' keyword that can be used to get or test properties on nearby items or mobiles.  This can be used in property assignments or property tests.  If more than one of the specified object is found, it will only return the value from one.

For example, to test to see if someone has placed the longsword named "Grizzleblag" on the ground near the spawner you could use a condition test like

GETONNEARBY,1,Grizzleblag,longsword,visible=true

Or you could get the size of a pile of gold in a nearby container with

SENDMSG/{GETONNEARBY,1,,gold,true,amount} gold pieces are in the container


Xerocrates- 10-11-2007
pork....


ehm.. hum... hee... ops...


tnx tongue.gif

Xerocrates- 10-11-2007
dha.. nothing... it doesn't work...

isin't a syntatx error, i have cut/copied


condiction:SETONNEARBY,5,*,head,visible=true
Text: I'm the best woman in the world


nothing... i'm flagged player, the head is nearby...

if i use any other condiction work...

ArteGordon- 10-11-2007
QUOTE

condiction:SETONNEARBY,5,*,head,visible=true

you need to use GETONNEARBY here, not SETONNEARBY.

Also, you might want to set the ResetTime to something less than the default of 1 minute.

(edit)

I think that there is an issue with the use of GETONNEARBY in an xmldialog that may be preventing it from working. It is assuming a spawner as a location reference and when used as an action in an attachment there is no spawner. I'm looking into it and will post a fix.

(edit)

fixed in BaseXmlspawner.cs and posted to the v3.23 beta.
http://xmlspawner.15.forumer.com/index.php...3&st=0#entry115

Xerocrates- 10-11-2007
yes getonnearby i have write wrong, but in the condiction field i have write getonnearby...


i see if i can make work that..

Xerocrates- 10-14-2007
hum...

one insolit question:


there is another way to correct this bug without upgrade at xmlspawner 2? the server where i play cant upgrade at the second xml because it run on a mod of runUO...



ArteGordon- 10-14-2007
the fix is the following change in basexmlspawner.cs around line 4250 if you want to make it manually

QUOTE

                        else if ((kw == valueKeyword.GETONNEARBY) && arglist.Length > 3)
                        {
                            // syntax is GETONNEARBY,range,name[,type][,searchcontainers],property
                            // or GETONNEARBY,range,name[,type][,searchcontainers],[ATTACHMENT,type,name,property]

                            string targetname = arglist[2];
                            string propname = arglist[3];
                            string typestr = null;
                            bool searchcontainers = false;
                            int range = -1;
                            try
                            {
                                range = int.Parse(arglist[1]);
                            }
                            catch { }

                            if (arglist.Length > 4)
                            {
                                typestr = arglist[3];
                                propname = arglist[4];
                            }

                            if (arglist.Length > 5)
                            {
                                try
                                {
                                    searchcontainers = bool.Parse(arglist[4]);
                                }
                                catch
                                {
                                }
                                propname = arglist[5];
                            }

                            Type targettype = null;
                            if (typestr != null)
                            {
                                targettype = SpawnerType.GetType(typestr);
                            }

                            if (range >= 0)
                            {
                                // get all of the nearby objects
                                object relativeto = spawner;
                                if (o is XmlAttachment)
                                {
                                    relativeto = ((XmlAttachment)o).AttachedTo;
                                }

                                ArrayList nearbylist = GetNearbyObjects(relativeto, targetname, targettype, typestr, range, searchcontainers, null);[/color]

                                // apply the properties from the first valid thing on the list
                                foreach (object nearbyobj in nearbylist)
                                {
                                    string getvalue = GetPropertyValue(spawner, nearbyobj, propname, out ptype);
                                    return ParseGetValue(getvalue, ptype);
                                }
                            }
                            else
                                return null;
                        }
.

Xerocrates- 10-14-2007
My Hero *_*

tnx smile.gif