Help with a Player Shop Mod?

Post » Fri Nov 18, 2011 4:15 am

I've been playing skyrim for a couple days now, and the number one thing I really want is my own shop, so I went over to morrowind to see if I could make one as practice. As far as I can tell, this should work. Of course, doing it this way, I have to write out every single sellable item in the game, but I don't know any other way to do it.

Either way, I can't seem to get it to work. The script is definitely running, but they just don't ever sell. What's wrong? (Side question, how many seconds is a day in both Morrowind and Skyrim?)


Edit:
Also, to explain a little more about how it's supposed to work. Every hour (It's set to 1 second for testing) There's a 1 in 10 chance of an item selling. Once it sets itemsold to 1, it'll pick a random number, which corresponds to one of the possible sold items. If it doesn't sell anything, itemsold will remain at 1, and it'll loop back through until it sells something. I chose to do it this way (beyond it being the easiest way) because it will simulate buyers being less likely to find what they're looking for, if you don't have as wide of a variety of items in stock. Again, this still doesn't work though, so if anyone can help me out, I'd really appreciate it. I literally have no clue why it doesn't work... although I haven't scripted in quite awhile. (Not that I was ever good to begin with. lol)
Begin aaa_shopshort ironshortshort ironlongshort steelmaceshort itemsoldshort perhourshort skillshort randompriceshort randomitemset skill to Player -> GetMercantileset randomprice to Random, 50set randomitem to Random, 4set perhour to ( perhour + GetSecondsPassed )if ( perhour => 1 )	if ( Random, 11 == 1 )		set itemsold to 1		set perhour to 0	EndifEndif	if ( itemsold == 1 )	if ( randomitem == 1 )		if ( aaa_shopchest->GetItemCount "iron shortsword" => 1 )			aaa_shopchest->RemoveItem, "iron shortsword", 1			aaa_shopchest->AddItem, "Gold_001", randomprice + skill			set itemsold to 0			messagebox "shortsword sold"		Endif	Endif				if ( randomitem == 2 )		if ( aaa_shopchest->GetItemCount "iron longsword" => 1 )			aaa_shopchest->RemoveItem, "iron longsword", 1			aaa_shopchest->AddItem, "Gold_001", 50 + randomprice + skill			set itemsold to 0			messagebox "longsword sold"		Endif	Endif				if ( randomitem == 3 )		if ( aaa_shopchest->GetItemCount "steel mace" => 1 )			aaa_shopchest->RemoveItem, "steel mace", 1			aaa_shopchest->AddItem, "Gold_001", 75 + randomprice + skill			set itemsold to 0			messagebox "mace sold"		Endif	EndifEndifEnd

User avatar
Tiffany Castillo
 
Posts: 3429
Joined: Mon Oct 22, 2007 7:09 am

Post » Fri Nov 18, 2011 3:02 am

if ( Random, 11 == 1 )

I don't think this works in Morrowind (though it may well in Skyrim), try this instead:
set Temp to Random 11if ( Temp == 1 )

You'd also need "short Temp" at the top, of course.

Finally note that that's a 1 in 11 chance, not one in ten, because you could also get a zero.
User avatar
Symone Velez
 
Posts: 3434
Joined: Thu Sep 07, 2006 12:39 am

Post » Fri Nov 18, 2011 5:19 am

Okay, you might be right on that one. I'm pretty sure the problem was with the randomizing, so I'll give it a shot.

Edit:
Unfortunately, it still doesn't work. I did learn a few things though. Either the perhour variable, or the randomizing is causing the whole thing to not work (actually, I think it's both.)

I tried deleting this whole bit,
if ( perhour => 1 )	if ( chance == 1 )		set itemsold to 1		set perhour to 0	EndifEndif

and it did work, except the random numbers weren't working at all. The "set randomitem to random 3" was set to 1 for every single transaction, and the price didn't randomize at all. So, I think it's safe to say that random doesn't work at all, unless I'm just totally doing it wrong. I looked it up though, and as far as I can tell, this is right.

Since none of the random variables are changing (I thought they'd be different every frame, since scripts repeat like that, but apparently not.) I decided to make the shop only open from 8am - 8pm, which would give me an excuse to put the random variables in a while loop, but they still don't change each loop. Is there any way to cause it to re-randomize the numbers each loop?
Begin aaa_shopshort ironshortshort ironlongshort steelmaceshort itemsoldshort perhourshort skillshort randompriceshort randomitemshort chancefloat openif ( GetCurrentTime => 8 )	if ( GetCurrentTime <= 19 )		set open to 1	EndifEndifif ( GetCurrentTime => 20 )	if ( GetCurrentTime <= 7 )		set open to 0	EndifEndifwhile ( open == 1 )	set ironshort to ( randomprice + skill )	set ironlong to ( 50 + randomprice + skill )	set steelmace to ( 75 + randomprice + skill )	set skill to Player -> GetMercantile	set randomprice to Random 50	set randomitem to Random 3	set chance to Random 10	set perhour to ( perhour + GetSecondsPassed )	if ( perhour => 1 )		if ( chance == 1 )			set itemsold to 1			set perhour to 0		Endif	Endif		if ( itemsold == 1 )		if ( randomitem == 0 )			if ( aaa_shopchest->GetItemCount "iron shortsword" => 1 )				aaa_shopchest->RemoveItem, "iron shortsword", 1				aaa_shopchest->AddItem, "Gold_001", ironshort				set itemsold to 0				messagebox "shortsword sold"			Endif		Endif					if ( randomitem == 1 )			if ( aaa_shopchest->GetItemCount "iron longsword" => 1 )				aaa_shopchest->RemoveItem, "iron longsword", 1				aaa_shopchest->AddItem, "Gold_001", ironlong				set itemsold to 0				messagebox "longsword sold"			Endif		Endif					if ( randomitem == 2 )			if ( aaa_shopchest->GetItemCount "steel mace" => 1 )				aaa_shopchest->RemoveItem, "steel mace", 1				aaa_shopchest->AddItem, "Gold_001", steelmace				set itemsold to 0				messagebox "mace sold"			Endif		Endif	EndifEndwhileEnd

User avatar
Laura Ellaby
 
Posts: 3355
Joined: Sun Jul 02, 2006 9:59 am

Post » Fri Nov 18, 2011 4:42 am

Morrowind can be pretty picky about syntax sometimes. I'd try changing it to random, #. Use a MessageBox to show what value is being returned.
User avatar
Kaylee Campbell
 
Posts: 3463
Joined: Mon Mar 05, 2007 11:17 am

Post » Fri Nov 18, 2011 5:30 am

Morrowind can be pretty picky about syntax sometimes. I'd try changing it to random, #. Use a MessageBox to show what value is being returned.

I actually did have the comma at first, I just changed it right before posting it. It was the last thing I tried.
User avatar
carley moss
 
Posts: 3331
Joined: Tue Jun 20, 2006 5:05 pm

Post » Fri Nov 18, 2011 11:57 am

Alright, lets not add new complications until you have what's already there working. Unless I misunderstand what you're doing, a while loop is not appropriate here. The whole script is essentially a loop anyway, in that it will execute once each frame. You only need a while loop if you need something to execute repeatedly within a frame.
User avatar
katsomaya Sanchez
 
Posts: 3368
Joined: Tue Jun 13, 2006 5:03 am

Post » Fri Nov 18, 2011 4:54 am

Well, the while loop was to set the hours that the shop will be open, like I said.
User avatar
joeK
 
Posts: 3370
Joined: Tue Jul 10, 2007 10:22 am

Post » Fri Nov 18, 2011 8:24 am

if ( GetCurrentTime => 8 )        if ( GetCurrentTime <= 19 )                set open to 1        EndifEndifif ( GetCurrentTime => 20 )        if ( GetCurrentTime <= 7 )                set open to 0        EndifEndif

First, this is wrong. The second condition will never be met and "open" will be stuck forever at 1. Use this instead:
set open to 0if ( GetCurrentTime => 8 )        if ( GetCurrentTime <= 19 )                set open to 1        EndifEndif


Second, as you were told, "while" should not be used here. Simple "if" is enough.

Third, you use variables' values before setting them:
        set ironshort to ( randomprice + skill )        set ironlong to ( 50 + randomprice + skill )        set steelmace to ( 75 + randomprice + skill )        set skill to Player -> GetMercantile        set randomprice to Random 50


Fourth, this code does not count an hour of *game* time, but *one* second of real time:
        set perhour to ( perhour + GetSecondsPassed )        if ( perhour => 1 )                if ( chance == 1 )                        set itemsold to 1                        set perhour to 0                Endif        Endif

User avatar
krystal sowten
 
Posts: 3367
Joined: Fri Mar 09, 2007 6:25 pm

Post » Fri Nov 18, 2011 11:48 am

=>
User avatar
Queen of Spades
 
Posts: 3383
Joined: Fri Dec 08, 2006 12:06 pm

Post » Fri Nov 18, 2011 4:55 pm

GetSecondsPassed and GetMercantile are floats...

I am smart.

Okay, I've gotten everything to work, except when it sells, it only gives me 1 gold. I checked the value of ironshort with a messagebox, and it's randomizing properly... so I guess I just can't use variables with additem or something?
User avatar
Mel E
 
Posts: 3354
Joined: Mon Apr 09, 2007 11:23 pm

Post » Fri Nov 18, 2011 12:55 pm

guess I just can't use variables with additem or something?
You can only in dialog result window (script is not pre-compiled there, just interpreted on the fly). In a standard script usually you use while loops (for fast/heavy 1 frame script) or if (for slower/less heavy script) loops, e.g.
begin testScriptlong goldset gold to Random  10001while ( gold >= 1000 )	player->additem "gold_001" 1000	set gold to ( gold - 1000 )endwhilewhile ( gold >= 100 )	player->additem "gold_001" 100	set gold to ( gold - 100 )endwhilewhile ( gold >= 10 )	player->additem "gold_001" 10	set gold to ( gold - 10 )endwhilewhile ( gold > 0 )	player->additem "gold_001" 1	set gold to ( gold - 1 )endwhileend

User avatar
Everardo Montano
 
Posts: 3373
Joined: Mon Dec 03, 2007 4:23 am

Post » Fri Nov 18, 2011 4:50 pm

Ah, thanks. That works great.

Looks like everything's good to go now.

Is it actually okay to write out each item individually though? I mean, this is going to be a good 5000+ line script, with hundreds of variables, so I'm not sure. lol




Oh, and I just thought of something else... what if you wanted to sell an item that you enchanted? How would that work?
User avatar
Amy Melissa
 
Posts: 3390
Joined: Fri Jun 23, 2006 2:35 pm

Post » Fri Nov 18, 2011 1:43 am

Is it actually okay to write out each item individually though? I mean, this is going to be a good 5000+ line script, with hundreds of variables, so I'm not sure. lol
You may have to split/chain some scripts. If you need a script using similar repeated code with different object ids, you may want to take a look to http://sourceforge.net/projects/mwedit/ script templates, they are useful if/when they work.
Oh, and I just thought of something else... what if you wanted to sell an item that you enchanted? How would that work?
As enchanted item id is changed by the engine, you would probably need a scripting extender to scan your inventory (this would probably also solve previous problem).
User avatar
Natalie Taylor
 
Posts: 3301
Joined: Mon Sep 11, 2006 7:54 pm

Post » Fri Nov 18, 2011 10:28 am

Ah. Well that doesn't bode well for this mod being possible in skyrim any time soon then.
User avatar
Talitha Kukk
 
Posts: 3477
Joined: Sun Oct 08, 2006 1:14 am


Return to III - Morrowind