Help using "tokens"

Post » Tue Jun 19, 2012 2:00 pm

I'm trying to use tokens to give weight to coins however it's not appearing to work. It compiles OK (no errors) but my weight doesn't increase upon picking up the coins. I know a lot of people associate tokens with save bloat, but I can't think of another way to do this. The reason I'm not just giving the coins weight is because then they won't auto pick-up in stacks like gold does.

Here is what I have so far.

CoinToken is obviously the token I'm using. AncientNordCoin is the coin (and the item the script is attached to).

Both properties are defined in the properties window in the item the script is attached to.

Also, do I need to fill out any special fields for the token? I just created a blank Armor ref, renamed it, gave it some weight, and made sure to check off "playable"

Spoiler

Scriptname HaraldWeight extends MiscObject  {This will add/remove CoinTokens when Haralds are picked up/dropped to simulate weight.}int NumberOfCoinsArmor property CoinToken autoMiscObject property AncientNordCoin autoEvent OnContainerChanged(ObjectReference NewContainer, ObjectReference OldContainer)	if (OldContainer && !NewContainer)		NumberOfCoins = OldContainer.GetItemCount (CoinToken)		OldContainer.removeitem (CoinToken, NumberOfCoins, true)		NumberOfCoins = OldContainer.GetItemCount (AncientNordCoin)		OldContainer.additem (CoinToken, NumberOfCoins, true)	elseif (NewContainer && !OldContainer)		NumberOfCoins = NewContainer.GetItemCount (CoinToken)		NewContainer.removeitem (CoinToken, NumberOfCoins, true)		NumberOfCoins = NewContainer.GetItemCount (AncientNordCoin)		NewContainer.additem (CoinToken, NumberOfCoins, true)	else		NumberOfCoins = OldContainer.GetItemCount (CoinToken)		OldContainer.removeitem (CoinToken, NumberOfCoins, true)		NumberOfCoins = OldContainer.GetItemCount (AncientNordCoin)		OldContainer.additem (CoinToken, NumberOfCoins, true)		NumberOfCoins = NewContainer.GetItemCount (CoinToken)		NewContainer.removeitem (CoinToken, NumberOfCoins, true)				NumberOfCoins = NewContainer.GetItemCount (AncientNordCoin)		NewContainer.additem (CoinToken, NumberOfCoins, true)	endifEndEvent  

I have a feeling I'm doing it all wrong :P
User avatar
Kaley X
 
Posts: 3372
Joined: Wed Jul 05, 2006 5:46 pm

Post » Tue Jun 19, 2012 4:44 pm

I think it would be easier to not use tokens at all. Why not use a quest script that updates every x number of seconds. On each update it checks how much gold the player has and modifies the players Carry Weight actor value based on that.
User avatar
Christine
 
Posts: 3442
Joined: Thu Dec 14, 2006 12:52 am

Post » Tue Jun 19, 2012 10:06 am

Actually using the player's Actor Value "InventoryWeight" might be even better.
User avatar
ILy- Forver
 
Posts: 3459
Joined: Sun Feb 04, 2007 3:18 am

Post » Tue Jun 19, 2012 5:01 am

Uhh, isn't there a 'gold' item in the game you can just give it a weight value? Or does that not work hence the 'token' system?

Otherwise, scripting like your doing is about the only way you can go about doing it..
as for it not working... not sure. not a scripting pro...
User avatar
Chantelle Walker
 
Posts: 3385
Joined: Mon Oct 16, 2006 5:56 am

Post » Tue Jun 19, 2012 4:52 pm

Coins don't go in inventory, so you have to fake it somehow.

Best way is, as said above, to manipulate - each turn, or few turns - the "InventoryWeight" variable with a bit of script that assumes a weight per coin - Using RegisterForUpdate.

But, like you say, this will create save bloat ... and the longer the game, the more bloat you will get.

tbh: I doubt it is worth it ... unless you want really heavy coins?
User avatar
ChloƩ
 
Posts: 3351
Joined: Sun Apr 08, 2007 8:15 am

Post » Tue Jun 19, 2012 2:26 pm

As far as I know, any use of Register For Update will create save game bloat unless deregister is also very well coded.

Depends how he/she wants to do it ... but (as money is spent, given and picked up), RegisterForUpdate seems the easiest way to keep checking and amending weight.

You can do it ... the wiki has a small piece on how to code RFU (and deregister) without spawning a million new process threads ... but like I say - as far as I know - your coding needs to be tight and well thought out, or bloat occurs.

(Like I put, too, I doubt there is much value in it, given coins are very light compared to shields ... but hey, who am I to say)
I know the Wiki does - I figured out how to fix it for my Crime Overhaul mod, which uses RegisterForUpdate. :tongue:
User avatar
No Name
 
Posts: 3456
Joined: Mon Dec 03, 2007 2:30 am

Post » Tue Jun 19, 2012 3:56 pm

How would this create save-game bloat? Even if he goes with the method of adding / subtracting weighted items (much like I did in my Gold Mod for Oblivion), that's not save-game bloat.
As far as I know, any use of Register For Update will create save game bloat unless deregister is also very well coded.

Depends how he/she wants to do it ... but (as money is spent, given and picked up), RegisterForUpdate seems the easiest way to keep checking and amending weight.

You can do it ... the wiki has a small piece on how to code RFU (and deregister) without spawning a million new process threads ... but like I say - as far as I know - your coding needs to be tight and well thought out, or bloat occurs.

(Like I put, too, I doubt there is much value in it, given coins are very light compared to shields ... but hey, who am I to say)
User avatar
Matt Bee
 
Posts: 3441
Joined: Tue Jul 10, 2007 5:32 am

Post » Tue Jun 19, 2012 10:25 am

I know the Wiki does - I figured out how to fix it for my Crime Overhaul mod, which uses RegisterForUpdate. :tongue:
Yeah, it works fine if you understand what is does and how to deregister it ... The wiki has a good example of only registering for one turn, then checking if you need to register again or deregister

I used that a couple of times and it works fine.

But if you don't understand it, or you're coding isn't bang on ... then it's very easy to get lots of bloat.

RFU is one of those functions that is almost too dangerous to include ;)
User avatar
Chloe Botham
 
Posts: 3537
Joined: Wed Aug 30, 2006 12:11 am

Post » Tue Jun 19, 2012 6:04 pm

Yeah, it works fine if you understand what is does and how to deregister it ... The wiki has a good example of only registering for one turn, then checking if you need to register again or deregister

I used that a couple of times and it works fine.

But if you don't understand it, or you're coding isn't bang on ... then it's very easy to get lots of bloat.

RFU is one of those functions that is almost too dangerous to include :wink:
By that logic, so is the Disable command... because you could disable the player and crash the game (well, in Oblivion at least).

And where is that Wiki post? I couldn't find it. I personally fixed the bloating issue using a "polling" state and an "empty" state that kept the script from running multiple threads.
User avatar
joseluis perez
 
Posts: 3507
Joined: Thu Nov 22, 2007 7:51 am

Post » Tue Jun 19, 2012 10:41 am

By that logic, so is the Disable command... because you could disable the player and crash the game (well, in Oblivion at least).

And where is that Wiki post? I couldn't find it. I personally fixed the bloating issue using a "polling" state and an "empty" state that kept the script from running multiple threads.

http://www.creationkit.com/OnUpdate_-_Form

(so, not where it should be :wink:)


And I know, many functions are dangerous if you're not 100% on what they do and how to use them. I'm a bit surprised so many were left in ... though I do get the feeling some were taken away before release
User avatar
Dawn Porter
 
Posts: 3449
Joined: Sun Jun 18, 2006 11:17 am

Post » Tue Jun 19, 2012 1:34 pm

@SinisterDeaths - The reason I can't just change the weight of the item itself is because then it will not be picked up in stacks (like gold or arrows are) and instead will be picked up like a stack of daggers (where you have to specify the size of the stack each time you pick it out of a container).

@Reneer and h4vent - Wowza...I'm not sure I understand any of that. Would the script still be attached to the item? If I put RegisterForUpdate in the script, does that mean it will run the OnUpdate block every time specified by the RegisterForUpdate for EVERY instance of the item in the game world?
User avatar
xemmybx
 
Posts: 3372
Joined: Thu Jun 22, 2006 2:01 pm

Post » Tue Jun 19, 2012 3:31 am

If your script is to be attached to coins, then it should extend http://www.creationkit.com/ObjectReference_Script, not http://www.creationkit.com/MiscObject_Script, as each instance of the script would run on an ObjectReference instance with base object type MiscObject.

However, I'd recommend not attaching your script to coins. Instead, I'd say you should use a script with an alias set to the player that has a script attached extending http://www.creationkit.com/ReferenceAlias_Script that either uses a chain of http://www.creationkit.com/RegisterForSingleUpdate_-_Form and http://www.creationkit.com/OnUpdate_-_Form, or listens for http://www.creationkit.com/OnItemAdded_-_ObjectReference and http://www.creationkit.com/OnItemRemoved_-_ObjectReference. I'd say using OnUpdate would be the preferred approach here.

Also, you can use a http://www.creationkit.com/FormList as the parameter of http://www.creationkit.com/GetItemCount_-_ObjectReference, which will shorten your code and make changing the types of object that you count much easier.

Cipscis
User avatar
N3T4
 
Posts: 3428
Joined: Wed Aug 08, 2007 8:36 pm

Post » Tue Jun 19, 2012 11:30 am

If your script is to be attached to coins, then it should extend http://www.creationkit.com/ObjectReference_Script, not http://www.creationkit.com/MiscObject_Script, as each instance of the script would run on an ObjectReference instance with base object type MiscObject.

However, I'd recommend not attaching your script to coins. Instead, I'd say you should use a script with an alias set to the player that has a script attached extending http://www.creationkit.com/ReferenceAlias_Script that either uses a chain of http://www.creationkit.com/RegisterForSingleUpdate_-_Form and http://www.creationkit.com/OnUpdate_-_Form, or listens for http://www.creationkit.com/OnItemAdded_-_ObjectReference and http://www.creationkit.com/OnItemRemoved_-_ObjectReference. I'd say using OnUpdate would be the preferred approach here.

Also, you can use a http://www.creationkit.com/FormList as the parameter of http://www.creationkit.com/GetItemCount_-_ObjectReference, which will shorten your code and make changing the types of object that you count much easier.

Cipscis
nods. nice, man :)
User avatar
Rudi Carter
 
Posts: 3365
Joined: Fri Sep 01, 2006 11:09 pm

Post » Tue Jun 19, 2012 4:31 pm

Thanks for all the insight. I've got it working now! Of course the only issue is that weight won't update while in a menu (I don't think you can get around that using "OnUpdate").

One thing, near the top of the thread it was mentioned that using OnUpdate/RegisterForUpdate could cause save bloat. Would you mind checking my code to see if I've done things properly before I release the mod to the public :P

Scriptname CoinWeight extends ReferenceAlias{This will add/remove CoinTokens when Haralds are picked up/dropped to simulate weight.}int NumberOfCoinsint NumberOfTokensArmor property CoinToken autoFormList property Coins autoActor property Player autoEvent OnInit()	RegisterForSingleUpdate(1)endEventEvent OnUpdate()	NumberOfCoins = Player.GetItemCount(Coins)	NumberOfTokens = Player.GetItemCount(CoinToken)	Player.RemoveItem (CoinToken, NumberOfTokens, true)	Player.Additem (CoinToken, NumberOfCoins, true)	RegisterForSingleUpdate(1)endEvent
User avatar
steve brewin
 
Posts: 3411
Joined: Thu Jun 21, 2007 7:17 am

Post » Tue Jun 19, 2012 9:33 am

Using http://www.creationkit.com/RegisterForSingleUpdate_-_Form as you've done, to create a chain of single updates, will prevent save bloat from registering for updates. That becomes a problem when http://www.creationkit.com/RegisterForUpdate_-_Form is used with a delay shorter than the length of time that may be taken for the http://www.creationkit.com/OnUpdate_-_Form event to complete.

I remember in Fallout 3 there was a but where invisible (i.e. with messages hidden) manipulating the player's inventory while it was being viewed wouldn't update some of the visuals, but adding and immediately removing a visible item would fix that. Perhaps you could try that and see if it works for Skyrim as well?

Cipscis
User avatar
Multi Multi
 
Posts: 3382
Joined: Mon Sep 18, 2006 4:07 pm


Return to V - Skyrim