How to detect nearby particles?

  • BrianTheEngineer
    21st Sep 2019 Member 0 Permalink

    I am making a potions script that will add potions that modify stickman and fighters. The script revolves around detecting when a stickman is submerged in a particular liquid. In simpler terms that means using a function to tell when a stickman is within 1 - 3 pixels of my new element. Is there a way to find out all nearby particles within a specific range?

    Edited 2 times by BrianTheEngineer. Last: 21st Sep 2019
  • phox
    21st Sep 2019 Member 0 Permalink

    pmap returns particle positions, or you could use t to find your particles X,Y pos and use an if statement to see if it matches your stickman pos,

  • jacob1
    21st Sep 2019 Developer 0 Permalink
    Use sim.partNeighbors

    so, sim.partNeighbors(100, 100, 3, tpt.el.dust.id) returns an iterator with all dust within 3 pixels.

    for i in sim.partNeighbors(<stuff>) do
        print(i)
    end


    @phox (View Post)
    pmap is a c++ thing, not a Lua function.
  • BrianTheEngineer
    21st Sep 2019 Member 0 Permalink

    @jacob1 (View Post)

     

    I don't understand how to use the function. Am I supposed to put the sim.partNeighbors(100, 100, 3, tpt.el.stkm.id) part in a update function that runs when the particle updates?

     

    The code below should turn all DUST that goes within 3 pixels of it into WATR.

     

    Current Code:

     

        local function test(x, y)

            for i in sim.partNeighbors(x, y, 3, tpt.el.dust.id) do

                elements.set_property("type""watr", i)

            end

        end

        local regeneration = elements.allocate("POTION""REG2")

            elements.element(elements.POTION_PT_REG2, elements.element(elements.DEFAULT_PT_WATR))

            elements.property(regeneration, "Name""REG2")

            elements.property(regeneration, "Description""Super Regen Potion.")

            elements.property(regeneration, "MenuSection", elem.SC_LIQUID)

            elements.property(regeneration, "Color"0xF092DD)

            elements.property(regeneration, "Update", test)
     
    Error: In particle update:
     
        scripts/Potions.lua:3: attempt to call a table value
    Edited 6 times by BrianTheEngineer. Last: 21st Sep 2019
  • bearbalene
    27th Feb 2023 Member 0 Permalink
    local function test(x, y)

     

            for i in sim.neighbors(x, y, 3, tpt.el.dust.id) do
     

                sim.partChangeType(i, elements.TPT_PT_WATR)

     

            end