Jump to content

Script Logic Problem Need another set of eyes


icecreamassassin

Recommended Posts

One of the reasons is because in scripting / programming the different variable types are (i think) treated seperately even if they both deal with the same type of data such as numbers.

 

Try changing all the 5bill etc + 5stack variable types to long to match the same data type of the long CRWRKTTL variable

 

if you have OBSE you could try using a while loop, end of the loop you could then set state to 0

 

ScriptName CRbankhousenewsscript

float fQuestDelayTimer

short convertedfunds
short customerservice

short doonce
short account
short interestdays
short convertedfunds

; paper currency convertion variables
long CRWRKTTL
long CRGOLDCT
long CRBANKNOTECT
short state

;paper currency counts
long fivebill
long tenbill
long twentybill
long fiftybill
long hundredbill
long fivehundredbill
long thousandbill
long fivestack
long tenstack
long twentystack
long fiftystack
long hundredstack
long fivehundredstack
long thousandstack

Begin MenuMode 1009

       if state == 0

               ;presets currency exchange variables
               set CRBANKNOTECT to 0
               set CRWRKTTL to 0
               
               ;player starts with X gold
               set CRGOLDCT to player.getitemcount gold001

               ;bill type and count player has 
               set fivebill to player.getitemcount MEOclutterseptimsbill0005
               set tenbill to player.getitemcount MEOclutterseptimsbill0010
               set twentybill to player.getitemcount MEOclutterseptimsbill0020
               set fiftybill to player.getitemcount MEOclutterseptimsbill0050
               set hundredbill to player.getitemcount MEOclutterseptimsbill0100
               set fivehundredbill to player.getitemcount MEOclutterseptimsbill0500
               set thousandbill to player.getitemcount MEOclutterseptimsbill1000
               set fivestack to player.getitemcount MEOclutterseptimsstack0005
               set tenstack to player.getitemcount MEOclutterseptimsstack0010
               set twentystack to player.getitemcount MEOclutterseptimsstack0020
               set fiftystack to player.getitemcount MEOclutterseptimsstack0050
               set hundredstack to player.getitemcount MEOclutterseptimsstack0100
               set fivehundredstack to player.getitemcount MEOclutterseptimsstack0500
               set thousandstack to player.getitemcount MEOclutterseptimsstack1000

;total gold value of all paper money player has
set CRBANKNOTECT to CRBANKNOTECT + ( ( fivebill * 5 ) + ( tenbill * 10 ) + ( twentybill * 20 ) + ( fiftybill * 50 ) + ( hundredbill * 100 ) + ( fivehundredbill * 500 ) + ( thousandbill * 1000 ) + ( fivestack * 500 ) + ( tenstack * 1000 ) + ( twentystack * 2000 ) + ( fiftystack * 5000 ) + ( hundredstack * 10000 ) + ( fivehundredstack * 50000 ) + ( thousandstack * 100000 ) )

               ;total starting funds of gold and bank notes player has
               set CRWRKTTL to CRBANKNOTECT + CRGOLDCT 

               Message "   "
               Message "   "
               player.additem gold001 CRBANKNOTECT
               player.removeitem MEOclutterseptimsbill0005 fivebill
               player.removeitem MEOclutterseptimsbill0010 tenbill
               player.removeitem MEOclutterseptimsbill0020 twentybill
               player.removeitem MEOclutterseptimsbill0050 fiftybill
               player.removeitem MEOclutterseptimsbill0100 hundredbill
               player.removeitem MEOclutterseptimsbill0500 fivehundredbill
               player.removeitem MEOclutterseptimsbill1000 thousandbill
               player.removeitem MEOclutterseptimsstack0005 fivestack
               player.removeitem MEOclutterseptimsstack0010 tenstack
               player.removeitem MEOclutterseptimsstack0020 twentystack
               player.removeitem MEOclutterseptimsstack0050 fiftystack
               player.removeitem MEOclutterseptimsstack0100 hundredstack
               player.removeitem MEOclutterseptimsstack0500 fivehundredstack
               player.removeitem MEOclutterseptimsstack1000 thousandstack

               set state to 1
       endif

end


Begin GameMode

set fQuestdelayTimer to .01

setstage CRbankhouses 10


if state == 1
       Set CRWRKTTL to CRWRKTTL - CRGOLDCT
       Set CRGOLDCT to 0
       while (CRWRKTTL >= 5)
               if CRWRKTTL >= 100000
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsstack1000 1
                       player.removeitem gold001 100000
                       set CRWRKTTL to CRWRKTTL - 100000
               elseif CRWRKTTL >= 50000 && CRWRKTTL < 100000
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsstack0500 1
                       player.removeitem gold001 50000
                       set CRWRKTTL to CRWRKTTL - 50000
               elseif CRWRKTTL >= 10000 && CRWRKTTL < 50000
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsstack0100 1
                       player.removeitem gold001 10000
                       set CRWRKTTL to CRWRKTTL - 10000
               elseif CRWRKTTL >= 5000 && CRWRKTTL < 10000
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsstack0050 1
                       player.removeitem gold001 5000
                       set CRWRKTTL to CRWRKTTL - 5000
               elseif CRWRKTTL >= 2000 && CRWRKTTL < 5000
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsstack0020 1
                       player.removeitem gold001 2000
                       set CRWRKTTL to CRWRKTTL - 2000
               elseif CRWRKTTL >= 1000 && CRWRKTTL < 2000
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsstack0010 1
                       player.removeitem gold001 1000
                       set CRWRKTTL to CRWRKTTL - 1000                 
               elseif CRWRKTTL >= 500 && CRWRKTTL < 1000
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsbill0500 1
                       player.removeitem gold001 500
                       set CRWRKTTL to CRWRKTTL - 500
               elseif CRWRKTTL >= 100 && CRWRKTTL < 500
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsbill0100 1
                       player.removeitem gold001 100
                       set CRWRKTTL to CRWRKTTL - 100
               elseif CRWRKTTL >= 50 && CRWRKTTL < 100
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsbill0050 1
                       player.removeitem gold001 50
                       set CRWRKTTL to CRWRKTTL - 50
               elseif CRWRKTTL >= 20 && CRWRKTTL < 50
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsbill0020 1
                       player.removeitem gold001 20
                       set CRWRKTTL to CRWRKTTL - 20
               elseif CRWRKTTL >= 10 && CRWRKTTL < 20
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsbill0010 1
                       player.removeitem gold001 10
                       set CRWRKTTL to CRWRKTTL - 10
               elseif CRWRKTTL >= 5 && CRWRKTTL < 10
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsbill0005 1
                       player.removeitem gold001 5
                       set CRWRKTTL to CRWRKTTL - 5
               endif   
       loop

set state to 0

endif


end

Edited by KMSvalley
Link to comment
Share on other sites

So I tried it more or less as you posted here and it basically does the same thing.

 

The one thing that I find odd, which has always happened when the script has functioned at all is that I start with 268,757 gold. I have a script run at the start which takes most your gold and converts it to notes when the controlling quest begins during the game loading (because gold has weight) and it leaves me with 3757 gold and 265,000 in bank notes, so all is good there. When I go to a merchant, all my notes are taken and converted back into gold (268,757... perfect) but then when I step away, I am encumbered, it almost immidiately takes 100,000 gold from me, puts a 100K note in inventory, then takes about 3-5 seconds for the script to complete and the encumbrance goes away, I check my gold at it's at 8757 and I have 260,000 in bank notes, which adds up right, however by the logic of the script the way it is now, the value which should be replaced is 265,000 since the total CRWRKTTL value is 268757 which you leave dialog, then it's immediately reduced by the value of CRGOLDCT (3757) so basically leaving 265000 to be replaced by bills. The cycle should continue until this value is below 5. It removes 100K, reduced CRWRKTTL by 100,000, then cycles, does it again, then does the 50,000, then 10,000 and then stops. By the script language it looks as if it should cycle again and remove 5000 more and reduce CRWRKTTL by 5000 which would make it 0, and at THAT point the script conditions would change, but it doesn't instead it leaves the CRWRKTTL presumably at 5000....

 

wait a sec I think I spotted it. At the 5000 check I seem to have forgotten the "&&" check for the max range of cash... let me try this.

Link to comment
Share on other sites

So I tried it more or less as you posted here and it basically does the same thing.

 

The one thing that I find odd, which has always happened when the script has functioned at all is that I start with 268,757 gold. I have a script run at the start which takes most your gold and converts it to notes when the controlling quest begins during the game loading (because gold has weight) and it leaves me with 3757 gold and 265,000 in bank notes, so all is good there. When I go to a merchant, all my notes are taken and converted back into gold (268,757... perfect) but then when I step away, I am encumbered, it almost immidiately takes 100,000 gold from me, puts a 100K note in inventory, then takes about 3-5 seconds for the script to complete and the encumbrance goes away, I check my gold at it's at 8757 and I have 260,000 in bank notes, which adds up right, however by the logic of the script the way it is now, the value which should be replaced is 265,000 since the total CRWRKTTL value is 268757 which you leave dialog, then it's immediately reduced by the value of CRGOLDCT (3757) so basically leaving 265000 to be replaced by bills. The cycle should continue until this value is below 5. It removes 100K, reduced CRWRKTTL by 100,000, then cycles, does it again, then does the 50,000, then 10,000 and then stops. By the script language it looks as if it should cycle again and remove 5000 more and reduce CRWRKTTL by 5000 which would make it 0, and at THAT point the script conditions would change, but it doesn't instead it leaves the CRWRKTTL presumably at 5000....

 

wait a sec I think I spotted it. At the 5000 check I seem to have forgotten the "&&" check for the max range of cash... let me try this.

 

 

Ok...so now the core of it functions properly! the && check was stopping it all up.

 

Problem now is that I have to have the script change the variables if you buy anything so that it isn't giving you notes for gold that you have spent... but I think all in all it's near complete now.

Link to comment
Share on other sites

yeah I have OBSE and use a couple functions now (I totally have not delved into it fully obviously)

 

thanks for your help. My head is starting to hurt wrapping my head around this. It's working at the moment when you do not buy anything. If you sell stuff it works fine and converts the gold to paper (which seems weird to me since the CRWRKTTL should not involve that acquired cash, but I did mess with the code and add a couple new variables to track the amount you spent or earned and the amount iof gold you exit dialog with, but I'm afraid I'm starting to loose my flow... time for a break I guess

Link to comment
Share on other sites

I''m so happy! I actually got it working. I set up a conditional check comparing the gold you have when you leave dialog to what you had when you started in a separate "STATE" block to handle the alteration of the CRWRKTTL before it's sent to the cycle down to manageable gold.

 

problem I see though is that you are encumbered after coming out of dialog for a few seconds. can you think of a good way to reverse engineer the script so that instead of coming out with a pile of gold and the script whittling it down to the proper amount, instead have it remove the gold entirely and add back in the difference? That way when you are rushed by a foe who has something to say before attacking you, you don't stand there for 5 seconds while your gold converts back to bills while they wail on you :P hehehe

Link to comment
Share on other sites

The variable controlling quest script processing is supposed to be "fquestdelaytime" and not "fquestdelaytimer". Try changing that and if it's still not fast enough, I guess you can try using a shorter script:

 

 

scn examplescript

array_var Currency

float fquestdelaytime

short state
short TotalGold
short BillValue
short index
short count
short value

ref itemref

Begin GameMode

if (fquestdelaytime != 0.01)
	let fquestdelaytime := 0.01
	let Currency := ar_List MEOclutterseptimsstack1000, MEOclutterseptimsstack0500, MEOclutterseptimsstack0100, MEOclutterseptimsstack0050, MEOclutterseptimsstack0020, MEOclutterseptimsstack0010, MEOclutterseptimsstack0005, MEOclutterseptimsbill1000, MEOclutterseptimsbill0500, MEOclutterseptimsbill0100, MEOclutterseptimsbill0050, MEOclutterseptimsbill0020, MEOclutterseptimsbill0010, MEOclutterseptimsbill0005
endif

if (state)
	let state := 0
	let BillValue := (Player.GetItemCount Gold001) - TotalGold
	let index := 0
	while (index < ar_Size Currency)
		let itemref := Currency[index]
		let value := GetGoldValue itemref
		while (BillValue >= value)
			Player.RemoveItemNS Gold001 value
			Player.AddItemNS itemref 1
			let BillValue -= value
		loop
		let index += 1
	loop
endif

End

Begin MenuMode 1009

if (state)
	Return
endif

let state := 1
let TotalGold := Player.GetItemCount Gold001
let BillValue := 0
let index := 0

while (index < ar_Size Currency)
	let itemref := Currency[index]
	let count := Player.GetItemCount itemref
	let BillValue += count * (GetGoldValue itemref)
	Player.RemoveItemNS itemref count
	let index += 1
loop

Player.AddItemNS Gold001 BillValue

End

 

It'll only work properly if the gold value of your money stacks are accurate (ie MEOclutterseptimsstack1000 is worth 100000, MEOclutterseptimsbill1000 is worth 1000, etc).

 

Edited by fg109
Link to comment
Share on other sites

MEOclutterseptimsbill0005 5

MEOclutterseptimsbill0010 10

MEOclutterseptimsbill0020 20

MEOclutterseptimsbill0050 50

MEOclutterseptimsbill0100 100

MEOclutterseptimsbill0500 500

*

*

MEOclutterseptimsstack0010 1000

MEOclutterseptimsstack0020 2000

MEOclutterseptimsstack0050 5000

MEOclutterseptimsstack0100 10000

MEOclutterseptimsstack0500 50000

MEOclutterseptimsstack1000 100000

 

(these two you don't need)

*MEOclutterseptimsbill1000 thousandbill

*MEOclutterseptimsstack0005 fivestack

 

so quick correction to fg109 above code example

let Currency := ar_List MEOclutterseptimsstack1000, MEOclutterseptimsstack0500, MEOclutterseptimsstack0100, MEOclutterseptimsstack0050, MEOclutterseptimsstack0020, MEOclutterseptimsstack0010, MEOclutterseptimsbill0500, MEOclutterseptimsbill0100, MEOclutterseptimsbill0050, MEOclutterseptimsbill0020, MEOclutterseptimsbill0010, MEOclutterseptimsbill0005

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...