Search the Community
Showing results for tags 'getageindays'.
-
I'm currently having a problem with my code within the modmain of a custom character I was creating and I was able to isolate it down to this line here: if v.components.age:GetAgeInDays() % daysRequired = 0 then What I'm trying to accomplish is a simple RNG item giver to a specific character, but only when their time alive in the world fully divides (nothing in the decimal places) into the required day count (determined by the config data of 'gem_generation'). However, when it comes to running the code below, I always receive the same results from the game. For the line I isolated above, it always crashes saying that "then is expected near =" for said line. I'd appreciate any assistance in finding out the issue as well as how to solve it. The full code: if GetModConfigData('gem_generation') > 0 then local function GiveGems() for i,v in ipairs(AllPlayers) do local daysRequired = tonumber(GetModConfigData('gem_generation')) local playerAge = tonumber(v.components.age:GetAgeInDays()) -- If the player is example, has more than 0 health (isn't dead) and the age of the player meets the generation requirements if (v:HasTag("example")) and (v.components.health.currenthealth > 0) and (playerAge > 1) and not v:HasTag("playerghost") then if v.components.age:GetAgeInDays() % daysRequired = 0 then --Gives the player a random gem local RNG = math.random(1,36) if RNG < 7 then v.components.inventory:GiveItem("redgem") elseif RNG >= 7 and RNG < 13 then v.components.inventory:GiveItem("orangegem") elseif RNG >= 13 and RNG < 19 then v.components.inventory:GiveItem("yellowgem") elseif RNG >= 19 and RNG < 25 then v.components.inventory:GiveItem("greengem") elseif RNG >= 25 and RNG < 31 then v.components.inventory:GiveItem("bluegem") else v.components.inventory:GiveItem("purplegem") end end end end end -- Runs GiveGems local function OnDayComplete(inst,day) GiveGems() end -- Runs GiveGems at the start of a new day AddWorldPostInit(function(w) w:WatchWorldState("cycles", OnDayComplete) end) end
- 5 replies
-
- getageindays
- components
-
(and 4 more)
Tagged with: