Author Topic: determine if player has clicked inside a trigger ?  (Read 608 times)

Legacy_azaz1234

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
determine if player has clicked inside a trigger ?
« on: November 10, 2015, 02:35:48 am »


               

title pretty much says it. i'd like to be able to figure out if the location clicked on by a player's mouse click happens to be inside a trigger. the application is a custom feat, where the feat's spell script is run at the clicked-on location and must determine if the target lies somewhere within the trigger. anyone know how i could do that ?



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
determine if player has clicked inside a trigger ?
« Reply #1 on: November 10, 2015, 04:15:33 am »


               


title pretty much says it. i'd like to be able to figure out if the location clicked on by a player's mouse click happens to be inside a trigger. the application is a custom feat, where the feat's spell script is run at the clicked-on location and must determine if the target lies somewhere within the trigger. anyone know how i could do that ?




you have to create an object there, atm not sure if it must be creature or if it can be placeable (invis placeable comes to mind), then you can use function GetIsInSubArea to determine that


 


maybe nwnx can do this without workarounds but I dont recall any such function


               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
determine if player has clicked inside a trigger ?
« Reply #2 on: November 10, 2015, 09:01:17 am »


               

I imagine it has to be a creature, because the function relies on the OnEnter and OnExit events.


 


Does it have to be a trigger? If the shape is simple (e.g. rectangle, circle), it might be easier to define its co-ordinates at (say) local float on an invisible placeable, then compare them with the target location.



               
               

               
            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
determine if player has clicked inside a trigger ?
« Reply #3 on: November 10, 2015, 03:51:02 pm »


               

One thing I've found is that simply spawning an invisible creature within a trigger doesn't always/ever fire a trigger's OnEnter event - which is needed for the GetIsInSubArea function or whatever you are planning to do in the trigger's OnEnter script. So if you plan to use the creature method to determine if something is within a trigger, you will likely need to create the creature and then jump it to the spot you want to test. Even if it's spawned in the trigger, jumping it to its same location will then still work to fire the trigger's OnEnter event.



               
               

               
            

Legacy_azaz1234

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
determine if player has clicked inside a trigger ?
« Reply #4 on: November 10, 2015, 04:10:20 pm »


               


you have to create an object there, atm not sure if it must be creature or if it can be placeable (invis placeable comes to mind), then you can use function GetIsInSubArea to determine that


 


maybe nwnx can do this without workarounds but I dont recall any such function




 


i found an nwnx function in nwnx_events.nss that might be interesting for this - GetEventPosition(). in the same file, there is an event type of EVENT_TYPE_USE_FEAT listed. so i'm guessing there could be a way to get the event location of where the player clicks for the feat, but it isn't clear to me how i'd set the event handler for this. the only function i see that looks like it's used to set any event handlers is SetGlobalEventHandler()... i hope this doesn't mean i'd have to write a function to handle events for all feats just to catch this one !  have you ever used any of these functions, shadooow ?


 


 




I imagine it has to be a creature, because the function relies on the OnEnter and OnExit events.


 


Does it have to be a trigger? If the shape is simple (e.g. rectangle, circle), it might be easier to define its co-ordinates at (say) local float on an invisible placeable, then compare them with the target location.




 


no, it doesn't have to be a trigger, specifically. it does have to fulfill the criterion that an event is generated when a player clicks on it, so in theory a placeable would work, except i think it'd need to be active, wouldn't it ?  which means it'd be visible to the player.



               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
determine if player has clicked inside a trigger ?
« Reply #5 on: November 10, 2015, 05:11:25 pm »


               

Just a shot in the dark here, but couldn't you use GetSpellTargetLocation(location lTarget) and compare it with GetLocation(object oTrigger)?



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
determine if player has clicked inside a trigger ?
« Reply #6 on: November 10, 2015, 08:18:44 pm »


               

Assuming  you don't need really irregular shapes for this you may be able to get away with just using a waypoint and checking that the targeted location is within a certain distance of the waypoint.



               
               

               
            

Legacy_azaz1234

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
determine if player has clicked inside a trigger ?
« Reply #7 on: November 10, 2015, 09:03:49 pm »


               


One thing I've found is that simply spawning an invisible creature within a trigger doesn't always/ever fire a trigger's OnEnter event - which is needed for the GetIsInSubArea function or whatever you are planning to do in the trigger's OnEnter script. So if you plan to use the creature method to determine if something is within a trigger, you will likely need to create the creature and then jump it to the spot you want to test. Even if it's spawned in the trigger, jumping it to its same location will then still work to fire the trigger's OnEnter event.




 


wow, talk about jumping through hoops just to make sure it works right. O_O


i'm often as surprised that bioware forgot some of the most basic things as i am about how great the game is.


good info, though, thanks !


 


 




Just a shot in the dark here, but couldn't you use GetSpellTargetLocation(location lTarget) and compare it with GetLocation(object oTrigger)?




 


i'd have to know beforehand what kind of trigger or aoe it is, since GetLocation(object oTrigger) returns the starting coordinate for a polygonal trigger but the centre point for a circular aoe, and the triggers/areas may vary in size and shape.  :/


 


 




Assuming  you don't need really irregular shapes for this you may be able to get away with just using a waypoint and checking that the targeted location is within a certain distance of the waypoint.




 


yeah, i'm beginning to think i should just go back and rework my basic approach to use something other than triggers. waypoints would work, for spherical areas.


 


basically what i'm looking for is a way to add 'terrain awareness' ; to circumscribe a given area, inside of which certain things would be allowed and outside of which they wouldn't. the constraints suggested using a trigger, but obviously that won't work if action has to be carried out at a distance. as an off-the-cuff example, suppose i want to require that casters may summon fire elementals only if a lava source is nearby, or water elementals only if a water source is nearby. i could then place a trigger around a pool of water so that a caster could target the spell within the confines of the trigger (i.e. the pool) and the summons would succeed, but outside it would fail. but apparently there's no way for me to tell if GetSpellTargetLocation() is within the confines of the pool (trigger).


               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
determine if player has clicked inside a trigger ?
« Reply #8 on: November 11, 2015, 05:25:25 am »


               

You could determine whether a PC is inside of a trigger in a round about way still. Use a local integer that is set on enter of the trigger and deleted or changed when leaving it. Then have summons scripts check for such an integer when determining what is called.



               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
determine if player has clicked inside a trigger ?
« Reply #9 on: November 12, 2015, 01:20:15 am »


               If you have access to nwnx - I believe there was a method in nwnx_funcs (maxrocks windows one) that could get the coords of each edge / vertices of the trigger.

With that knowledge, you can through Mathematical wizardry, determine if the GetSpelltargetLocation is inside the trigger

( GetSpellTargetLocation is fired on feats which take target locations and/or target ground positions.)
               
               

               
            

Legacy_azaz1234

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
determine if player has clicked inside a trigger ?
« Reply #10 on: November 12, 2015, 02:39:45 pm »


               


If you have access to nwnx - I believe there was a method in nwnx_funcs (maxrocks windows one) that could get the coords of each edge / vertices of the trigger.

With that knowledge, you can through Mathematical wizardry, determine if the GetSpelltargetLocation is inside the trigger

( GetSpellTargetLocation is fired on feats which take target locations and/or target ground positions.)




 


aha !  that sounds promising. i'll check it out, thanks !



               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
determine if player has clicked inside a trigger ?
« Reply #11 on: November 13, 2015, 01:22:57 am »


               

Don't ask me what mathematical formulae to use.


I am not too good at working geometry out.


 


 


basically:


 


nwnx can give you the x,y,z of the points of the trigger:


 


x                  x


              o


 


x                  x


 


 


With o being the clicking location.


 


You just need to work out a function that can take the positions of each x, and determine if the o is inside.


In C# this can be done via:


http://stackoverflow...oint-in-polygon


 


C# is very similar to nwscript - infact, nwscript is based of several C-like languages.


So it should be possible to replicate the functionality


               
               

               
            

Legacy_azaz1234

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
determine if player has clicked inside a trigger ?
« Reply #12 on: November 13, 2015, 01:39:55 am »


               

yeah, in fact it'd be pretty simple. there are even several inherent functions in vanilla nwn that i could use to triangulate. my big problem is i'm running nwnx-linux. i tracked down maxrock's nwnx_funcs you mentioned, and it does look like it'd be perfect for the job. i wonder if anyone will port it to linux ?  looking through the source on github, it's a little over my head. :/