. . . Posted May 13, 2018 Share Posted May 13, 2018 (edited) Hello, I need some help if someone can help that'd be nice ! 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 May 13, 2018 by SuperDavid Link to comment Share on other sites More sharing options...
ksaab Posted May 13, 2018 Share Posted May 13, 2018 You pick a random point which doesn't have any relations to grass entity. Of course it will not work. local tile = GLOBAL.TheWorld.Map:GetTileAtPoint(inst.Transform:GetWorldPosition()) Link to comment Share on other sites More sharing options...
. . . Posted May 13, 2018 Author Share Posted May 13, 2018 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 , thank you for your help still Link to comment Share on other sites More sharing options...
ksaab Posted May 13, 2018 Share Posted May 13, 2018 (edited) 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 May 13, 2018 by ksaab Link to comment Share on other sites More sharing options...
. . . Posted May 13, 2018 Author Share Posted May 13, 2018 (edited) Hey man thanks so much it works great thanks thanks !! 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 Edited May 13, 2018 by SuperDavid Link to comment Share on other sites More sharing options...
ksaab Posted May 14, 2018 Share Posted May 14, 2018 (edited) 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 May 14, 2018 by ksaab Link to comment Share on other sites More sharing options...
. . . Posted May 14, 2018 Author Share Posted May 14, 2018 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 !!! Link to comment Share on other sites More sharing options...
PuffinBy Posted May 15, 2018 Share Posted May 15, 2018 local ignoreGreenGrass = { -- line 579 [GROUND.SAVANNA] = true, [GROUND.ROCKY] = true, [GROUND.DESERT_DIRT] = true, } This would work, I think. Link to comment Share on other sites More sharing options...
ksaab Posted May 15, 2018 Share Posted May 15, 2018 (edited) 2 hours ago, PuffinBy said: This would work, I think. Yeah, It should. I've forgotten that the GROUND table contains numbers and not strings. Edited May 15, 2018 by ksaab Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now