how to use capsule in certain location?

Place to get help with not working mods / modding interface.
Post Reply
meifray
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Sat May 29, 2021 6:12 pm
Contact:

how to use capsule in certain location?

Post by meifray »

how to script it,as far as I know,I can only read item prototype to know what action when capsule is throw will activate,then fake it...

if only we can just have itemstack.use_capsule(position[,surface])->bool
then the thing just will be much easier,

and maybe same thing can apply to ammo and gun...

User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 489
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: how to use capsule in certain location?

Post by Silari »

You can spawn the projectile form of a capsule using LUASurface.create_entity - should also work for guns that use projectiles.

If you want to target an arbitrary position on the ground instead of an entity, you can just set an arbitrary target but give a speed and max_range of 0 - this'll make it go off immediately wherever it was created.

Code: Select all

/c game.player.surface.create_entity{name="poison-capsule", position={214,176}, target=game.player.character, speed=1, max_range=0}
in the console makes a poison capsule explode at the given position.

You could also probably spawn some invisible EntityWithHealth and set the target to that, just need to make sure the entity goes away afterwards.


There's also https://lua-api.factorio.com/latest/Lua ... rom_cursor . You'd have to swap the user's cursor with a capsule, call the function, then swap the original items (if any) back in. Only method I know of to call a capsule directly.

meifray
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Sat May 29, 2021 6:12 pm
Contact:

Re: how to use capsule in certain location?

Post by meifray »

Silari wrote:
Tue Nov 02, 2021 4:49 pm
You can spawn the projectile form of a capsule using LUASurface.create_entity - should also work for guns that use projectiles.

If you want to target an arbitrary position on the ground instead of an entity, you can just set an arbitrary target but give a speed and max_range of 0 - this'll make it go off immediately wherever it was created.

Code: Select all

/c game.player.surface.create_entity{name="poison-capsule", position={214,176}, target=game.player.character, speed=1, max_range=0}
in the console makes a poison capsule explode at the given position.

You could also probably spawn some invisible EntityWithHealth and set the target to that, just need to make sure the entity goes away afterwards.


There's also https://lua-api.factorio.com/latest/Lua ... rom_cursor . You'd have to swap the user's cursor with a capsule, call the function, then swap the original items (if any) back in. Only method I know of to call a capsule directly.
is there a way to create dummy player? my goal is release capsule by entity or combination of entities,not necessary a player who playing the game.

if not,then that means I can only choose using script or turrent create these projectile to do things now...

User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 489
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: how to use capsule in certain location?

Post by Silari »

For use_from_cursor, you have to have an actual player to use it as the function only exists as an attribute of a Player instance.

User avatar
Nightc0re
Burner Inserter
Burner Inserter
Posts: 10
Joined: Mon Mar 21, 2016 12:06 am
Contact:

Re: how to use capsule in certain location?

Post by Nightc0re »

meifray wrote:
Tue Nov 02, 2021 6:56 pm
my goal is release capsule by entity or combination of entities,not necessary a player who playing the game.
Xterminator spotlighted a mod called Renai Transportation (https://mods.factorio.com/mod/RenaiTransportation).
Link is here: https://youtu.be/hHCDSJsDH74?t=1016 (Starting at 16:56).

And there you can see, he can throw defender capsules via this mod, and the defender capsules are not locked to the player.
So you could look into Kiplacon's mod, how to do it. Maybe it's also a combination of some things Silari already mentioned :)

meifray
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Sat May 29, 2021 6:12 pm
Contact:

Re: how to use capsule in certain location?

Post by meifray »

Nightc0re wrote:
Tue Nov 02, 2021 9:28 pm
meifray wrote:
Tue Nov 02, 2021 6:56 pm
my goal is release capsule by entity or combination of entities,not necessary a player who playing the game.
Xterminator spotlighted a mod called Renai Transportation (https://mods.factorio.com/mod/RenaiTransportation).
Link is here: https://youtu.be/hHCDSJsDH74?t=1016 (Starting at 16:56).

And there you can see, he can throw defender capsules via this mod, and the defender capsules are not locked to the player.
So you could look into Kiplacon's mod, how to do it. Maybe it's also a combination of some things Silari already mentioned :)
well,it is using projectile.

Post Reply

Return to “Modding help”