whismerhill Posted May 23, 2016 Share Posted May 23, 2016 Hi, having an issue here. I made a character which has two ways to level up : either it eats stuff & gets awarded experience or it battles creatures & gets awarded experience. When leveling up from battle the character says something & it works fine. When leveling up from eating, the character is supposed to say the same something but it does not fire up. I suspect it's because the eating animation is taking place ??? IF that's the case then how to circumvent that problem ? maybe wait till eating is finished ? but I have no idea how to do that. Thanks. Spoiler local function levelupfx(inst) -- NEED to apply a factor 1000 to each level instant -- REASON is floor & floating point values do not behave correctly -- example when incrementing from by 0.1 values, 5 might become in reality 4.999999999999 -- then floor 4.99 = 4 whereas 5 was the expected result inst.HUD.controls.status.heart:PulseGreen() inst.HUD.controls.status.stomach:PulseGreen() inst.HUD.controls.status.brain:PulseGreen() inst.HUD.controls.status.brain:ScaleTo(1.3,1,.7) inst.HUD.controls.status.heart:ScaleTo(1.3,1,.7) inst.HUD.controls.status.stomach:ScaleTo(1.3,1,.7) local lvl = (math.floor(inst.level))/1000 inst.components.talker:Say("Level Up! : " .. lvl) SeasonManager:DoMediumLightning() end local function oneat(inst, food) --leveling up on eating fish if food then if (food.prefab == "fish" or food.prefab == "tropical_fish" or food.prefab == "fish_raw") then if inst.level < 60000 then local previouslevel = math.floor(inst.level/1000) local xpdivisor = (math.floor(inst.level/50/1000)+1) *100 if inst.level < 30000 then inst.level = inst.level + 500 --instead of 0.5 since multiplied by 1000 (half a level) else inst.level = inst.level + 200 --instead of 0.1 (tenth of a level) if previouslevel ~= math.floor(inst.level/1000) then levelupfx(inst) applyupgrades(inst) else inst.components.talker:Say("Current XP: " .. ((inst.level/1000 - previouslevel)*xpdivisor) .. " Next level at:" .. (xpdivisor) ) end end end end end end Sidenote1: the medium lightning from season manager is not working either, though that wasn't the point of this post, and I'm probably gonna post about this later. Actually searching for an effect more visible than "pulsegreen" without having to create art (which I'm very bad at) Sidenote2: the XP "say" doesn't work either (and again it works for the award battle xp function) Sidenote3: some comments are outdated Link to comment Share on other sites More sharing options...
Mobbstar Posted May 23, 2016 Share Posted May 23, 2016 If you want a lightning flash, call the clock component using "GetClock()" and do lightning lighting. You could instead use wolfgang's "powerup" though. I think the cracked tallbird egg does what you are trying to achieve. Link to comment Share on other sites More sharing options...
whismerhill Posted May 23, 2016 Author Share Posted May 23, 2016 GetClock():DoLightningLighting works but only for the battle xp system. Thanks. again having the issue that : - when using the battle system, levelups & xp display & lightning flash work - when eating, levelups, xp display & lightning do not work. however the greenpulse do fireup EDIT: no idea what you meant for the tallbird cracked eggs ... I looked at the tallbirdegg prefab didn't see anything particular Link to comment Share on other sites More sharing options...
DarkXero Posted May 24, 2016 Share Posted May 24, 2016 46 minutes ago, whismerhill said: - when eating, levelups, xp display & lightning do not work. however the greenpulse do fireup You don't need your code to get a green pulse when eating something. What triggers the oneat function? An event? Is it a function assigned to your eater component? Put prints inside your function like print("I'm here") to follow the ifs. Link to comment Share on other sites More sharing options...
whismerhill Posted May 24, 2016 Author Share Posted May 24, 2016 local fn = function(inst) inst.soundsname = "wendy" inst.MiniMapEntity:SetIcon( "h02.tex" ) inst.level = 0 inst.components.eater:SetOnEatFn(oneat) THANKS A TON Darkxero ! Your input actually put me on the right track, I reviewed my code and the if statement that fired up the levelupfx is badly located ... don't know how I missed that, I've written that part of the code I should know better fixed & works now. OMG what a stupid mistake lol. Here's the corrected oneat function for reference : Spoiler local function oneat(inst, food) --leveling up on eating fish if food then if (food.prefab == "fish" or food.prefab == "tropical_fish" or food.prefab == "fish_raw") then if inst.level < 60000 then local previouslevel = math.floor(inst.level/1000) local xpdivisor = (math.floor(inst.level/50/1000)+1) *100 if inst.level < 30000 then inst.level = inst.level + 500 --instead of 0.5 since multiplied by 1000 (half a level) else inst.level = inst.level + 200 --instead of 0.1 (tenth of a level) end if previouslevel ~= math.floor(inst.level/1000) then levelupfx(inst) applyupgrades(inst) else inst.components.talker:Say("Current XP: " .. ((inst.level/1000 - previouslevel)*xpdivisor) .. " Next level at:" .. (xpdivisor),5) end end end end end Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.