SYSEVENT_ENTERED_AREA on item control script

Here you can post threads specific to the current release of the core (099)

Moderator: POL Developer

Post Reply
DevGIB
Grandmaster Poster
Posts: 197
Joined: Mon Feb 06, 2006 6:12 am

SYSEVENT_ENTERED_AREA on item control script

Post by DevGIB » Sat Sep 17, 2016 7:28 pm

Hi All,
Been searching the forums and only found 1 reference to it with no answer given.
I'm trying to apply a SYSEVENT_ENTERED_AREA on an item control script so that when players walk within range of a camp fire it triggers something.
At the moment from what i can see its doing the while loop and waiting for an even but at the end of the wait there is no event received even though a player has walked within the range defined.

Is there a specific reason why SYSEVENT_ENTERED_AREA doesn't appear to work on items or am i doing something wrong?

Code: Select all

program townflamecontrol( item ) 
         EnableEvents( SYSEVENT_ENTEREDAREA, 4 );
         
         var ev;
         while( item )
         
                ev := os::wait_for_event( 10 );
                if( ev )
                      if( ev.type == SYSEVENT_ENTEREDAREA )
                                SendQuestArrowEx( ev.source, -1, -1 );
                      endif
                endif
         endwhile
         
         return 1;
endprogram

Nando
POL Developer
Posts: 260
Joined: Wed Sep 17, 2008 6:53 pm
Contact:

Re: SYSEVENT_ENTERED_AREA on item control script

Post by Nando » Sun Sep 18, 2016 12:03 am

If I recall correctly, the ENTEREDAREA event was only sent to NPCs for performance reasons, because there may be too many items in an area. I'm afraid that's an old limitation of POL.

DevGIB
Grandmaster Poster
Posts: 197
Joined: Mon Feb 06, 2006 6:12 am

Re: SYSEVENT_ENTERED_AREA on item control script

Post by DevGIB » Sun Sep 18, 2016 2:22 am

I guess there could be just as many NPC's in an area, but i understand that there might be limitations.
I just wanted to make sure that i wasn't missing something basic. I'm sure i can work out a different way of handling things just the entered area would be worked well for what i wanted.

User avatar
CWO
POL Expert
Posts: 1140
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA
Contact:

Re: SYSEVENT_ENTERED_AREA on item control script

Post by CWO » Sun Sep 18, 2016 6:35 pm

What's the range that you want to search, how many of these items would exist, and how instant does the reaction need to be? You can probably pull it off using ListMobilesNearLocation with about a second or two of sleep between checks.

DevGIB
Grandmaster Poster
Posts: 197
Joined: Mon Feb 06, 2006 6:12 am

Re: SYSEVENT_ENTERED_AREA on item control script

Post by DevGIB » Mon Sep 19, 2016 2:17 am

Item count: approx 10.
Range: approx 3-4.
Response time: fairly quick.

Effectively what you've suggested is what I ended up doing. It works fine for now :)

If i wanted to be crazy technical i could have it spawn an invisible NPC which carried out the function but that just seems overkill.

Nando
POL Developer
Posts: 260
Joined: Wed Sep 17, 2008 6:53 pm
Contact:

Re: SYSEVENT_ENTERED_AREA on item control script

Post by Nando » Mon Sep 19, 2016 11:54 am

It's an old design decision, I assume it would require some big code changes at the moment. Probably at the time the cost of updating the events each time an item was added/removed from the world was considered too high. Or just no one thought about it... :P

Yukiko
Distro Developer
Posts: 2480
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: SYSEVENT_ENTERED_AREA on item control script

Post by Yukiko » Mon Sep 19, 2016 9:28 pm

Given today's processor speeds I imagine the overhead of adding that event to items shouldn't be a problem. The Devs would know better about this but it seems to me that having a script scan for mobiles in a range would take about as much time.

We're talking about players entering the area here. Is there a way to specify some sort of flag to differentiate between mobile types, ie. NPCs and players? That might reduce overhead since the entered area event would be looking for only characters that are players. I've thought it odd that this was only limited to NPCs but I'm sure Nando is right that it was either a design oversight or the original though was to reduce overhead.
Sincerely,
Yukiko

I would tell you a UDP joke but you might not get it.

Titus 2:13

OWHorus
Master Poster
Posts: 95
Joined: Sat Feb 04, 2006 1:24 pm
Location: Vienna, Austria

Re: SYSEVENT_ENTERED_AREA on item control script

Post by OWHorus » Tue Jan 03, 2017 2:50 pm

Hello,

I would like a special POL object with a control script which acts like a NPC and supports EnteredArea-Events. It is not necessary that every item supports this.

I am using a NPC for exactly this function: I have a miracle-spell which does things to an area, for example it does not allow fighting. This is temporary and limited to a radius around the cast location. I am actually using an invisible NPC with a special NPC-script for this - it works like a charm, but is a bit complicated.

What I did: I created a NPC (human form), and set it invisible, the player will never see it. The NPC-script does not support moving or fighting, it is very simple and does only setup the Area-Events for itself. Then it stands around and applies the effect to every mobile entering its area, and removes it when it leaves the area. It also stores all modified mobiles, and when the effect ends, it removes it from all remaining mobiles and deletes itself.

This could be a solution to your problem, but not a very elegant one I admit...

OWHorus

guialtran
Adept Poster
Posts: 84
Joined: Wed Jul 30, 2008 12:42 pm

Re: SYSEVENT_ENTERED_AREA on item control script

Post by guialtran » Thu Jan 05, 2017 5:09 am

sorry about my English.

How are you starting the script on this item?

NpcTemplate AlfredNobel
{
//Name (string paperdoll name)
//ObjType (integer body model type)
//Script (string AI script) <<<<<<<< THISS


This is a special script that only has in the NPC.

Item 0x7778
{
//Name (string unique object name)
//Graphic (int tile number)
//[Color (int color {default 0})]
//[Facing (int facing {default 0})]
//[Desc (string description {default empty})]
//[Tooltip (string tooltip {default empty})]
//[WalkOnScript (string scriptname)]
//[Script (string scriptname)] <<< This script is only called when you click on the item.

So you have to look for a script that runs at the beginning of the server, to always be in it

Item (objtype)
{
Name (string unique object name)
[Name...]
Graphic (int tile number)
[Color (int color {default 0})]
[Facing (int facing {default 0})]
[Desc (string description {default empty})]
[Tooltip (string tooltip {default empty})]
[WalkOnScript (string scriptname)]
[Script (string scriptname)]
[EquipScript (string scriptname)]
[UnequipScript (string scriptname)]
[ControlScript (string scriptname)] <<<<<<<this
Last edited by guialtran on Thu Jan 05, 2017 6:20 am, edited 1 time in total.

guialtran
Adept Poster
Posts: 84
Joined: Wed Jul 30, 2008 12:42 pm

Re: SYSEVENT_ENTERED_AREA on item control script

Post by guialtran » Thu Jan 05, 2017 5:27 am


Post Reply