How do I use game methods? or destroy?
Re: How do I use game methods? or destroy?
is there any way I can define the entity without using the findentities function?
Re: How do I use game methods? or destroy?
I tried with this
but it didnt work 
Code: Select all
if glob.playerdiedtick==true then
glob.playerdiedtick=false
local entities = game.findentities{ topleft = {x = game.getplayer().position.x - 1, y = game.getplayer().position.y - 1}, bottomright = {x = game.getplayer().position.x + 1 ,y = game.getplayer().position.y + 1} }
for i,entity in ipairs(entities) do
if (entity.name== "Spawn") then
entity[i].destroy()
break
end
end
end
if event.name == "onplayerdied" then
glob.playerdiedtick=true
end

Re: How do I use game methods? or destroy?
I don't think onplayerdied is implemented yet (but I could be wrong)
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me
Or drop into #factorio on irc.esper.net
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me

Or drop into #factorio on irc.esper.net
Re: How do I use game methods? or destroy?
I think it is implemented, but it will be removed in 0.3, and merged with onunitdied into on entitydied
Re: How do I use game methods? or destroy?
Well the reason I thought it wasn't implemented was because I get nothing from trying to use it even:
gives no result
Code: Select all
if event.name == "onplayerdied" then
game.getplayer().print("DEAD")
end
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me
Or drop into #factorio on irc.esper.net
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me

Or drop into #factorio on irc.esper.net
Re: How do I use game methods? or destroy?
uh weird, kovarex plz help D:?
Re: How do I use game methods? or destroy?
I dont believe that this event is implemented, too.
But les say it is, then it is important to know how then dead of the player is handled in-game.
Will the end-screen instantly pop up (with a call of the onplayerdied event parallel) or will it call the event first, execute the code in it and only if the player is still dead after the execution then display the end-screen.
But anyway, at least you have to recreate the player-entity in the onplayerdied event.
But les say it is, then it is important to know how then dead of the player is handled in-game.
Will the end-screen instantly pop up (with a call of the onplayerdied event parallel) or will it call the event first, execute the code in it and only if the player is still dead after the execution then display the end-screen.
But anyway, at least you have to recreate the player-entity in the onplayerdied event.
Re: How do I use game methods? or destroy?
The death screen wont be pooped out, we are talking about when a player port (an entity that respawns the player) is placed.drs9999 wrote:I dont believe that this event is implemented, too.
But les say it is, then it is important to know how then dead of the player is handled in-game.
Will the end-screen instantly pop up (with a call of the onplayerdied event parallel) or will it call the event first, execute the code in it and only if the player is still dead after the execution then display the end-screen.
But anyway, at least you have to recreate the player-entity in the onplayerdied event.
Re: How do I use game methods? or destroy?
perhaps it is that onplayerdied isn't being called/used at all because the player is instead being teleported to the player-port, not actually dieing? If so we'd probably need a onplayerteleport (or something similar). Or if the player-port could be configured through the json file to self-destruct after x uses.
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me
Or drop into #factorio on irc.esper.net
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me

Or drop into #factorio on irc.esper.net
Re: How do I use game methods? or destroy?
Ah maybe thats why kovarex said about onplqyerrespawned
Re: How do I use game methods? or destroy?
Hmm..
Another idea:
Try "entity.destroy()" instead of "entity.destroy()"
Very unsure if this will work, but it is worth a try ( if you didnt tried it, already)
Another idea:
Try "entity.destroy()" instead of "entity.destroy()"
Very unsure if this will work, but it is worth a try ( if you didnt tried it, already)
Re: How do I use game methods? or destroy?
quick and easy test for that is:drs9999 wrote: Will the end-screen instantly pop up (with a call of the onplayerdied event parallel) or will it call the event first, execute the code in it and only if the player is still dead after the execution then display the end-screen.
Code: Select all
if event.name == "onplayerdied" then game.getplayer().health=100 end
Not sure the proper way of increasing an entity's health or I'd do a proper test, but this would seem to show that onplayerdied does exist (in 2.10), but is only called on a true death. not when respawning
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me
Or drop into #factorio on irc.esper.net
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me

Or drop into #factorio on irc.esper.net
Re: How do I use game methods? or destroy?
I think you cant do game.getplayer().health=100, instead you can use game.getplayer().sethealth(100)
also, can you test this:
if glob.playerdiedtick==true then
glob.playerdiedtick=false
local entities = game.findentities{ topleft = {x = game.getplayer().position.x - 1, y = game.getplayer().position.y - 1}, bottomright = {x = game.getplayer().position.x + 1 ,y = game.getplayer().position.y + 1} }
for i,entity in ipairs(entities) do
if (entity.name== "Spawn") then
entity.destroy()
break
end
end
end
if game.getplayer().health==0 then
glob.playerdiedtick=true
end
also, can you test this:
if glob.playerdiedtick==true then
glob.playerdiedtick=false
local entities = game.findentities{ topleft = {x = game.getplayer().position.x - 1, y = game.getplayer().position.y - 1}, bottomright = {x = game.getplayer().position.x + 1 ,y = game.getplayer().position.y + 1} }
for i,entity in ipairs(entities) do
if (entity.name== "Spawn") then
entity.destroy()
break
end
end
end
if game.getplayer().health==0 then
glob.playerdiedtick=true
end
Last edited by ficolas on Sat Mar 16, 2013 9:24 pm, edited 1 time in total.
Re: How do I use game methods? or destroy?
yes i changed my opinion.
the onplayerdied event exist.
but sadly it seems that the onplayerdied event isnt called when the player can respawn. but you already noticed that before.
the onplayerdied event exist.
but sadly it seems that the onplayerdied event isnt called when the player can respawn. but you already noticed that before.
Re: How do I use game methods? or destroy?
game.getplayer().sethealth(100) does not throw an error, however it still goes to gameover screen (perhaps because the player is destoryed?)ficolas wrote:I think you cant do game.getplayer().health=100, instead you can use game.getplayer().sethealth(100)
also, can you test this:
tested: unfortunately it did not destroy the spawner
edit: entity.destroy() instead of entity.destroy() DOES however work

drs9999 wrote:Try "entity.destroy()" instead of "entity.destroy()"
Thanks drs
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me
Or drop into #factorio on irc.esper.net
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me

Or drop into #factorio on irc.esper.net
Re: How do I use game methods? or destroy?
Lol, I wonder, why did I use entity.destroy...
Re: How do I use game methods? or destroy?
just used to doing so with a for loop? idk 

<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me
Or drop into #factorio on irc.esper.net
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me

Or drop into #factorio on irc.esper.net
Re: How do I use game methods? or destroy?
And the event onplayerdied is called when respawning? or it is not? it works with health==0 and entity.remove(), or with the event and entity.remove()?
Re: How do I use game methods? or destroy?
I only tested:
The message is only displayed if the player dies and NO player-port is built before.
Code: Select all
if event.name == "onplayerdied" then game.getplayer().print("DEAD") end
Re: How do I use game methods? or destroy?
onplayerdied is not called on a respawn (from what I can tell). You'd have to monitor the health of the player. It works with what you asked us to test: using game.getplayer().health==0 then for ... end and entity.destroy() not entity.destroy()
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me
Or drop into #factorio on irc.esper.net
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me

Or drop into #factorio on irc.esper.net