Jump to content


Photo

Random Placement of Items


  • Please log in to reply
17 replies to this topic

#1 Bookwyrme

Bookwyrme
  • Modder
  • 5804 posts

Posted 01 April 2007 - 03:25 PM

Is it possible to make sure that certain items get into the game but are randomly scattered throughout the game's containers?

Mods: <a data-cke-saved-href="http://www.shsforums...-auroras-shoes/">Aurora's Shoes (released),

 


 

 


#2 GeN1e

GeN1e

    A very GAR character

  • Modder
  • 1604 posts

Posted 01 April 2007 - 05:42 PM

For each started game - yes.

Retired from modding.


#3 Bookwyrme

Bookwyrme
  • Modder
  • 5804 posts

Posted 01 April 2007 - 05:43 PM

But not for a mod added later?

Mods: <a data-cke-saved-href="http://www.shsforums...-auroras-shoes/">Aurora's Shoes (released),

 


 

 


#4 igi

igi

    IESDP Guardian

  • Administrator
  • 1058 posts

Posted 02 April 2007 - 04:29 AM

Is it possible to make sure that certain items get into the game but are randomly scattered throughout the game's containers?


Yes.
It's on the todo list for iiItem (which at the moment just settles for placing unique items in stores).
I'll let you know when it's done (a weidu macro to iterate over containers in areas), unless someone else wants to write it (or has a simpler way).

Visit the IESDP


#5 GeN1e

GeN1e

    A very GAR character

  • Modder
  • 1604 posts

Posted 02 April 2007 - 05:26 AM

It's on the todo list for iiItem (which at the moment just settles for placing unique items in stores).
I'll let you know when it's done (a weidu macro to iterate over containers in areas), unless someone else wants to write it (or has a simpler way).

I admit that Weidu isn't a strong part of mine, but this method seems to randomize item placement only during installiation and once installed there is no other way to change placements without reinstalliation?
Wouldn't scripts be better?

PS After thinking a bit more, I have come to conclusion that scripts won't be of too much help. They allow semirandom placement only (an item can be found in one of X certain places, not in any one). Still, going with scripts makes possible to get new order in every game (in already started one and in every next).

Edited by GeN1e, 02 April 2007 - 10:00 AM.

Retired from modding.


#6 Miloch

Miloch

    Barbarian

  • Modder
  • 6573 posts

Posted 05 April 2007 - 12:27 AM

Still, going with scripts makes possible to get new order in every game (in already started one and in every next).

This was the method I suggested to Bookwyrme before suggesting this be asked of the wider community (I also thought iiItem might've already had functionality like this). It should suit the purposes of Bookwyrme's items, which could be found in a finite (though perhaps large) number of places, but not every conceivable place. Unless I'm wrong though, random placement via TP2 would have the same shortcoming as via script - you still have to have a finite list of where you'll be 'randomly' putting the items. Other codebases I've worked on had commands like 'STREW' which would literally scatter items anywhere throughout the world.

So I guess it's up to Bookwyrme to come up with a list of possible locations, however long that list might be. The coding/scripting itself should be pretty simple - more looking up references than actual writing probably.

Edited by Miloch, 05 April 2007 - 12:28 AM.

Infinity Engine Contributions
Aurora * BG1 NPC * BG1 Fixpack * Haiass * Infinity Animations * Level 1 NPCs * P5Tweaks
PnP Free Action * Thrown Hammers * Unique Containers * BG:EE * BGII:EE * IWD:EE
================================================================
Player & Modder Resources
BAM Batcher * Creature Lister * Creature Checker * Creature Fixer * Tutu/BGT Area Map & List * Tutu Mod List
================================================================
"Infinity turns out to be the opposite of what people say it is. It is not 'that which has nothing beyond itself' that is infinite, but 'that which always has something beyond itself'." -Aristotle


#7 Cuv

Cuv

    Area Maker (retired)

  • Modder
  • 925 posts

Posted 05 April 2007 - 06:23 AM

If you just want to get them into the game, then create a WeiDU install that just appends or changes the RNDTREAS.2DA. All kinds of monsters and containers use this 2DA throughout the game. I am not sure what type of items you are talking about... if they are quest items, you will need to be more careful.

This will add your items to any place that calls for a random treasure item... or you can replace an existing random treasure item to place your items more specifically. Then you can use scripts to bring in these items on certain creatures or in certain containers. This will work in a mod and you don't have to start a new game to see the items appear. We did something similar for RTW.

RNDTREAS
2DA V1.0
*
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
POOR MISC19 004 SCRL75 001 001 001 001 001 001 001 001 001 001 001 002 002 003 003 MISC16
AVERAGE RNDMAG01 MISC23 AMUL05 MISC17 015 012 SCRL75 008 006 003 001 001 007 009 RNDSCR01 MISC18 MISC22 AMUL06 RNDMAG01
WELL_OFF RNDMAG01 RNDMAG01 AMUL08 MISC20 034 AMUL09 RNDSCR01 008 009 RING11 023 RNDSCR01 RING14 MISC26 MISC25 057 MISC27 MISC28 RNDMAG01
WEALTHY RNDMAG02 RNDMAG01 MISC37 MISC35 RING16 AMUL07 RNDSCR02 047 038 029 AMUL09 RING10 RING15 RNDSCR02 RING13 RING17 MISC34 RNDMAG01 RNDMAG02
RICH RNDMAG02 RNDMAG02 RNDMAG01 RNDMAG01 AMUL12 AMUL13 AMUL10 MISC29 MISC21 073 MISC24 RNDSCR03 MISC34 MISC38 RNDSCR03 RNDMAG01 RNDMAG01 RNDMAG02 RNDMAG02
RTWTRE01 SCRL81 SCRL99 SCRLA5 SCRL6U SCRL95 SCRL6E SCRL93 SCRL1V SCRL6J SCRL3G SCRLA8 SCRL77 SCRL6W SCRL7G SCRL72 SCRL1I SCRL76 SCRL1N SCRL66

RTWTRE02 013 026 004 009 235 002 021 001 003 004 SCRL75 007 065 028 031 001 006 094 001

RTWTRE03 SW1HO5 BLUN13 SPER06 STAF19 BRAC14 SHLD23 HELM05 PLAT05 SHLD17 BELT06 HAMM06 SW2H20 SW1H72 RING22 CHAN05 PLAT02 RING07 BOOT03 XBOW18

RTWTRE04 AMUL05 MISC17 AMUL09 RING11 MISC37 MISC44 MISC23 033 MISC28 RING14 MISC34 007 RING17 MISC22 MISC45 RING13 MISC16 RNDTRE01 008


Cuv

#8 Miloch

Miloch

    Barbarian

  • Modder
  • 6573 posts

Posted 05 April 2007 - 09:30 PM

These are in fact quest items and as such, should be unique. Would you be able to prevent an item from spawning more than once with this method? It'd probably work great for igi's iiItems though ;). Also, what do the numbered values like 004, 002 etc. represent in this table?

Infinity Engine Contributions
Aurora * BG1 NPC * BG1 Fixpack * Haiass * Infinity Animations * Level 1 NPCs * P5Tweaks
PnP Free Action * Thrown Hammers * Unique Containers * BG:EE * BGII:EE * IWD:EE
================================================================
Player & Modder Resources
BAM Batcher * Creature Lister * Creature Checker * Creature Fixer * Tutu/BGT Area Map & List * Tutu Mod List
================================================================
"Infinity turns out to be the opposite of what people say it is. It is not 'that which has nothing beyond itself' that is infinite, but 'that which always has something beyond itself'." -Aristotle


#9 Cuv

Cuv

    Area Maker (retired)

  • Modder
  • 925 posts

Posted 06 April 2007 - 06:38 AM

These are in fact quest items and as such, should be unique. Would you be able to prevent an item from spawning more than once with this method? It'd probably work great for igi's iiItems though ;).


I'd have to give that some thought, but it seems do-able. Since they are unique items, perhaps narrow down where they could occur and run a snippet in the area scripts to look for those items and possible change them. The items don't actually get created until you enter that area... the random number generation doesnt happen until you are there and then it gets saved in the cache.

Maybe just create one entry item to be added to the RNDTREAS.2DA... replace a common useless item. This new item would essentially be every quest item you have. Set the item to run a script with variables that check to see which actual entry was produced... or have that script simply choose the items in sequential order starting at the top of the list each time that item is called for. Eventually all your items would be produced??? Just thinking out loud. Might come up with some clearer answers in the near future.

Also, what do the numbered values like 004, 002 etc. represent in this table?


Honestly, I have been away from modding for over a year and I simply don't remember what those values mean...hehe. I bet someone who is actively immersed in 2DA values could tell you.

Wait... I remember. That is gold!!!


Cuv

Edited by Cuv, 06 April 2007 - 06:40 AM.


#10 Zyraen

Zyraen
  • Modder
  • 1402 posts

Posted 06 April 2007 - 08:06 AM

If nothing else, welcome back to the Modding world, Cuv :)

Meantime, I had thought about if such an idea were possible for myself, but I truly don't see it happening just yet I think for what I know of coding.

kiyos.jpg____btlbn2.gif____kovaS.jpg
Love between a Law Enforcer and a Fugitive - can such a thing even happen?
SoA Release - Overview / Download Links

Zyraen's Miscellaneous Mods - Ust Natha Accelerator, item tweaks, XP caps, The Ub3r Reaver Kit, and much more...
Spellhold Gauntlet - more than just a Spellhold-Be-Gone
Hidden Kits - hidden dual-classed kits with a twist for progression


#11 Cuv

Cuv

    Area Maker (retired)

  • Modder
  • 925 posts

Posted 07 April 2007 - 07:53 AM

If nothing else, welcome back to the Modding world, Cuv :)



Thank you very much Zyraen. I am going to slowly get back into the modding scene as my time permits. Some unfinished smaller projects I want to get done before I tackle RTW again. Glad to see most people are still around. Anyone is free to PM me if they need any help with areas and I will help best I can in this forum if I think I can answer anything :rolleyes:

Cuv

#12 Miloch

Miloch

    Barbarian

  • Modder
  • 6573 posts

Posted 07 April 2007 - 01:41 PM

Since they are unique items, perhaps narrow down where they could occur and run a snippet in the area scripts to look for those items and possible change them. The items don't actually get created until you enter that area... the random number generation doesnt happen until you are there and then it gets saved in the cache.

That's kinda what we were thinking of doing - extending area scripts via randomisation to place the items.

Maybe just create one entry item to be added to the RNDTREAS.2DA... replace a common useless item. This new item would essentially be every quest item you have. Set the item to run a script with variables that check to see which actual entry was produced...

How does an item run a script? Maybe we could have the main CRE (to whom you return the items) trigger the random item placement, and increment a variable so it only happens once for each item. But I still don't see how we'd make use of RNDTREAS.2DA. If I understand that table correctly (I probably don't), it seems to spawn a random treasure under certain circumstances any time its called for. I don't know if there's anything that limits entries from respawning, though I haven't really looked at any scripts that make use of it. In theory, you could add and delete entries from the table via scripting, or TP2 code at least, but I still can't think of a way of preventing multiple spawnings just with that alone. Maybe you can.

Infinity Engine Contributions
Aurora * BG1 NPC * BG1 Fixpack * Haiass * Infinity Animations * Level 1 NPCs * P5Tweaks
PnP Free Action * Thrown Hammers * Unique Containers * BG:EE * BGII:EE * IWD:EE
================================================================
Player & Modder Resources
BAM Batcher * Creature Lister * Creature Checker * Creature Fixer * Tutu/BGT Area Map & List * Tutu Mod List
================================================================
"Infinity turns out to be the opposite of what people say it is. It is not 'that which has nothing beyond itself' that is infinite, but 'that which always has something beyond itself'." -Aristotle


#13 Cuv

Cuv

    Area Maker (retired)

  • Modder
  • 925 posts

Posted 07 April 2007 - 07:57 PM

How does an item run a script? Maybe we could have the main CRE (to whom you return the items) trigger the random item placement, and increment a variable so it only happens once for each item. But I still don't see how we'd make use of RNDTREAS.2DA. If I understand that table correctly (I probably don't), it seems to spawn a random treasure under certain circumstances any time its called for. I don't know if there's anything that limits entries from respawning, though I haven't really looked at any scripts that make use of it. In theory, you could add and delete entries from the table via scripting, or TP2 code at least, but I still can't think of a way of preventing multiple spawnings just with that alone. Maybe you can.


Well, like I said, it sounds do-able... but havent really tried.

Here's my train of thought (and it might not even work like we want):

1. Call your item something like "RndQst.itm". Does nothing, no effects of any kind
2. Add this item in the first column of the Rndtreas.2da replacing a couple of the Gold entries
3. Create a new 2da called RNDQST.2da. This is where you list your table of quest items
4. Once you have something like this...anybody's mod can add their quest items randomly if they wish

Any time RndQst gets chosen randomly by the engine, this will take you to your new 2da. Heck, you could have multiple columns with only one quest item on each column... that would narrow the chances a bit of multiples being produced.

More ideas...Here's where it gets tricky:

There are a few ways to run other resource files on items... the best is with EFF files
You can take your first item and give it an EFF effect which might call for a "create an item on condition", or set a global variable to help you control the items produced, or run a script, or whatever.... I see plenty of possible workarounds... but just not sure how complicated it might get. You would certainly need some scripts running somewhere else to control the action... either on areas, containers or creatures.

Not sure if this is helpful, but it should get us thinking.

Cuv

#14 Miloch

Miloch

    Barbarian

  • Modder
  • 6573 posts

Posted 07 April 2007 - 08:42 PM

I think I get how rndtreas works now, by consulting the IESDP and hacking around the game. By default, the table has 5 rows, going from 'poor' to 'rich'. Now there are a bunch (I mean a *bunch*) of CREs and probably containers in the game that have items rnditem01 to rnditem05 that corresponds to a row on this table 1 through 5, going from 'poor' to 'rich'. When the game finds one of these items, it rolls 2d10 to get a column that corresponds to an item in that row. And as you say, this can in turn lead to another table with more items. So you can weight the randomisation differently for different items.

But, as I said, I see of no graceful way of limiting each item to one. There are tons of CREs with the same virtual item (let's say rnditem03). In theory, there could be two of these in the same area that roll the same die and therefore end up with the same quest item, if we extended the table to include quest items.

I thought perhaps you could extend the script of every CRE and every area containing one of these items to delete an entry from rndtreas.2da every time it finds a specific one. But I don't see any graceful way to do that, like I said, that won't lead to potential duplication. I'm not even sure when the engine checks for the specific item. If it's on area creation or game initialisation, we're probably out of luck. If it's on CRE death, we might be in better shape, but it'd still be theoretically possible to wipe out a couple CREs simultaneously who'd end up drawing the same card, so to speak.

So I think we're back to our original idea of coming up with a master script of all possible locations (CREs and area containers) where these items could possibly be, and when we generate one, increment a variable so it can't be generated again. Using EFFs and such sounds like it would make it even more complex.

Still, I think the rndtreas option would be a great way for mods like iiItem to spawn random items that aren't unique. Maybe I'll even see if I can use it for my Lost Items remake ;).

Infinity Engine Contributions
Aurora * BG1 NPC * BG1 Fixpack * Haiass * Infinity Animations * Level 1 NPCs * P5Tweaks
PnP Free Action * Thrown Hammers * Unique Containers * BG:EE * BGII:EE * IWD:EE
================================================================
Player & Modder Resources
BAM Batcher * Creature Lister * Creature Checker * Creature Fixer * Tutu/BGT Area Map & List * Tutu Mod List
================================================================
"Infinity turns out to be the opposite of what people say it is. It is not 'that which has nothing beyond itself' that is infinite, but 'that which always has something beyond itself'." -Aristotle


#15 igi

igi

    IESDP Guardian

  • Administrator
  • 1058 posts

Posted 08 April 2007 - 01:34 AM

I seriously doubt you can get the control you are looking for from using RND*.2da.

The best way to get something like this in-game is (obviously) scripting - but you run into trouble in that you can only address objects not in the current area (so, i.e. you can only add items to areas as the party reaches them). So, you either need a shed-load of blocks in either every area script (or 1 script per area and an invisible cre), baldur.bcs or dplayerx.bcs.

The alternative, which doesn't quite fit in the game, but would be quite neat, would be to place the items via RND*.2da, but have them all as 'mysterious item'. You'd ident the item via its conversable button, and in the resulting dialog you could then check/set globals and TakeItemReplace to give the relevant item. If all the quest items have already been given, you could give a random potion/sword etc.


Still, I think the rndtreas option would be a great way for mods like iiItem to spawn random items that aren't unique. Maybe I'll even see if I can use it for my Lost Items remake.


I prefer the control of doing it all myself at install time - that way I can handle unique and on-unique together, and set percentages for each item individually (I can also restrict to specific creature/area types etc, and change the percentages based on items the creature/container already has).
Besides, I think it looks cool to see so much scolling text :)

Visit the IESDP


#16 Cuv

Cuv

    Area Maker (retired)

  • Modder
  • 925 posts

Posted 08 April 2007 - 06:34 AM

Thanks Igi for pointing that stuff out... but now I am curious to see if I can get it to work at all. Will see what I can come up with. Won't be the first time I have had to make the impossible possible ;)

Will post here if I come up with something.

Cuv

#17 Cuv

Cuv

    Area Maker (retired)

  • Modder
  • 925 posts

Posted 08 April 2007 - 10:09 AM

Okay, did some testing and this is an alternative that I came up with that works:

Use creatures listed in the SpawnGrp.2da ;)

For my experiment I chose RDUndead. This group includes 3 mummies (Mummy01) and 2 Ghasts (Ghast01).
Since every time I bring in the mummy, it is essentially the same creature with the same script and death variable, so I had to check for items as if it was the same creature all the time.

I exported and renamed some items to MyQst01, MyQst02, etc.

I gave the creature a simple script to distribute these items on their person as they are created.

I created a WeiDU install to help with the testing. I tested them alone and in groups of eight or more.

I found that the script works just fine and once the 7 items are created, that's all that happens with these creatures.

Here is my TP2:

// MyQuestItems (MQI) test by Cuv April 8, 2007

//////////////////////////////////////////////////////////////////////////////////////
// backup game files
BACKUP ~MQI\backup~
//////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////
// author info
AUTHOR ~Lorne Ledger <cuvieronius@aol.com>~
//////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////
// language options
///LANGUAGE ~English~ ~english~ ~_trans/english/MQI.tra~
//////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////
// Quest item test
BEGIN ~MQI~
//////////////////////////////////////////////////////////////////////////////////////

// ...cres
// ......basic creatures
COPY ~MQI/cre/Mummy01.cre~ ~override/Mummy01.cre~
WRITE_ASCII 0x248 ~MyQuest~ // Quest item test script

// ...itms
// ......Test Quest Items
COPY ~MQI/Itm/MyQst01.itm~ ~override~
COPY ~MQI/Itm/MyQst02.itm~ ~override~
COPY ~MQI/Itm/MyQst03.itm~ ~override~
COPY ~MQI/Itm/MyQst04.itm~ ~override~
COPY ~MQI/Itm/MyQst05.itm~ ~override~
COPY ~MQI/Itm/MyQst06.itm~ ~override~
COPY ~MQI/Itm/MyQst07.itm~ ~override~

// Script
COPY ~MQI/Bcs/MyQuest.bcs~ ~override~


Here is my script (I bet it gets messed here):

IF
Global("MyQuestPack","GLOBAL",0)
THEN
RESPONSE #100
SetGlobal("MyQuestPack","GLOBAL",1)
GiveItemCreate("MyQst01",myself,0,0,0)
END

IF
Global("MyQuestPack","GLOBAL",1)
!HasItem("MyQst01",myself)
THEN
RESPONSE #100
SetGlobal("MyQuestPack","GLOBAL",2)
GiveItemCreate("MyQst02",myself,0,0,0)
END

IF
Global("MyQuestPack","GLOBAL",2)
!HasItem("MyQst01",myself)
!HasItem("MyQst02",myself)
THEN
RESPONSE #100
SetGlobal("MyQuestPack","GLOBAL",3)
GiveItemCreate("MyQst03",myself,0,0,0)
END

IF
Global("MyQuestPack","GLOBAL",3)
!HasItem("MyQst01",myself)
!HasItem("MyQst02",myself)
!HasItem("MyQst03",myself)
THEN
RESPONSE #100
SetGlobal("MyQuestPack","GLOBAL",4)
GiveItemCreate("MyQst04",myself,0,0,0)
END

IF
Global("MyQuestPack","GLOBAL",4)
!HasItem("MyQst01",myself)
!HasItem("MyQst02",myself)
!HasItem("MyQst03",myself)
!HasItem("MyQst04",myself)
THEN
RESPONSE #100
SetGlobal("MyQuestPack","GLOBAL",5)
GiveItemCreate("MyQst05",myself,0,0,0)
END

IF
Global("MyQuestPack","GLOBAL",5)
!HasItem("MyQst01",myself)
!HasItem("MyQst02",myself)
!HasItem("MyQst03",myself)
!HasItem("MyQst04",myself)
!HasItem("MyQst05",myself)
THEN
RESPONSE #100
SetGlobal("MyQuestPack","GLOBAL",6)
GiveItemCreate("MyQst06",myself,0,0,0)
END

IF
Global("MyQuestPack","GLOBAL",6)
!HasItem("MyQst01",myself)
!HasItem("MyQst02",myself)
!HasItem("MyQst03",myself)
!HasItem("MyQst04",myself)
!HasItem("MyQst05",myself)
!HasItem("MyQst06",myself)
THEN
RESPONSE #100
SetGlobal("MyQuestPack","GLOBAL",7)
GiveItemCreate("MyQst07",myself,0,0,0)
END

IF
Global("MyQuestPack","GLOBAL",7)
!HasItem("MyQst01",myself)
!HasItem("MyQst02",myself)
!HasItem("MyQst03",myself)
!HasItem("MyQst04",myself)
!HasItem("MyQst05",myself)
!HasItem("MyQst06",myself)
!HasItem("MyQst07",myself)
THEN
RESPONSE #100
SetGlobal("MyQuestPack","GLOBAL",8)
GiveItemCreate("Misc07",myself,4,0,0)
ChangeAIScript("",OVERRIDE)
END

This may not be what you are looking for, but perhaps it will be useful to someone. And, again, this is just a rough test that seemed to work perfectly.

Cuv

#18 GeN1e

GeN1e

    A very GAR character

  • Modder
  • 1604 posts

Posted 08 April 2007 - 11:33 AM

I must say I didn't think about creatures taking items on their own. My idea was to have a spyguy to ActionOverride others.

Now I've got a better (well, imho) idea than my previous one - to append Wtasight script. Many creatures have got it, thus many will be affected.

IF
Global("quest_item_1","GLOBAL",0)
Global("quest_item_1_me","LOCALS",0)
!General(Myself,ANIMAL)
!Race(Myself,SLIME)
!Race(Myself,DEMONIC)
!Race(Myself,SHADOW)
!Race(Myself,SPECTRE)
!Race(Myself,MIST)
!Race(Myself,ELEMENTAL)
!Race(Myself,GOLEM)
!Gender(Myself,SUMMONED)
!Gender(Myself,ILLUSIONARY)
THEN
RESPONSE #500
SetGlobal("quest_item_1_me","LOCALS",1)
RESPONSE #1
SetGlobal("quest_item_1_me","LOCALS",1)
SetGlobal("quest_item_1","GLOBAL",1)
GiveItemCreate("Quest1",Myself,0,0,0) // Quest1
END

And repeat it for each item.
But, hell, it won't help with containers.

Edited by GeN1e, 08 April 2007 - 11:35 AM.

Retired from modding.