AnaalNathrakh Posted January 8, 2014 Share Posted January 8, 2014 Just fiddled around with modding PZ and stumbled upon an unexpected behaviour of ISBaseTimedAction:update(). I guess this function is called similar as Events.OnTick with every update and therefore it depends on the speed of the game how often it is called. This seems to be a problem for some of the existing code likeISLightFromKindle Is there any way to call a function during the execition of a timed action in a reliable manner? Link to comment Share on other sites More sharing options...
RoboMat Posted January 8, 2014 Share Posted January 8, 2014 What kind of problems do you mean? The update() callback only influences the time until the TA is performed() and I didn't encounter any strangeness yet (but I only used it to check some values etc.). As far as I know there is no other possibility other than update() atm. Link to comment Share on other sites More sharing options...
AnaalNathrakh Posted January 8, 2014 Author Share Posted January 8, 2014 What's TA? As example the ISLightFromKindle from the current Build 21.function ISLightFromKindle:update() self.item:setJobDelta(self:getJobDelta()); -- every tick we lower the endurance of the player, he also have a chance to light the fire or broke the kindle self.character:getStats():setEndurance(self.character:getStats():getEndurance() - 0.006); local randNumber = 300; local randBrokeNumber = 300; if self.isOutdoorsMan then randNumber = 150; randBrokeNumber = 450; end if ZombRand(randNumber) == 0 then self.campfire.fireLvl = 2; camping.changeFireLvl(self.campfire); else -- fail ? Maybe the wood kit will broke... if ZombRand(randBrokeNumber) == 0 then--~ self.character:Say("I broke my kindling..."); self.character:getInventory():Remove(self.item); self.item = self.character:getInventory():FindAndReturn("FireWoodKit"); end endendSo, there is a randomNumber-check if the fire start or kindling breaks. Using Normal Speed this check (calling update method) is done 100 times, on fastest speed the check is done only 5 times. (numbers are arbitary)So on normal speed you have 100/300 = 33% chance to start fire, on fast you have a 5/300 = 1,6% chance. Thereby the outcome of the job is influenced by the gamespeed. Hope this clarifies my issue. Link to comment Share on other sites More sharing options...
ExcentriCreation Posted January 9, 2014 Share Posted January 9, 2014 an abbreviation for TimedAction.... I don't think what you are asking is possible, if you really must "fix" it, I would try looping over the check based on the gamespeed:function ISLightFromKindle:update() self.item:setJobDelta(self:getJobDelta()); -- every tick we lower the endurance of the player, he also have a chance to light the fire or broke the kindle self.character:getStats():setEndurance(self.character:getStats():getEndurance() - 0.006); local checkSpeed = getGameSpeed(); local checkMultiplier = nil; local checkStep = nil; if checkSpeed == 3 then checkMultiplier = 20; elseif checkSpeed == 2 then checkMultiplier = **(whatever that would be)** else checkMultiplier = 1; end local randNumber = 300; local randBrokeNumber = 300; if self.isOutdoorsMan then randNumber = 150; randBrokeNumber = 450; end for checkStep = 1, checkMultiplier do if ZombRand(randNumber) == 0 then self.campfire.fireLvl = 2; camping.changeFireLvl(self.campfire); else -- fail ? Maybe the wood kit will broke... if ZombRand(randBrokeNumber) == 0 then--~ self.character:Say("I broke my kindling..."); self.character:getInventory():Remove(self.item); self.item = self.character:getInventory():FindAndReturn("FireWoodKit"); end end endendthis is just an example, I'm sure I'm overlooking something EDIT:I hope that is what you were asking If you've already tried onTick then RoboMat already answered your question & it seems like you already know why Link to comment Share on other sites More sharing options...
AnaalNathrakh Posted January 9, 2014 Author Share Posted January 9, 2014 In the end i solved my problem by just looking at the jobDelta between to calls of update() and adjust the chance accordingly. Here's an example from my fishing mod. local currentdelta = self:getJobDelta(); local deltachange = currentdelta - self.lastDelta; if deltachange >0.005 then self.character:getStats():setFatigue(self.character:getStats():getFatigue() + 0.1*deltachange); if currentdelta >0.1 then -- dont catch anything when job is less than 10% finished if self.lastDelta<0.1 then deltachange = currentdelta-0.1; end randomValue = ZombRandBetween(0,100000); if randomValue<deltachange*10000 then self.character:getInventory():AddItems("Base.Salmon",1); self.character:Say("I caught something"); end end self.lastDelta = currentdelta; end Link to comment Share on other sites More sharing options...
RobertJohnson Posted January 9, 2014 Share Posted January 9, 2014 Don't go for a loop with the gamespeed, just multiply the number with the gamespeed (or / depending...) Link to comment Share on other sites More sharing options...
ExcentriCreation Posted January 9, 2014 Share Posted January 9, 2014 Yeah, I suppose the loop IS getting resource heavy again. Just thought that the chance to break on fail wouldn't be accurate without the same number of rolls 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