Jump to content

A real challenge if someone is up for it (script related)


Recommended Posts

So I have this script which now is working flawlessly aside from one small point, and I frankly know enough about scripting just to get myself into trouble and I'd rather not totally break it at this point. This script takes your gold and converts it into paper money at the start of the game (gold has weight in the mod) and it will auto-add the paper money back in as gold every time you talk to someone, and when you leave conversation, the gold is converted back into bills (leaving a small amount). The script accurately changes the money back and forth and none is lost or gained through script loopholes. You can buy stuff and sell stuff and it calculates it pretty nicely.

 

The problem is this. I'd like to make sure that players don't have more than about 25,000 on them in gold after dialog, in order to prevent encumbrance. There is a depository where the player can put bills in and manually get gold back if you WANT to carry more, but in general there is no reason to since the money converts seemlessly, but there you have it. The other little bug is that if you do buy or sell anything and then talk to people several times without buying anything, it jacks your gold count up and removes the proper bills, and once it passes about 50,000 gold on hand, it stabilizes. I'd like to figure out where that loop hole in the code is and reset the right variable at the right stage so it doesn't convert bills to gold unnecessarily at the end of the conversation.

 

Also I'd rather not redesign the entire code using OBSE, since I've got it working to a usable level without game breaking bugs, I'd just like to fine tune it. So anyone up for a challenge, let me know if you see anything. Thanks

 

scn CRCurrencyHandlerScript

float fQuestDelayTime

short convertedfunds

; paper currency convertion variables
long CRWRKTTL
long CRGOLDCT
long CRBANKNOTECT
long CRCURRENTGOLD
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

long leftovers

Begin gamemode

set fQuestdelayTime to .04
if state == 1
   Set CRCURRENTGOLD to player.getitemcount gold001
											
if CRCURRENTGOLD < CRGOLDCT
	set state to 0
elseif CRCURRENTGOLD >= CRGOLDCT
	set CRWRKTTL to CRCURRENTGOLD - CRGOLDCT
	set state to 2
endif
endif

if state == 2
    
       while (CRWRKTTL >= CRGOLDCT)
               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

; Initial gold changout on first load

if convertedfunds >= 0 && convertedfunds < 10
if player.getitemcount gold001 > 10000 && 	player.getitemcount gold001 < 15000
message "  "
message "  "
	player.additem MEOclutterseptimsstack0100 1
	player.removeitem gold001 10000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 15000 && player.getitemcount gold001 < 20000
message "  "
message "  "
	player.additem MEOclutterseptimsstack0100 1
	player.additem MEOclutterseptimsstack0050 1
	player.removeitem gold001 15000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 20000 && player.getitemcount gold001 < 30000
message "  "
message "  "
	player.additem MEOclutterseptimsstack0100 2
	player.removeitem gold001 20000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 30000 && player.getitemcount gold001 < 40000
message "  "
message "  "
	player.additem MEOclutterseptimsstack0100 3
	player.removeitem gold001 30000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 40000 && player.getitemcount gold001 < 50000
message "  "
message "  "
	player.additem MEOclutterseptimsstack0100 4
	player.removeitem gold001 40000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 50000 && player.getitemcount gold001 < 60000
message "  "
message "  "
	player.additem MEOclutterseptimsstack0500 1
	player.removeitem gold001 50000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 60000 && player.getitemcount gold001 < 75000
message "  "
message "  "
	player.additem MEOclutterseptimsstack0500 1
	player.additem MEOclutterseptimsstack0100 1
	player.removeitem gold001 60000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 75000 && player.getitemcount gold001 < 100000
message "  "
message "  "
	player.additem MEOclutterseptimsstack0500 1
	player.additem MEOclutterseptimsstack0050 3
	player.removeitem gold001 75000
	set convertedfunds to convertedfunds + 1	
elseif player.getitemcount gold001 > 100000 && player.getitemcount gold001 < 125000
message "  "
message "  "
	player.additem MEOclutterseptimsstack1000 1
	player.removeitem gold001 100000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 125000 && player.getitemcount gold001 < 150000
message "  "
message "  "
	player.additem MEOclutterseptimsstack1000 1
	player.additem MEOclutterseptimsstack0100 2
	player.removeitem gold001 125000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 150000 && player.getitemcount gold001 < 175000
message "  "
message "  "
	player.additem MEOclutterseptimsstack0500 1
	player.additem MEOclutterseptimsstack1000 1
	player.removeitem gold001 150000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 175000 && player.getitemcount gold001 < 200000
message "  "
message "  "
	player.additem MEOclutterseptimsstack1000 1
	player.additem MEOclutterseptimsstack0500 1
	player.additem MEOclutterseptimsstack0100 2
	player.additem MEOclutterseptimsstack0050 1
	player.removeitem gold001 175000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 200000 && player.getitemcount gold001 < 225000
message "  "
message "  "
	player.additem MEOclutterseptimsstack1000 2
	player.removeitem gold001 200000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 225000 && player.getitemcount gold001 < 250000
message "  "
message "  "
	player.additem MEOclutterseptimsstack1000 2
	player.additem MEOclutterseptimsstack0100 2
	player.additem MEOclutterseptimsstack0050 1
	player.removeitem gold001 225000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 250000 && player.getitemcount gold001 < 275000
message "  "
message "  "
	player.additem MEOclutterseptimsstack1000 2
	player.additem MEOclutterseptimsstack0500 1
	player.removeitem gold001 250000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 275000 && player.getitemcount gold001 < 300000
message "  "
message "  "
	player.additem MEOclutterseptimsstack1000 2
	player.additem MEOclutterseptimsstack0500 1
	player.additem MEOclutterseptimsstack0100 2
	player.additem MEOclutterseptimsstack0050 1
	player.removeitem gold001 275000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 300000 && player.getitemcount gold001 < 500000
message "  "
message "  "
	player.additem MEOclutterseptimsstack1000 3
	player.removeitem gold001 300000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 500000  && player.getitemcount gold001 < 1000000
message "  "
message "  "
	player.additem MEOclutterseptimsstack1000 5
	player.removeitem gold001 500000
	set convertedfunds to convertedfunds + 1
elseif player.getitemcount gold001 > 1000000  
message "  "
message "  "
	player.additem MEOclutterseptimsstack1000 10
	player.removeitem gold001 1000000
	set convertedfunds to convertedfunds + 1
else
	set convertedfunds to 10
endif
elseif convertedfunds == 10
set leftovers to player.getitemcount gold001
set leftovers to leftovers - 1000
if leftovers > 50000
	messagebox "The majority of your gold has been converted into paper bank notes. Imperial Bank Notes are treated just like normal gold by all merchants and will total with your regular gold while speaking with them. Most of your remaining funds have been placed into a savings account in your name. merely speak to a teller in the imperial bank about opening a savings account to gain access to the rest of your gold."
	set CRpersonalaccount to leftovers
	player.removeitem gold001 leftovers
	set convertedfunds to 11
else
	messagebox "The majority of your gold has been converted into paper bank notes. Imperial Bank Notes are treated just like normal gold by all merchants and will total with your regular gold while speaking with them. You can also visit the bank and exchange them for gold and deposit the gold into a personal account."
	set convertedfunds to 11
endif
endif

end

Begin MenuMode 1009

if menumode 1009 == 1
		set CRgold to player.getitemcount gold001
endif

       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

Link to comment
Share on other sites

I am on a friends' computer now and he won't let me download Notepad++, but you can. I find it useful in writing scripts. You can download the Oblivion script syntax as well. When you highlight a word, it will show you all instances of the word in the document. And it is free

 

-edit-

 

In the first block of the begin gamemode, state == 1, I prefer to write the following:

set CRWRKTTL to CRCURRENTGOLD - CRGOLDCT

as:

set CRWRKTTL to (CRCURRENTGOLD - CRGOLDCT)

While the punctuation seems redundant, on my old machine it worked better for complex scripts. Also, is it a good idea to set the fquest delay time to 0.4 every 3 seconds?

 

Your block in state == 2 looks solid. I prefer to use a return command at the end of each condition, but the while/loop block looks nice. Maybe try it my way?? Other than that, the block looks perfect.

 

There are too many variables for my puny brain to handle after that point, but it looks genius. I like the way you handle turning the cash into money in your begin menuMode1009 block:

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 ) )

 

the way that I find what part is active when is by adding a trivial item to my inventory every if block. I then up the ammounts by adding another zero each time. For example:

if state == 2
    player.additem 00038BA5 1
       while (CRWRKTTL >= CRGOLDCT)
               if CRWRKTTL >= 100000
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsstack1000 1
                       player.removeitem gold001 100000
                       set CRWRKTTL to CRWRKTTL - 100000
                       player.additem 00038BA5 10
               elseif CRWRKTTL >= 50000 && CRWRKTTL < 100000
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsstack0500 1
                       player.removeitem gold001 50000
                       set CRWRKTTL to CRWRKTTL - 50000
                       player.additem 00038BA5 100
               elseif CRWRKTTL >= 10000 && CRWRKTTL < 50000
                       message "   "
                       message "   "
                       player.additem MEOclutterseptimsstack0100 1
                       player.removeitem gold001 10000
                       set CRWRKTTL to CRWRKTTL - 10000
                       player.additem 00038BA5 1000

 

While I believe this block to be solid, it serves a quick example of how I add the items to my inventory. From there, when you enter dialogue but don't purchase anything, you will narrow it down to which part of the script is running (hopefully). You can then match what is going on with the item count in your inventory. If you have 2012 emeralds in your inventory, you would know the first place you put the code ran twice, the second place ran once, the third ran none and the fourth placement ran twice as well. So you basically read the number backwards.

 

Also, I like to split my scripts into pieces that run when needed. I would separate the script to convert on beginning the mod and the script that runs when you enter 1009. I would run the first block with a self ending quest script. Make a quest, attach a script and make it disable the quest when the script is finished. While unfamiliar with obse, I'm pretty sure that you would have to warn people that they could lose all gold when removing the mod.

 

Sorry I couldn't help more,

theuseless

Edited by theuseless
Link to comment
Share on other sites

I agree with getting NotePad++. I use it to write up scripts too, although I haven't tried downloading the Oblivion syntax.

 

About your script, there are two variables that aren't defined in there (CRpersonalaccount and CRgold), so I guess they're global variables. I can see why you want CRpersonalaccount like that, but I don't understand about CRgold. In fact, what do you even use that one for?

 

I'm not sure why the player's gold stabilizes at around 50k, but I do see a problem with your code.

 

if state == 1
          Set CRCURRENTGOLD to player.getitemcount gold001
                                                                                               
       if CRCURRENTGOLD < CRGOLDCT
               set state to 0
       elseif CRCURRENTGOLD >= CRGOLDCT
               set CRWRKTTL to CRCURRENTGOLD - CRGOLDCT
               set state to 2
       endif
endif

if state == 2
    
       while (CRWRKTTL >= CRGOLDCT)
               if CRWRKTTL >= 100000

 

Suppose you had 50k when you went into dialogue, but came out with 90k. So in state 1, CRWRKTTL is 40k, and then you go into state 2. But the loop in state 2 only works when CRWRKTTL is greater than or equal to CRGOLDCT. So this part doesn't run because 40k is less than 50k. It will skip the whole loop and go to state 0.

 

Maybe it stabilized to 50k because of a coincidence, but that part of the code definitely needs to be changed. Also, are you sure you want to keep the code that long? With arrays, you could shorten it by quite a lot.

Edited by fg109
Link to comment
Share on other sites

  • Recently Browsing   0 members

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