Page 1 of 1

how to use capsule in certain location?

Posted: Tue Nov 02, 2021 8:29 am
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...

Re: how to use capsule in certain location?

Posted: Tue Nov 02, 2021 4:49 pm
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.

Re: how to use capsule in certain location?

Posted: Tue Nov 02, 2021 6:56 pm
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...

Re: how to use capsule in certain location?

Posted: Tue Nov 02, 2021 8:49 pm
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.

Re: how to use capsule in certain location?

Posted: Tue Nov 02, 2021 9:28 pm
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 :)

Re: how to use capsule in certain location?

Posted: Wed Nov 03, 2021 8:40 am
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.