Page 2 of 3
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 1:19 pm
by ficolas
is there any way I can define the entity without using the findentities function?
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 4:29 pm
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

Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 6:49 pm
by FreeER
I don't think onplayerdied is implemented yet (but I could be wrong)
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 7:21 pm
by ficolas
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?
Posted: Sat Mar 16, 2013 7:46 pm
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
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 8:22 pm
by ficolas
uh weird, kovarex plz help D:?
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 8:36 pm
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.
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 8:42 pm
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.
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 8:50 pm
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.
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 9:04 pm
by ficolas
Ah maybe thats why kovarex said about onplqyerrespawned
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 9:10 pm
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)
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 9:10 pm
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
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 9:21 pm
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
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 9:23 pm
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.
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 9:38 pm
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
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 10:53 pm
by ficolas
Lol, I wonder, why did I use entity.destroy...
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 11:01 pm
by FreeER
just used to doing so with a for loop? idk

Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 11:09 pm
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()?
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 11:21 pm
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.
Re: How do I use game methods? or destroy?
Posted: Sat Mar 16, 2013 11:30 pm
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()