Jump to content

how to get tile info like if its "blends_street" or "blends_natural" ?


JonSyn

Recommended Posts

i been trying to figure this out for a couple hours to finish my chop up corpse for meat/bury corpse mod, but i cant figure it out .i need to check if its a corpse and if its on a natural tile and if it is have it show the bury corpse menu. it checks if its a corpse and if you have a shovel equiped but when i get to the part to check if its a natural tile i fail.

eatNbury.onFillWorldObjectContextMenu = function(player, context, worldobjects)	 local player = getSpecificPlayer(0);         local weapon = player:getPrimaryHandItem();	 local tile = getFloor():getSprite():getName(); 		local itemList = {}		for i,v in ipairs(worldobjects) do			if v:getSquare() then				for n = 0,v:getSquare():getWorldObjects():size()-1 do					local item = v:getSquare():getWorldObjects():get(n)					local itemName = item:getName() or (item:getItem():getName() or "???")					if not itemList[itemName] then itemList[itemName] = {} end					table.insert(itemList[itemName], item)				end			end		end   if body and weapon:getType() == "Axe" then      local itemName = "Corpse";      context:addOption(getText("Chop Up") .." ".. itemName, worldobjects, eatNbury1.buryNeat, body);	  end if body and weapon:getType() == "Shovel" and tile == "blends_natural" then       local itemName = "Corpse";            context:addOption(getText("Bury") .." ".. itemName, worldobjects, eatNbury2.buryNeat, body);	  	      endend
Link to comment
Share on other sites

iv tried alot beside just what i posted, even looked thru the farming lua and any that would involve ground tiles.

local square = getPlayer:getSquare();local tile = square:getFloor():getSprite():getName();
local square = getWorld:getSquare();local tile = square:getFloor():getSprite():getName();
local square = getSquare();local tile = square:getFloor():getSprite():getName();
local square = getSquare();local tile = square:getFloor():getSprite():getTextureName();

and a number of others , plus i looked thru the spraypaint mos and erosion mods to see how they get the tile. they dont do it anything alike so i cant figure it out. and this is literally the last part of the mod to finish and its done. can chop up corpses with axe and they delete and drop meat that can be cooked and eaten( custom meat :) ), or you can bury a corpse with a spade or trowel.

Link to comment
Share on other sites

yeah i got that var lol, and im assuming i need to make another table

eatNbury.onFillWorldObjectContextMenu = function(player, context, worldobjects)	 local player = getSpecificPlayer(0);         local weapon = player:getPrimaryHandItem(); 		local itemList = {}		for i,v in ipairs(worldobjects) do			if v:getSquare() then				for n = 0,v:getSquare():getWorldObjects():size()-1 do					local item = v:getSquare():getWorldObjects():get(n)					local itemName = item:getName() or (item:getItem():getName() or item:getFloor():getSprite():getName() or "???")					if not itemList[itemName] then itemList[itemName] = {} end					table.insert(itemList[itemName], item)				end			end		end   if body and weapon:getType() == "Axe" then      local itemName = "Corpse";      context:addOption(getText("Chop Up") .." ".. itemName, worldobjects, eatNbury1.buryNeat, body);	  end if body and weapon:getType() == "Shovel" and blends_natural then       local itemName = "Corpse";            context:addOption(getText("Bury") .." ".. itemName, worldobjects, eatNbury2.buryNeat, body);	  	      endend
eatNbury.onFillWorldObjectContextMenu = function(player, context, worldobjects)	 local player = getSpecificPlayer(0);         local weapon = player:getPrimaryHandItem();         local itemList = {}        for i,v in ipairs(worldobjects) do            if v:getSquare() then                for n = 0,v:getSquare():getWorldObjects():size()-1 do                    local item = v:getSquare():getWorldObjects():get(n)                    local itemName = item:getName() or (item:getItem():getName() or "???")                    local tile = item:getFloor():getSprite():getName();                    if not itemList[itemName] then itemList[itemName] = {} end                    table.insert(itemList[itemName], item)                end            end        end  if body and weapon:getType() == "Axe" then      local itemName = "Corpse";      context:addOption(getText("Chop Up") .." ".. itemName, worldobjects, eatNbury1.buryNeat, body);	  end if body and weapon:getType() == "Shovel" and blends_natural then       local itemName = "Corpse";            context:addOption(getText("Bury") .." ".. itemName, worldobjects, eatNbury2.buryNeat, body);	  	      endend

i dont know...........

Link to comment
Share on other sites

The big problem here is, that I'm not sure what you are doing here alltogether (lack of comments etc. ;)) ... e.g.:

for i,v in ipairs(worldobjects) do			if v:getSquare() then				for n = 0,v:getSquare():getWorldObjects():size()-1 do               	 local item = v:getSquare():getWorldObjects():get(n)

So you cycle through the world objects, then you get the square of that world object and then you cycle through the square of that world object to get all world objects again? Then you cycle through that and get the world object at position 'n' in the world object table?

Anyway - considering you get the correct object from the above code (which I doubt) - then you can try something like this:

local tileName = item:getSquare():getFloor():getSprite():getName();

Or you can try this:

local tileName = v:getSquare():getFloor():getSprite():getName();

Also another small tip:

You can rewrite

    	 if not itemList[itemName] then itemList[itemName] = {} end

as

itemList[itemName] = itemList[itemName] or {};

Also what is "if body and weapon:getType() == "Shovel" and blends_natural then" supposed to do? Unless you have a global variable of the name blends_natural somewhere and it is set to anything other than nil or false this if-statement will always fail.

Link to comment
Share on other sites

Didn't read all the post, but erm, you use the fillContextMenu which give you in parameter ALL the world object/object clicked in parameter, so why fetch again all the object on the square ?

 

Just do the for _,v in ipairs(worldobjects) do

 

Then test if it's an instance of IsoDeadBody (if i understood what you want :D)

Link to comment
Share on other sites

Didn't read all the post, but erm, you use the fillContextMenu which give you in parameter ALL the world object/object clicked in parameter, so why fetch again all the object on the square ?

 

Just do the for _,v in ipairs(worldobjects) do

 

Then test if it's an instance of IsoDeadBody (if i understood what you want :D)

The OP didn't provide a lot of info, but I'm guessing he wants to know the type of terrain on the tile to know if a corpse can be buried there.

Link to comment
Share on other sites

yeah i have been able to remove the corpse just fine, what i want to do is check if its a exterior tile and if its a natural tile like grass or dirt or sand and if it is bury it. should have it working soon tho.

Link to comment
Share on other sites

buries corpses on grass tiles, not in homes,on roads, or on dirt , i used 'blends_natural' . and i see that 'blends_natural_02' is water , and 'blends_street' is streets but is there others?

 

Basically I gave you all the information you need to achieve that in my reply above ;)

 

didnt work, but this did....

if body and weapon:getType() == "Shovel" and luautils.stringStarts(v:getSprite():getName(), 'blends_natural_01') or body and weapon:getType() == "Shovel" and luautils.stringStarts(v:getSprite():getName(), 'blends_grassoverlays_01') then        local itemName = "Corpse";           context:addOption(getText("Bury") .." ".. itemName, worldobjects, ZambieCleaner1.CleanZambies1, body);	

thanks for the help so far.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...