Script to randomly place a "creature" a certain dist

Post » Fri Nov 06, 2009 3:46 am

Been playing Lord of the Rings Online a lot, and one thing I really like is the harvestable ore nodes that spawn on the landscape.
(Yes I realize they are placed there, but it is the feel of never knowing where ore might pop up that makes it fun, and the fact that the ore does keep spawning again.)

LadyE and Proudfoot made nice ore node "creatures" that you needed a mining pick to attack and harvest from.

I was thinking it would be fun to have a mod that had such nodes, and other things as well possibly, be placed near the PC randomly, if an item was in the PCs inventory.

It would mean you could have a mod with harvestable things that were not hand placed all over the map.

Is it possible, and would the things placed stay in the game memory and lag it down, or just be gone for good once they are "harvested"?

Please note that I am not a scripter, so would need the script written for me.
User avatar
CxvIII
 
Posts: 3329
Joined: Wed Sep 06, 2006 10:35 pm

Post » Fri Nov 06, 2009 1:54 pm

I made some assumptions about your needs. The code is somewhat adjustable, but if you want features I omitted, such as spawning ore inside caverns there will have to be some changes. As it is it only runs when the pick (just one of my assumptions) is in the player's inventory. The script does not run (and thereby spawn ore) just lying on the ground. I assumed you did not want ore spawning underwater (since your ore is actually a creature that could prove an interesting sight). The easiest way to do that was to make an elevation check since all water in exterior cells is at sea level. This would be problematic in an interior cell. In order to prevent the player from standing in one place waiting for the next ore to spawn, a cell change is required after the spawning of ore. Of course, the enterprising player could pass through a load door to achieve this, but I try not to invest too much time in saving the player from him/herself. However, it might be possible to close that exploit if you wish. The cell change, elevation check and random100 make the spawning pretty sporadic.

This is the code as I tested it. It depends on Morrowind only. With the frameCounter it is very efficient - but I added the memumode check to prevent player from standing with the menu open waiting for ore to spawn - at the very least it cost the player some time. The messageboxes were to help me judge the progress of the script while testing. You will want to comment them out before release, but you might welcome the feedback as you test and tweak the settings.

With these settings I spawned 4 ore (scribs) along the traditional (Ascadian Isles) route between Seyda Neen and Balmora. I think that is too frequent, and I suspected as much when I set the parameters. About half of that journey was 'at sea level' (below 500 units) so there was no chance of ore being spawned. You could lower that threshold elevation a little, but I think it is a reasonable minimum from preventing the spawning of ore in the water when the player is looking in that direction. The spawn distance of 2000 units can be changed. I would not want it so close to the player as to be noticeable, and depending on the mesh you are using it may not be noticeable at a near distance. Too far off and it is possible that the player will miss it entirely (turn in the path) or it will spawn in an undesirable location (such as water).

Other than changing the elevation cut-off. There are two ways of decreasing (or increasing) the frequency: increasing (or decreasing) the number of frame cycles for the script to return, and decreasing (or increasing) the value for Random100 to return as true. I feel a return on if ( frameCounter < 300 ) reasonable, and although I have a five percent chance, I was thinking two or even one percent as reasonable. I did not test for very long, and hardly at all at higher elevations so my personal opinion could change. Of course, it is entirely up to you to decide what is reasonable for your application. Happily there are a number of ways you could adjust the script to give the results you wish.

Begin rts_MinersPickScript; Attached to rts_miners_pick.; When in player's inventory it will spawn ore some distance in front of the player.short frameCountershort oreSpawnedfloat playerZif ( menumode == 1 )    returnendifif ( CellChanged == 1 ) ; must be above frame counter - true only one frame    set oreSpawned to 0    messagebox "Cell change - reset oreSpawned."endifset frameCounter to ( frameCounter + 1 )if ( frameCounter < 200 )    returnendifset frameCounter to 0if ( GetInterior == 1 )    returnendifif ( ( player->GetItemCount "rts_miners_pick" ) <= 0 )    returnendifset playerZ to ( player->GetPos Z )if ( ( playerZ ) < 500 )    messagebox "Player at sea level"    returnendifif ( oreSpawned == 1 )    messagebox "Ore already spawned this cell."    returnendifif ( Random100 >= 5 )    messagebox "Failed random chance."    returnendifset oreSpawned to 1PlaceAtPC "scrib" 1 2000 0messagebox "Ore spawned."End rts_MinersPickScript

User avatar
neil slattery
 
Posts: 3358
Joined: Wed May 16, 2007 4:57 am

Post » Fri Nov 06, 2009 4:36 am

Script definitely spawns the nodes. I made a crystal node version at first. I deleted the message boxes but the last, and headed off towards Balmora from Seyda Neen. Once I got high enough I got a message that crystal had spawned. As I went looking for it, got three more messages. Found the node and started fighting it. (Made it too tough I think).

By the time I defeated it and collected the crystal, many messages had popped up about crystals spawning. I saw another crystal and started fighting it. ROFL, must have been 20 crystal nodes that had all spawned on top of each other.

I see very interesting possibilities with the script beyond ore nodes. For example, in Dragon Warrior 4, there is a golden claw you get at the bottom of a pyramid. Powerful weapon, but as long as you have it with you, monsters are drawn to you.
Could be problematic like that in Morrowind though. Is is possible to have it so only when the item is equipped the monsters spawn?

And also, what should I do with the script so it spawns nodes very infrequently vs. rabid ore growth? ;)
I fear I am a complete noobie when it comes to scripting...
User avatar
Cash n Class
 
Posts: 3430
Joined: Wed Jun 28, 2006 10:01 am

Post » Fri Nov 06, 2009 6:36 am

And also, what should I do with the script so it spawns nodes very infrequently vs. rabid ore growth? ;)
I fear I am a complete noobie when it comes to scripting...

My last paragraph before the posting of the code describes how you can change the script so it spawns ore less frequently:

Change if ( ( playerZ ) < 500 ) to if ( ( playerZ ) < 600 ) for example.
Change if ( frameCounter < 200 ) to if ( frameCounter < 300 ) for example.
Change if ( Random100 >= 5 ) to if ( Random100 >= 2 ) for example.

I am unable to produce the deluge of ore that you seem to be experiencing (I retested across a longer journey). My script does not allow more than one spawning per cell (that is a cell change must take place after each spawn}. When you deleted the messageboxes did you also delete this entire block of code (or at least the return)?

if ( oreSpawned == 1 )
messagebox "Ore already spawned this cell."
return
endif


That is the only explanation I have for what you observe.
User avatar
Tracy Byworth
 
Posts: 3403
Joined: Sun Jul 02, 2006 10:09 pm

Post » Fri Nov 06, 2009 8:56 am

Thanks, I'll play around with it more. :)
User avatar
Amy Gibson
 
Posts: 3540
Joined: Wed Oct 04, 2006 2:11 pm

Post » Fri Nov 06, 2009 9:01 am

I do some of my clearest thinking while I am taking my exercise, so here are a few thoughts after coming off my run this morning.

Originally I introduced the frame count to make the script a little more efficient, but now that the delay is significant so will be the effect of different computer systems on the script's execution. A system with a large frame rate will generate ore more quickly (perhaps many times faster) than that of a older computer. I replaced it with a timer that is much more reliable. Now you can judge much more closely how it will perform for any player.

I had originally hoped that the elevation check would prevent spawning in most towns, but certainly some are higher than 500, Even Vivec with its cantons, and the Telvanni towers will place the player above the cut-off. I added checks for all settlements and the stronghold cells once development begins. I can just imaging claim-jumping prospector/guards rushing in to steal your find. Levitation could spoil things as well. If the player is levitating over water then the spawn could occur there. Also it is unreasonable for the player to spot the ore at a great height above the ground. I added a check for levitation. Since it is not reasonable for the player to be prospecting at night I added GameHour checks.

This is the version of the script I lately tested. It checks every five seconds, I shortened the spawn distance to 1500, and decreased the chance of success to two percent. Even with that I spawned four ore between Seyda Neen and Ald'ruhn (by main road through Balmora and Caldera). One occurrance was as I was just about to enter Caldara and appeared inside the settlement *sigh*. I still think that is too frequent. Changing the chance to one percent, and/or increasing the timer from five seconds would make it spawn less often.

I commented out all messages except for the last for your purposes. I do not know if you intend to keep a hint for the player when ore is found, but if you do I thought something less direct appropriate. Change it or comment it out as you wish.

Begin rts_MinersPickScript; Attached to rts_miners_pick.; When in player's inventory it will spawn ore some distance in front of the player.short oreSpawnedfloat timerfloat playerZif ( menumode == 1 )	returnendifif ( CellChanged == 1 ) ; must be above timer - true only one frame	set oreSpawned to 0;	messagebox "Cell change - reset oreSpawned."endifset timer to ( timer + GetSecondsPassed )if ( timer < 5 )	returnendifset timer to 0if ( GetInterior == 1 )	returnendifif ( ( player->GetItemCount "rts_miners_pick" ) <= 0 )	returnendifif ( oreSpawned == 1 );	messagebox "Ore already spawned this cell."	returnendifif ( GameHour >= 19 ) ; do not spawn at night	returnelseif ( GameHour < 7 )	returnendifset playerZ to ( player->GetPos Z )if ( ( playerZ ) < 500 ) ; do not spawn at or near water;	messagebox "Player at sea level"	returnendifif ( ( GetPCCell "Ald-ruhn" ) == 1 ) ; do not spawn in towns	returnelseif ( ( GetPCCell "Ald Velothi" ) == 1 )	returnelseif ( ( GetPCCell "Balmora" ) == 1 )	returnelseif ( ( GetPCCell "Buckmoth Legion Fort" ) == 1 )	returnelseif ( ( GetPCCell "Caldera" ) == 1 )	returnelseif ( ( GetPCCell "Dagon Fel" ) == 1 )	returnelseif ( ( GetPCCell "Ebonheart" ) == 1 )	returnelseif ( ( GetPCCell "Gnaar Mok" ) == 1 )	returnelseif ( ( GetPCCell "Gnisis" ) == 1 )	returnelseif ( ( GetPCCell "Hla Oad" ) == 1 )	returnelseif ( ( GetPCCell "Khuul" ) == 1 )	returnelseif ( ( GetPCCell "Maar Gan" ) == 1 )	returnelseif ( ( GetPCCell "Molag Mar" ) == 1 )	returnelseif ( ( GetPCCell "Moonmoth Legion Fort" ) == 1 )	returnelseif ( ( GetPCCell "Pelagiad" ) == 1 )	returnelseif ( ( GetPCCell "Sadrith Mora" ) == 1 )	returnelseif ( ( GetPCCell "Seyda Neen" ) == 1 )	returnelseif ( ( GetPCCell "Suran" ) == 1 )	returnelseif ( ( GetPCCell "Tel Aruhn" ) == 1 )	returnelseif ( ( GetPCCell "Tel Branora" ) == 1 )	returnelseif ( ( GetPCCell "Tel Mora" ) == 1 )	returnelseif ( ( GetPCCell "Tel Vos" ) == 1 )	returnelseif ( ( GetPCCell "Vivec" ) == 1 )	returnelseif ( ( GetPCCell "Vos" ) == 1 )	returnelseif ( ( GetPCCell "Wolverine Hall" ) == 1 )	returnendifif ( Stronghold >= 1 ) ; construction on strongholds has begun	if ( ( GetPCCell "Bal Isra" ) == 1 )		return	elseif ( ( GetPCCell "Odai Plateau" ) == 1 )		return	elseif ( ( GetPCCell "Uvirith's Grave" ) == 1 )		return	endifendifif ( ( player->GetEffect sEffectLevitate ) == 1 ) ; do not spawn when levitating	returnendifif ( Random100 >= 2 );	messagebox "Failed random chance."	returnendifset oreSpawned to 1PlaceAtPC "scrib" 1 1500 0messagebox "Ahead you notice rock outcropings of a sort associated with ebony ore."End rts_MinersPickScript

User avatar
Alycia Leann grace
 
Posts: 3539
Joined: Tue Jun 26, 2007 10:07 pm

Post » Fri Nov 06, 2009 12:35 pm

Thanks! It seems to be working well now. :)

Is there a way to have a script like this place monsters from a leveled list only when the item/weapon is equipped, a simpler version that does it say every certain length of time?
User avatar
Timara White
 
Posts: 3464
Joined: Mon Aug 27, 2007 7:39 am

Post » Fri Nov 06, 2009 5:02 pm

I rarely work with leveled lists. I know that they can be amended through scripts, but I do not believe it is possible to place creatures from such a list. However that should not be necessary. The effect of a leveled list can be scripted.

A leveled list checks the player's level and then based on random chance spawns a creature. A script can check the player's level and using Random100 place a particular creature some distance from the player. Since you do not script, you can describe what creatures at what levels at what percent chance that you want and I can code it for you. Or if you are feeling up to it, I can make a template script that you can adjust with the levels, creatures and chances. I will also need to know what time interval you want between spawns (it could be somewhat randomized without too much trouble), other restrictions (such as not in water or towns like in the previous script), exterior cells only (I hope), and what distance and direction from the player the creature is spawned. The latter could be problematic. Spawn too close and the player will notice if it is in front of the player (but not other directions), Spawn too far away and it could be place in an inconvenient or inappropriate location. The advantage of placing leveled creatures in the editor is that you can make certain the location is appropriate and it will spawn according to the player's AI distance setting (I think).
User avatar
Oyuki Manson Lavey
 
Posts: 3438
Joined: Mon Aug 28, 2006 2:47 am


Return to III - Morrowind