Floor trigger and flying monsters

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
vieuxchat
Posts: 48
Joined: Wed Mar 02, 2016 3:14 pm

Floor trigger and flying monsters

Post by vieuxchat »

Is there a way for flying units to activate floor triggers ?
User avatar
Zo Kath Ra
Posts: 944
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Floor trigger and flying monsters

Post by Zo Kath Ra »

vieuxchat
Posts: 48
Joined: Wed Mar 02, 2016 3:14 pm

Re: Floor trigger and flying monsters

Post by vieuxchat »

EDIT: My bad, I didn't see that the line that creates a connector isn't a function. Do I understand it well if I think that those lines that add onEndAction connectors are computed on game start ? But what about dynamically created monsters ? What would happen if a monster is created after the game start ?

Here is the code part I'm speaking of (from Isaac) :

Code: Select all

    --trigger script (works on specific monsters; checks position and elevation.)

    do     --Add additional monster ids to the monster table.
       local monster = {"crowern_1"}
       
       for x = 1, #monster do
          findEntity(monster[x]).move:addConnector('onEndAction', self.go.id, 'triggerFunction')
       end
    end

    function triggerFunction(target)
       if   target.go.x == self.go.x  and target.go.y  == self.go.y and target.go.elevation == self.go.elevation then
          
          --Do something when triggered
          
             playSound("secret")
             hudPrint(target.go.id.." (a "..target.go.name.."), has triggered the function.")
          
          --
       end
    end

User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Floor trigger and flying monsters

Post by Isaac »

The initial loop adds the connector to each monster in the monster table. For any newly spawned monsters, one need only add the connector manually when spawned.

Example: [Untested! ~but it should work barring typo]

Code: Select all

spawn("crowern").move:addConnector('onEndAction', <the script id you've used> , 'triggerFunction')
Post Reply