TES Script- Dividing and Multiplication Reliable?

Post » Fri May 13, 2011 10:38 pm

Hi there,

(edit) Sorry, as anyone who read this no doubt guessed the problem was one of programmer error :) I must've been more tired than I thought last night as I couldn't see where the problem was. It was quite obvious this morning.

I'm having a go a messing about with someones script mostly for my own amusemant at the moment (Let me apologize if this your script and this annoys you).

Basically I'm converting Azzer's Bounty Reduction Over Time to run in game time rather than real time, and I'm trying to keep all other timing and function exactly the same. Needless to say to do so required a complete rewrite.

I have part of the script (just the basic function for now) behaving mostly like Azzer's - i.e. there is a delay of 60 mins game time after you commit a crime then you loose 1 gold of bounty for every 30 mins game time. (I've converted the game time times to match Azzer's real time times - i.e. 2 seconds real time = 1 minute game time.

However if I use the sleep function it all goes a bit weird. The game time is still calculated OK the next time you sleep (including the sleeping time), but the bounty is not reduced appropriately. The culprit appears to be a variable that is divided by a number and then assigned to a short - to round it down. This works as expected in normal play but returns 0.0000 after a sleep. What's really weird is that the same variable when used a second later to calculate how many minutes worth of bounty to remove seems to return a non-zero answer!

Anyway the code probably makes more sense than me describing it.
Spoiler
scn ABCmikeyAzzerBountyScriptfloat fQuestDelayTimefloat fOldBountyfloat fCurrentBountyfloat fRecalculatedBounty ;******************* Modified Mikey ****************float fGameHoursA ;including partial hours (AKA minutes and seconds)float fGameHoursB ;including partial hours (AKA minutes and seconds)float fGameMinutes ;Vanilla Game rate = 1 minute of game time per 2 seconds of real timeshort iRoundedNum short iRunOnceshort iStartDropshort iReduceBountyBy;******************** Menu mode ********************;begin menumode;	set fQuestDelayTime to .001;	; Mikey- Why is this running nothing every frame in menu mode? Does it affect the game mode?;end;******************** Main game mode ********************begin gamemode	set fQuestDelayTime to 2 ; As script is now based on interveening game time this can be set to whatever we like 	; ***** Setup the Game Time Counter *****	if iRunOnce == 0		set fGameHoursA to GetCurrentTime + (GameDaysPassed * 24)		set iRunOnce to 1	endif	set fGameHoursB to GetCurrentTime + (GameDaysPassed * 24)	set fGameMinutes to fGameMinutes + (fGameHoursB - fGameHoursA) * 60	PrintToConsole "GM: %.5f" fGameMinutes	set fGameHoursA to fGameHoursB	set fCurrentBounty to player.GetCrimeGold	if (fCurrentBounty == 0)		set fGameMinutes to 0		return	endif	if (fCurrentBounty > fOldBounty) ; Committed a crime		if (fOldBounty == 0)            ; New Criminal			Message "You are now a wanted criminal!", 10		endif		set iStartDrop to 0		set fGameMinutes to 0	endif	if (fCurrentBounty <= 4000) ; Don't reduce bounty or drop delay for "huge" bounties (mass-murder, genocide)		;******************* Add a drop delay based on the current bounty ************		if (fCurrentBounty > 3600)			if (fGameMinutes >= 3600)				set iStartDrop to 1				set fGameMinutes to fGameMinutes - 3600			endif		elseif (fCurrentBounty > 2500)			if (fGameMinutes >= 1800)				set iStartDrop to 1				set fGameMinutes to fGameMinutes - 1800			endif		else			if (fGameMinutes >= 60)				set iStartDrop to 1				set fGameMinutes to fGameMinutes - 60			endif		endif		;******************* Start dropping the bounty at an appropriate rate ************		if (iStartDrop == 1)			if (fGameMinutes > 0 && fCurrentBounty > 0) ; Drop Rate based on Bounty				set iReduceBountyBy to fGameMinutes / -30				PrintToConsole "Dummy"				PrintToConsole "iReduceBountyBy = %.5f" iReduceBountyBy				set fRecalculatedBounty to fCurrentBounty + iReduceBountyBy				PrintToConsole "fRecalculatedBounty = %.5f" fRecalculatedBounty				if (fRecalculatedBounty < 0) ; Dropped below Current Drop Rate Range 					set iReduceBountyBy to -1 * fCurrentBounty ; Set bounty to 0					; Note to self this can get stuck if partial gold bounties are allowed				endif				player.ModCrimeGold iReduceBountyBy; Is this the best way to modify the CrimeGold? is it possible just to set it to a value?				PrintToConsole "Reduced Bounty By %.5f Gold at 0+ rate" iReduceBountyBy				set fGameMinutes to fGameMinutes + 30 * iReduceBountyBy				set fCurrentBounty to fCurrentBounty + iReduceBountyBy			endif			set fCurrentBounty to player.GetCrimeGold			PrintToConsole "Bounty Is Now %.5f" fCurrentBounty		endif	endif	if (fCurrentBounty == 0 && fOldBounty > 0)		set iStartDrop to 0		Message "You are no longer a wanted criminal.", 10	endif	set fOldBounty to fCurrentBountyend


As I say the suspect line is this one:

set iReduceBountyBy to fGameMinutes / -30

I've tried it as a multiply by -0.033333 as well with the same results.

Here's a picture of the http://img339.imageshack.us/img339/1246/screenshot201009031024x.png, and then http://img268.imageshack.us/img268/1246/screenshot201009031024x.png.

(edit) And http://img3.imageshack.us/img3/1246/screenshot201009031024x.png
User avatar
liz barnes
 
Posts: 3387
Joined: Tue Oct 31, 2006 4:10 am

Return to IV - Oblivion