Page 3 of 3
					
				Re: How do I use game methods? or destroy?
				Posted: Sun Mar 17, 2013 12:19 pm
				by ficolas
				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.destroy()
				break
			end
		end
	end
Um this doesnt seem to work for me, do somebody know why D:
 
			 
			
					
				Re: How do I use game methods? or destroy?
				Posted: Sun Mar 17, 2013 2:19 pm
				by kovarex
				The entity name is not "Spawn", but "player-port"
			 
			
					
				Re: How do I use game methods? or destroy?
				Posted: Sun Mar 17, 2013 2:52 pm
				by ficolas
				kovarex wrote:The entity name is not "Spawn", but "player-port"
No, the entity type is player-port, the entity name is Spawn, because to apply new graphics without modifying vanilla files I made a new entity calles Spawn
 
			 
			
					
				Re: How do I use game methods? or destroy?
				Posted: Sun Mar 17, 2013 6:27 pm
				by FreeER
				this seems to do the job fairly well:
Code: Select all
  if event.name == "ontick" then
  if game.getplayer().health<10 then glob.playerdiedtick=maybe end
  if glob.playerdiedtick==maybe then if game.getplayer().health==100 then glob.playerdiedtick=true end end
  if glob.playerdiedtick==true then
  game.getplayer().print("health")
      glob.playerdiedtick=false
      entities = game.findentities{ topleft = {x = game.getplayer().position.x - 10, y = game.getplayer().position.y - 10}, bottomright = {x = game.getplayer().position.x + 10, y = game.getplayer().position.y + 10} }
      for i,entity in ipairs(entities) do
      game.getplayer().print("checking entities")
         if (entity.name=="Spawn") then
            entity.destroy()
            break
         end
      end
   end
of course you can ignore the game.getplayer().print statements, they were for debugging 

I think a slightly better way would be to have glob.playerdiedtick be set to false after a five seconds or so, that way if a player happens to get down below 10 health and actually live, it won't punish him once he is back to 100 health and walks over his spawn lol.
 
			 
			
					
				Re: How do I use game methods? or destroy?
				Posted: Sun Mar 17, 2013 6:45 pm
				by ficolas
				I thought about doing that, but I didnt do it because what you said at the end, and if the player gets overkilled (with a rocket, for example, rockets do 20 dmg so the player port wont be removed.
maybe if I use <=0 it would work
			 
			
					
				Re: How do I use game methods? or destroy?
				Posted: Sun Mar 17, 2013 9:25 pm
				by FreeER
				It should be easy enough to reset the glob.playerdiedtick, something like (didn't test btw):
Code: Select all
if event.name == "ontick" then
  if glob.playerdiedtick == maybe then
    if event.tick % 300 == 0 then glob.playerdiedtick = false
    end
  end
end
or you could have glob.playerdiedtick a table and have a tick counter built into it, so
Code: Select all
if event.name == "ontick" then
  if game.getplayer().health<10 then
    glob.playerdiedtick[dead]=maybe
    glob.playerdiedtick[tick]=1
    end
  if  glob.playerdiedtick[dead]==maybe then
    if glob.playerdiedtick[tick]<301 then glob.playerdiedtick[tick]=glob.playerdiedtick[tick]+1 end
  else glob.playerdiedtick[tick]=glob.playerdiedtick[tick]+1
  end
end
 
			 
			
					
				Re: How do I use game methods? or destroy?
				Posted: Sun Mar 17, 2013 9:29 pm
				by ficolas
				But I like things to be exact D:
			 
			
					
				Re: How do I use game methods? or destroy?
				Posted: Sun Mar 17, 2013 9:44 pm
				by FreeER
				well, just have to wait until an onplayersrespawned event then lol
			 
			
					
				Re: How do I use game methods? or destroy?
				Posted: Sun Mar 17, 2013 9:49 pm
				by ficolas
				if that happends some day, becausw I dont think it is prioritary
			 
			
					
				Re: How do I use game methods? or destroy?
				Posted: Sun Mar 17, 2013 9:59 pm
				by FreeER
				if we're lucky maybe it will be rolled into onunitdied, like with onplayerdied 

 or have 'self-destruct-after' simply be a json config option which would be much easier lol