Jump to content

Recommended Posts

Hello, I need some help if someone can help that'd be nice :wilson_celebrate:!

Here is code.

modmain.lua

Spoiler

AddPrefabPostInit("grass", function(inst)
	local pt = Vector3(math.random(-1000, 1000), 0, math.random(-1000, 1000))
	local tile = GLOBAL.TheWorld.Map:GetTileAtPoint(pt.x, pt.y, pt.z)
	if tile == GROUND.SAVANNA then
		inst.AnimState:SetBuild("grass1")
	else
		inst.AnimState:SetBuild("grass1_forest")
	end
end)

 

 I'm trying to change texture of grass to be different if not on savanna turf, the problem is it seems even when I plant grass on a savanna "tile" it still goes to the forest texture, does someone know what is wrong or if this is the wrong way to do this? Thanks for your time have a wonderful time!

Edited by SuperDavid

hey, thanks for your help! I did this code

Spoiler

AddPrefabPostInit("grass", function(inst)
	local tile = GLOBAL.TheWorld.Map:GetTileAtPoint(inst.Transform:GetWorldPosition())
	if tile == GROUND.SAVANNA then
		inst.AnimState:SetBuild("grass1")
	else
		inst.AnimState:SetBuild("grass1_forest")
	end
end)

 

but for some reason the grass still changes to the forest color even when on savanna turf :wilson_dead:, thank you for your help still :wilson_dorky:

When you (or the game) create an entity, its coordinates are 0, 0, 0. So you need to wait for one frame before check the tile:
 

AddPrefabPostInit("grass", function(inst)
    inst:DoTaskInTime(0, function(inst)
        local tile = GLOBAL.TheWorld.Map:GetTileAtPoint(inst.Transform:GetWorldPosition())
        if tile ~= GLOBAL.GROUND.SAVANNA then
            inst.AnimState:SetBuild("grass1_forest")
        end
    end)
end)

 

Edited by ksaab

Hey man thanks so much it works great thanks thanks :wilson_celebrate:!!

If you might be willing to help me out with a little more of this that'd be superduper awesome!

so I wanted to exclude a couple other biomes from having "forest" grass but when I tried

Spoiler

local GROUND = GLOBAL.GROUND

AddPrefabPostInit("grass", function(inst) -- Alternate texture.
    inst:DoTaskInTime(0, function(inst)
	
        local tile = GLOBAL.TheWorld.Map:GetTileAtPoint(inst.Transform:GetWorldPosition())
        if (tile ~= GROUND.SAVANNA) or (tile ~= GROUND.ROCKY) or (tile ~= GROUND.DESERT_DIRT) then
            inst.AnimState:SetBuild("grassgreen_build")
        end
		
    end)
end)

 

it ruined everything and now all grass becomes forest again :wilson_dead:

Edited by SuperDavid
if tile ~= GROUND.SAVANNA and tile ~= GROUND.ROCKY and tile ~= GROUND.DESERT_DIRT then

or

local GROUND = GLOBAL.GROUND

local ignoreGreenGrass = 
{
	GROUND.SAVANNA = true,
	GROUND.ROCKY = true,
	GROUND.DESERT_DIRT = true,
}

AddPrefabPostInit("grass", function(inst) -- Alternate texture.
    inst:DoTaskInTime(0, function(inst)
	
        local tile = GLOBAL.TheWorld.Map:GetTileAtPoint(inst.Transform:GetWorldPosition())
        if not ignoreGreenGrass[tile] then
            inst.AnimState:SetBuild("grassgreen_build")
        end
		
    end)
end)

 

Edited by ksaab

Hey thanks again so I tried this code

Spoiler

local GROUND = GLOBAL.GROUND

AddPrefabPostInit("grass", function(inst) -- Alternate texture.
	local ignoreGreenGrass = 
	{ -- line 579
	GROUND.SAVANNA = true,
	GROUND.ROCKY = true,
	GROUND.DESERT_DIRT = true,
	}

    inst:DoTaskInTime(0, function(inst)
	
        local tile = GLOBAL.TheWorld.Map:GetTileAtPoint(inst.Transform:GetWorldPosition())
        if not ignoreGreenGrass[tile] then
            inst.AnimState:SetBuild("grassgreen_build")
        end
		
    end)
end)

 

but it crashes saying " :580: '}' expected (to close '{' at line 579) near '=' " , do you maybe know why this happens, and the other code works perfectly but still just curious why the table one didn't and thanks again for your help :wilson_celebrate:!!!

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