How do I use game methods? or destroy?

Place to get help with not working mods / modding interface.
ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: How do I use game methods? or destroy?

Post by ficolas »

is there any way I can define the entity without using the findentities function?

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: How do I use game methods? or destroy?

Post by ficolas »

I tried with this

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
but it didnt work :(

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How do I use game methods? or destroy?

Post by FreeER »

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

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: How do I use game methods? or destroy?

Post by ficolas »

I think it is implemented, but it will be removed in 0.3, and merged with onunitdied into on entitydied

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How do I use game methods? or destroy?

Post by FreeER »

Well the reason I thought it wasn't implemented was because I get nothing from trying to use it even:

Code: Select all

       if event.name == "onplayerdied" then
          game.getplayer().print("DEAD")
       end
gives no result
<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

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: How do I use game methods? or destroy?

Post by ficolas »

uh weird, kovarex plz help D:?

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: How do I use game methods? or destroy?

Post by drs9999 »

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.

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: How do I use game methods? or destroy?

Post by ficolas »

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.
The death screen wont be pooped out, we are talking about when a player port (an entity that respawns the player) is placed.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How do I use game methods? or destroy?

Post by FreeER »

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

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: How do I use game methods? or destroy?

Post by ficolas »

Ah maybe thats why kovarex said about onplqyerrespawned

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: How do I use game methods? or destroy?

Post by drs9999 »

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)

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How do I use game methods? or destroy?

Post by FreeER »

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.
quick and easy test for that is:

Code: Select all

if event.name == "onplayerdied" then game.getplayer().health=100 end
HOWEVER, that crashed the game with LuaEntity::luaNewIndex: readonly
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

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: How do I use game methods? or destroy?

Post by ficolas »

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
Last edited by ficolas on Sat Mar 16, 2013 9:24 pm, edited 1 time in total.

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: How do I use game methods? or destroy?

Post by drs9999 »

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.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How do I use game methods? or destroy?

Post by FreeER »

ficolas wrote:I think you cant do game.getplayer().health=100, instead you can use game.getplayer().sethealth(100)

also, can you test this:
game.getplayer().sethealth(100) does not throw an error, however it still goes to gameover screen (perhaps because the player is destoryed?)
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

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: How do I use game methods? or destroy?

Post by ficolas »

Lol, I wonder, why did I use entity.destroy...

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How do I use game methods? or destroy?

Post by FreeER »

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

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: How do I use game methods? or destroy?

Post by ficolas »

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()?

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: How do I use game methods? or destroy?

Post by drs9999 »

I only tested:

Code: Select all

if event.name == "onplayerdied" then game.getplayer().print("DEAD") end
The message is only displayed if the player dies and NO player-port is built before.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How do I use game methods? or destroy?

Post by FreeER »

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

Post Reply

Return to “Modding help”