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

Script not working 100% of the time. Why?


Force85
 Share

Recommended Posts

I'm working on a mod that introduces new coins into the game. I'm replacing the default gold coin with a copper coin and then adding in a silver and gold coin. And I'm using a script to make it where when you pick up one of those new coins (silver or gold) you will get a set amount of copper coins. The reason is, is that I didn't want people to have to sell my coins in order to gain their value. So I'm using a modified version of the script attached to the coin purses. So basically how it's suppose to work is this.

 

Player picks up new coin. Coin is deleted from inventory. Set amount of copper coins added to players inventory. 

 

Now the script does work, but the problem is, is that it doesn't work 100% of the time. and I don't know why. Every so often when I pick up one of the new coins I will get one of these two glitches. 

 

1. The script doesn't run and the coin is added to my inventory. And if you drop the coin, you won't be able to pick it back up.

 

2. The script will run, but you will gain double the amount of coin that your suppose to. 

 

Here is the script. Could someone look it over and see what could be causing those glitches? I'm not a scripter. I just used the coin purse script and another modder helped with a few of the other glitches I was experiencing. 

 

Scriptname newcoinscript extends ObjectReference  Conditional


import debug
import utility




MiscObject property coinObj auto
{Should be set to Coin01}
MiscObject property gold00 auto
Int property coinMin auto
{minimum amount of coins player receives}




Int property coinMax auto
{maximum amount of coins player receives}




;************************************




event OnLoad()
BlockActivation()
endEvent




function CoinTake()
;player has activated
int numOfCoins = game.GetPlayer().GetItemCount(Gold00)
If numOfCoins == 0
     numOfCoins = 1
EndIf
numOfCoins *= randomInt(coinMin, coinMax)
gotoState("done")
game.getplayer().removeitem(gold00, game.GetPlayer().GetItemCount(Gold00), true)
game.getPlayer().addItem(coinObj, numOfCoins,true)
endFunction




auto State Waiting




Event OnActivate (objectReference triggerRef)




Actor actorRef = triggerRef as Actor




if(actorRef == game.getPlayer())
CoinTake()
disable()
delete()
endif




endEvent






Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)






if akNewContainer == game.getplayer()
CoinTake()
endif




endEvent




endState


;************************************




State done
;do nothing
endState




;************************************

Link to comment
Share on other sites

1. You can't pick up coin because you block it in the onload section. I guess because you have it onload it might be possible that for one coin you block it and for another you don't as the 3d is already loaded.

 

2. Can you elaborate coinmin, coinmax and randomInt(coinMin, coinMax)? I don't understand your intention here and how the min/max is set.

Edited by schatten
Link to comment
Share on other sites

I'll try. As I've stated I'm not a scripter. And the script that I'm using is basically just a modified version of the script that is attached to the coin purses. And that script used the coinmin and coinmax to set the min and max amount of coins you would get when you would pick up a coin purse. So the only reason I'm using the coinmin, coinmax. Is because I don't know of another command that will allow me to set the amount of an item you gain when you pick up an item. As for the randomInt(coinMin, coinMax). I really didn't even know that was there. I didn't write this script. Most of it was already there, via the coin purse script. 

 

Here is an image of the properties for one of my coins. I have the min and max set to 50, so that way I will always get 50. 

 

1.png

 

I hope I was able to answer your question.

Link to comment
Share on other sites

Okay, I guess I understand the whole picture now.

My solution isn't easy for you. I would create a whole new script for your coin...

 

http://www.creationkit.com/OnItemAdded_-_ObjectReference

http://www.creationkit.com/Cast_Reference

 

Create a new quest and an referencealias for the player. Attach below script to the player alias.

 

script blah extends referencealias

 

Miscobject Property your_silver_coin auto

Miscobject Property your_gold_coin auto

Miscobject Property gold001 auto

 

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  if (akBaseItem as miscobject) == your_silver_coin;check to see if the added item is your silver coin. the first part is casting the form akbaseitem to an miscobject, not sure if needed or not.
      getactorreference().removeitem(akBaseItem, aiItemCount); getactorreference gets the reference of the alias. we extended the script to refalias and attached it to the quest alias. the q alias is the player so in effect, it gets the player
      getactorreference().additem(akBaseItem, (aiItemCount * how_much_gold_is_silver))
  endif
  if (akBaseItem as miscobject) == your_silver_coin;check to see if the added item is your gold coin.
      getactorreference().removeitem(akBaseItem, aiItemCount)
      getactorreference().additem(akBaseItem, (aiItemCount * how_much_gold_is_silver))
  endif
endEvent

 

 

Something like this should do. Do you understand this script? What's it doing?

Edited by schatten
Link to comment
Share on other sites

Okay. So I ran into a problem. When I pick up one of the new coins. It doesn't add gold001 to my inventory. It just keeps removing and adding the coin I pick up. As seen in the pic below. I'm guessing I messed up somewhere. 

 

TESV2014-02-2413-53-14-70.jpg

It keeps going for a few second and then it stops.

 

Here is the script. gold002 is silver and gold003 is gold. 

 

Scriptname newcoinscript extends referencealias
 
Miscobject Property gold002 auto
Miscobject Property gold003 auto
Miscobject Property gold001 auto
 
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  if (akBaseItem as miscobject) == gold002;check to see if the added item is your silver coin. the first part is casting the form akbaseitem to an miscobject, not sure if needed or not.
      getactorreference().removeitem(akBaseItem, aiItemCount); getactorreference gets the reference of the alias. we extended the script to refalias and attached it to the quest alias. the q alias is the player so in effect, it gets the player
      getactorreference().additem(akBaseItem, (aiItemCount * 50))
  endif
 
  if (akBaseItem as miscobject) == gold003;check to see if the added item is your gold coin.
      getactorreference().removeitem(akBaseItem, aiItemCount)
      getactorreference().additem(akBaseItem, (aiItemCount * 100))
  endif
endEvent

 
What am I missing?
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...