Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

Need help with script.


Force85
 Share

Recommended Posts

I'm trying to update the script for my mod Coins of Tamriel. Making it to where it no longer removes the coins when you pick them, but also making it to where it tricks the player into thinking that they are spending those coins. What I want to do is have all three coins run by the script copper, silver and gold, to where when you pick them up you gain a set amount of septims (I already have this part).

 

Now. What I need is a script that checks the coins that the player has in his/her inventory. So if the player spends septims it will then remove the correct amount of the proper coin. based on the amount removed, amount in inventory and the coin priority. Which is the following

 

Gold

Silver

Copper

 

Here is the script that I have so far. 

 

Scriptname CoinsofTamriel extends referencealias



Miscobject Property gold001 auto
Miscobject Property gold002 auto
Miscobject Property gold003 auto
Miscobject Property gold004 auto

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  if (akBaseItem as miscobject) == gold002;checks to see if the added item is a Copper coin. 
      getactorreference().additem(gold001, (aiItemCount * 1),true)
  endif


  if (akBaseItem as miscobject) == gold003;checks to see if the added item is a Silver coin.
      getactorreference().additem(gold001, (aiItemCount * 50),true)
  endif
 
if (akBaseItem as miscobject) == gold004;checks to see if the added item is a gold coin.
      getactorreference().additem(gold001, (aiItemCount * 100),true)
  endif
endEvent


Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
if (akBaseItem as miscobject) == gold002;checks to see if the added item is a Copper coin. 
      getactorreference().additem(gold001, (aiItemCount * 1),true)
  endif 

if (akBaseItem as miscobject) == gold003;checks to see if the removed item is a silver coin. 
      getactorreference().removeitem(gold001, (aiItemCount * 50),true)
  endif


  if (akBaseItem as miscobject) == gold004;checks to see if the removed item is a gold coin.
      getactorreference().removeitem(gold001, (aiItemCount * 100),true)
  endif
endEvent

 

So far I have it to where if the player picks up or drops one of the new coins it will remove or add the correct amount of septims from their inventory. What I need now is that if you remove a certain amount of septims from your inventory it will remove the correct amount and the correct coin from your inventory. I'm guessing I'm going to need to have global variables. But I just don't know how to make what I want happen. I'm not a scripter. This script was created for me. I just modified it to make it to where if you drop the coins it will remove septims from your inventory. 

 

I'll try and give some examples

.

If player removes/spends 1-50 Septims from their inventory it will check to see if the player has either copper or silver. If the player has silver that will take higher priority over the copper and there for shall be removed, if the player doesn't have silver the script will then remove the correct value of copper.

 

If the player removes 1-100 Septims from their inventory it will check to see if the player has either copper, silver or gold. If the player has gold that will take higher priority over the copper and there for shall be removed, if the player doesn't have gold the script will then check to see if the player has silver, if  found it will then remove the correct amount. If the player does have silver but not the correct amount, like if you have 100 septims but its 50 coppers and 1 silver it will removes both the silver and the 50 coppers. Now if the player has 135 septims and the spend 100 of that,  and again they don't have a gold coin or 2 silver but instead have 1 silver and 85 coppers, the script will remove the correct value from both so it will remove the 1 silver and 50 coppers while leaving 35 coppers.

 

Now if the player has only a silver coin which equals to 50 Septims and the spend some of it, lets say 30 Septims. The game will remove the silver and then add in the correct number of copper in this case 20 to the player.

 

Now if the player spent all of the coin then it would just remove the silver.

If the player doesn't have silver but only copper it will remove the correct number of copper coins from the players inventory.

 

Lets say the Player has 100 copper, 2 silver and 2 gold. which = to 400 Septims. And the player spends 100 Septims. The script will then check the players inventory to see what coins in needs to remove based on the amount of Septims were removed. So since the player has 2 gold coins the script will remove 1 of them. But if the player didn't have gold it would then go to the next highest item on the list which is silver and remove the correct amount there, which would be 2 silver coins. If the player only had 1 silver coin and 100 copper coins it would remove 1 silver and 50 copper. If the player didn't have any silver or gold coins it would then move to copper which the player has 100 and then would remove 100 copper.

 

Link to comment
Share on other sites

Would a viable solution be to always convert the copper/silver/gold coins to the optimal quantity for the total septim value?

 

In other words, if copper =1, silver = 50 and gold = 100, a player with 168 septims can only have 1 gold, 1 silver, and 18 copper. This is perhaps a little less than entirely realistic, but is a convenience for players who really probably wouldn't want to be walking around with 168 coppers and it lets you avoid some nasty math and problems that vendors could have making change.

 

If that is indeed the case, you might consider a 1/10/100 ratio or 1/50/500 since the silver/gold ratio really isn't very convenient.

 

I'm realizing this isn't exactly what your asked for, but sometimes a simpler solution can be of greater benefit to users of your mod and much less prone to error.

Link to comment
Share on other sites

I would have to see your solution in action to know what your talking about. But I want to keep the current values of 1/50/100.

 

As it stand right now, when a player picks up one of the new coins it will add a set amount of septims to their inventory, and when they drop those coins it will remove that same amount. What I want is this. If the player drops or spends any septims the script will run and scan the players inventory to see what coins they have and them based on the amount of septims removed it will remove the correct amount in the coins based on a ranking system. If the player looses 100 septims in will scan to see if the player has gold if he\she does it will remove that. If the player doesn't it will then try and remove the amount in silver, if the player doesn't have silver or doesn't have the correct amount in silver it will then move to copper and remove the remaining amount from that. I don't know if what I want is even possible. I'm not a scripter, other wise I would have made it myself.

Link to comment
Share on other sites

I suppose I'm not sure of the actual intent of your mod. My impression is that you are striving to make the money system more realistic, with the smallest denomination being 1 copper instead of 1 gold septim. You've created copper (Orichalcum), silver and gold coins with gold values of 1/50/100 for this purpose but the underlying measure for pricing, money held, and item value is in the original gold septims value.

 

Great. Now suppose you have 1 gold piece, 0 silvers, and 2 coppers. You walk into a merchant and wish to purchase an item costing 5 septims. The vendor has to make change in order for you to buy it. Assuming this is possible, it now becomes a nightmare of math for all the possible permutations of coins you might carry.

 

If you want to avoid this programming nightmare, avoid errors, and make it easier for players using your mod, why not just express the number of septims held as the optimal number of coins, wherein:

NumGoldCoins = [ActorID.]GetGold / 100

NumSilverCoins = ([ActorID.]GetGold % 100) / 50

NumCopperCoins = [ActorID.]GetGold % 50

 

You can update inventory every time a container/inventory menu is opened. Players/vendors never have to make change or walk around with 4821 coppers.

 

The unrealistic side of this approach is that 2 silvers added to inventory will magically combine into 1 gold and that players will never see more than 1 silver coin in inventory (because you have set silver = 50 and gold = 100). This is the basis for my suggestion to change the exchange ratios a bit.

 

 

You mod does invite an interesting opportunity to melt coins down to ingots, both for crafting and storing value (i.e., gold bullion). Of course with the 45/50/100 ingot value ratios for Orichalcum/Silver/Gold you would have to have a different number of coins per ingot to make the ratios right (and 1 gold coin = 1 gold ingot seems weird IMHO).

 

 

Anyway.... the bottom line is this is your mod and you will make it work the way you want. The complex math you suggest is certainly possible. IMHO it just makes thinks more complex for players and invites errors.

 

All the best.

Link to comment
Share on other sites

I think I know what your suggestion, but even if I went with the conversion route, I'm still going to need a script to remove the new coins when you spend/drop their value in septims (gold001) other wise they will never leave your inventory. For an example, lets say you have 1 gold coin, which equals to 100 septims and you spend 100 septims your still going to have that gold coin in your inventory. 

Link to comment
Share on other sites

How about something like this?

Scriptname JaxonzTestGetGold extends ReferenceAlias

Form Property frmGoldSeptim Auto
Form Property frmSilverSeptim Auto
Form Property frmCopperSeptim Auto
Form Property frmOriginalGold Auto
ObjectReference Property objPlayer Auto


Event OnInit()
	RegisterForMenu("BarterMenu")
	RegisterForMenu("Training Menu")
EndEvent
 
Event OnMenuOpen(String MenuName)
	Debug.Trace("Converting coins to value")
	;it really doesn't matter which menu we open... just convert all coins to native gold
	
	;what's in inventory
	Int iNumberGoldSeptims = objPlayer.GetItemCount(frmGoldSeptim)
	Int iNumberSilverSeptims = objPlayer.GetItemCount(frmSilverSeptim)
	Int iNumberCopperSeptims = objPlayer.GetItemCount(frmCopperSeptim)
	
	int iGoldValue = iNumberGoldSeptims * 100 + iNumberSilverSeptims * 50 + iNumberCopperSeptims
	
	;remove the coins
	objPlayer.RemoveItem(frmGoldSeptim, iNumberGoldSeptims, True)
	objPlayer.RemoveItem(frmSilverSeptim, iNumberSilverSeptims, True)
	objPlayer.RemoveItem(frmCopperSeptim, iNumberCopperSeptims, True)
	
	;replace with native Skyrim gold
	objPlayer.AddItem(frmOriginalGold, iGoldValue, True)
	
EndEvent

Event OnMenuClose(String MenuName)
	Debug.Trace("Converting value to coins")

	;how much gold does the player have?
	int iGoldValue = objPlayer.GetItemCount(frmOriginalGold)
	
	;calculate optimal number of coins
	Int iNumberGoldSeptims = iGoldValue / 100
	Int iNumberSilverSeptims = (iGoldValue % 100) / 50
	Int iNumberCopperSeptims = iGoldValue % 50
	
	;remove Skyrim gold
	objPlayer.RemoveItem(frmOriginalGold, iGoldValue, True)

	;replace with coins
	objPlayer.AddItem(frmGoldSeptim, iNumberGoldSeptims, True)
	objPlayer.AddItem(frmSilverSeptim, iNumberSilverSeptims, True)
	objPlayer.AddItem(frmCopperSeptim, iNumberCopperSeptims, True)
EndEvent

This script uses the SKSE events to notify your script whenever Barter and Training menus are opened or closed. So far as I can tell, only the Barter and Training menus deal with the exchange of gold.

 

When opened, we count up the value of all the coins, remove them, and replace them with original gold (admittedly, there is a little loss of realism here, but a decent trade-off for convenience to the player).

 

When closed, we convert the gold back to your coin system.

 

This script would be attached to a ReferenceAlias in a Quest. (One referencing the player would be the norm.) You would have to set the properties to the coins in your system.

Link to comment
Share on other sites

That actually sounds like it might work. I'll give that a shot. Thanks! One question though. Is this making it to where 2 silver septims will automatically transfer into 1 gold septim like you previously suggested? And if so is there a way to make it to where it doesn't do that?

Link to comment
Share on other sites

Just mentioning that there are also several quests with conditions to check for players gold, e.g. buying the player houses. You might want to register for dialogue menu too. Maybe there are more situations in game where it would be necessary to do this exchange.

 

Every mod that checks for the players gold amount at any time in game without using one of those menus will be causing a compatibilty issue. Imho, that's begging for trouble. Your mod and your decisicion, of course.

Edited by Ghaunadaur
Link to comment
Share on other sites

Very good point, Ghaunadaur. There are definitely some challenges in attempting to modify something so core to the game.

 

In response to Force85's question: the above script would only change the number of coins when visiting a vendor or trainer, so it would be possible to accumulate any number of silver septims and have them show accurately in inventory. The lore-friendly explanation for the change in number of coins could be that merchants and trainers help make correct change.

Link to comment
Share on other sites

@Ghaunadaur: You do have a good point. This mod is definitely not perfect, and like jaxonz said. There are some challenges in modifying a core element in the game.

 

@jaxonz: Thanks for the help. Just one more question. If I decide to just continue using the default coin as the copper coin. What would need to be changed in the script that you provided?

 

EDIT: I tried the sctipt and it seems to have worked. The only thing I had to change in the script was Form property to Miscobject property, since under form property my coins wouldn't show up. The only thing I don't really care for is that it is still coveting the coins when I exit one of the menus in the script. So if I enter one of them with 2 silver septims and exit I will have 1 gold septim in their place. Its slightly annoying but I can live with it if it is the only way to have this work.

Edited by Force85
Link to comment
Share on other sites

OK, in toying with this I think I've actually developed the math you originally wanted.

 

Here's an updated script:

Scriptname JaxonzTestGetGold2 extends ReferenceAlias

MiscObject Property frmGoldSeptim Auto
MiscObject Property frmSilverSeptim Auto
MiscObject Property frmCopperSeptim Auto
MiscObject Property frmOriginalGold Auto
ObjectReference Property objPlayer Auto

int Property iGoldCoinValue = 100 Auto
int Property iSilverCoinValue = 50 Auto
int Property iCopperCoinValue = 1 Auto

int iOldTotalValue
Int iNumberGoldSeptims
Int iNumberSilverSeptims
Int iNumberCopperSeptims

Event OnInit()
	RegisterForMenu("BarterMenu")
	RegisterForMenu("Training Menu")
EndEvent
 
Event OnMenuOpen(String MenuName)
	Debug.Trace("Converting coins to value")
	;it really doesn't matter which menu we open... just convert all coins to native gold
	
	;what's in inventory
	iNumberGoldSeptims = objPlayer.GetItemCount(frmGoldSeptim)
	iNumberSilverSeptims = objPlayer.GetItemCount(frmSilverSeptim)
	iNumberCopperSeptims = objPlayer.GetItemCount(frmCopperSeptim)
	
	iOldTotalValue = (iNumberGoldSeptims * iGoldCoinValue) + (iNumberSilverSeptims * iSilverCoinValue) + iNumberCopperSeptims
	
	;remove the coins
	objPlayer.RemoveItem(frmGoldSeptim, iNumberGoldSeptims, True)
	objPlayer.RemoveItem(frmSilverSeptim, iNumberSilverSeptims, True)
	objPlayer.RemoveItem(frmCopperSeptim, iNumberCopperSeptims, True)
	
	;replace with native Skyrim gold
	objPlayer.AddItem(frmOriginalGold, iOldTotalValue, True)
	
EndEvent

Event OnMenuClose(String MenuName)
	Debug.Trace("Converting value to coins")

	;how much gold does the player have?
	int iTotalValueDiff = iOldTotalValue - (objPlayer as Actor).GetGoldAmount()
	
	;make change for difference in gold value
	if iTotalValueDiff >= 0	;same or more total value
		;just add new coins of proper denomination
		iNumberGoldSeptims = iNumberGoldSeptims + iTotalValueDiff / iGoldCoinValue
		iNumberSilverSeptims = iNumberSilverSeptims + (iTotalValueDiff % iGoldCoinValue) / iSilverCoinValue
		iNumberCopperSeptims = iNumberCopperSeptims + iTotalValueDiff % iSilverCoinValue
	Else	;less total value
		if iNumberCopperSeptims >= iTotalValueDiff
			;take the entire difference out in coppers
			iNumberCopperSeptims = iNumberCopperSeptims - iTotalValueDiff
		Else
			;remove change in coppers
			iNumberCopperSeptims = iNumberCopperSeptims - iTotalValueDiff % iSilverCoinValue
			iTotalValueDiff = iTotalValueDiff - iTotalValueDiff % iSilverCoinValue
			if (iNumberSilverSeptims * iSilverCoinValue) >= iTotalValueDiff		;there is enough silver to cover entire value difference
				iNumberSilverSeptims = iNumberSilverSeptims - (iTotalValueDiff / iSilverCoinValue)
			Else
				iNumberSilverSeptims = iNumberSilverSeptims - (iTotalValueDiff / iSilverCoinValue)	;take everything we can out of silver, OK to go negative
				While iNumberSilverSeptims < 0	;iterate making change in gold until we have 0 or more silver
					iNumberCopperSeptims = iNumberCopperSeptims + (iGoldCoinValue / iSilverCoinValue)	;assumes a gold coin value divides equally into silver coin value
					iNumberGoldSeptims -= 1
					iTotalValueDiff = iTotalValueDiff - iGoldCoinValue
				EndWhile
			EndIf
		Endif
	EndIf
	
	;remove Skyrim gold
	objPlayer.RemoveItem(frmOriginalGold, iOldTotalValue, True)

	;replace with coins
	objPlayer.AddItem(frmGoldSeptim, iNumberGoldSeptims, True)
	objPlayer.AddItem(frmSilverSeptim, iNumberSilverSeptims, True)
	objPlayer.AddItem(frmCopperSeptim, iNumberCopperSeptims, True)
EndEvent

Notes:

  • You can make the frmCopperSeptim and frmOriginalGold properties point to the same MiscObject if your mod replaces default gold. I left things as they were just in case you decide to use something different. It works both ways.
  • I made the values of each coin properties. You can change them to whatever values you like and the script will still work. However, it does assume that the value of silver coins divides evenly into the value of gold coins (i.e., if iGoldCoinValue = 100, then iSilverCoinValue could equal 1, 2, 5, 10, 20, 25, or 50)
  • Promoting the number of each coin to higher scope allows tracking the original total value and the number of each coin. The intent of this is to preserve the original number of each coin as much as possible.
  • There is more complexity in the OnMenuClose routine so that change can be made. The logic is as follows:​​
    • If the player has the same or more money
      • Add new coins of optimal denominations to those already existing
    • If the player has less total money
      • Take as much from copper coins as possible
      • Then take as much from silver coins as possible
      • Take gold coins last.

If you look close, you will see that I found it easier to take the remainder out in silver, allowing for a negative number of coins, and then iteratively make change from gold until there were 0 or more silver.

 

It compiles, but I don't have your mod installed so I haven't run the code. As I stated before, the more complex the math the greater the odds of something going wrong so you should thoroughly kick the tires on this.

 

Addressing Ghaunadaur's point, you may want to register for other menu types that may exchange money. There is a list at http://www.creationkit.com/UI_Script#Valid_Menu_Names . However,  I would NOT enable this for ContainerMenu, GiftMenu, or InventoryMenu as this would cause players to never see your special coins.

 

Enjoy!

Edited by jaxonz
Link to comment
Share on other sites

So I tried it out and I rather odd glitch happened. When I have it to where my mod replaces the original gold with copper. When I purchased a few items from a merchant I ended up leaving with more coin then I started with. This happens when I have both the the frmCopperSeptim and frmOriginalGold properties point to the same MiscObject. 

Edited by Force85
Link to comment
Share on other sites

Tried the new values and I'm still getting the glitch to where if I have both the frmCopperSeptim and frmOriginalGold properties point to the same MiscObject I ended leaving with more coin then I had even if I have them point to different objects it does the same thing. I would prefer if the default coin was copper that way I wouldn't have to replace all the coins in the world space and it would be more compatible with other mods. Suggestions? 

 

EDIT: I tried your original script (the first one you gave me) and the glitch isn't in that one.

Edited by Force85
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...