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 »

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:

kovarex
Factorio Staff
Factorio Staff
Posts: 8194
Joined: Wed Feb 06, 2013 12:00 am
Contact:

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

Post by kovarex »

The entity name is not "Spawn", but "player-port"

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 »

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

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 »

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.
<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 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

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 »

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
<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 »

But I like things to be exact D:

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, just have to wait until an onplayersrespawned event then lol
<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 »

if that happends some day, becausw I dont think it is prioritary

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 »

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
<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”