Author Topic: Creating an item using ONLY a specific local variable  (Read 584 times)

Legacy_Jacen Saracen

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Creating an item using ONLY a specific local variable
« on: August 17, 2010, 07:16:12 am »


               Basically, I want to write an item creation script that creates a specific item.
 
I don't want the script to look up the resref, the tag or the item's name.  I want it to create the item using no other information than a local variable attached to the item via the toolset.

Can this be done?
               
               

               


                     Modifié par Jacen Saracen, 17 août 2010 - 06:16 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Creating an item using ONLY a specific local variable
« Reply #1 on: August 17, 2010, 08:35:24 am »


               Yes but you still need to use the res ref of the item that you want to create. Both the "CreateObject" and "CreateItemOnObject" functions require a blueprint res ref. You just store it as a string variable on whatever the object/item that will create the specific item.

So whatever object/item that will be making the specific item would have variable put on it in the toolset like:

RES_REF | string | actual res ref of item to create here

I'm not sure what you are using to create this item so this is pretty generic but then the script would have something like so:

void main()
{
string sResRef = GetLocalString(OBJECT_SELF, "RES_REF");
location lLoc = GetLocation(OBJECT_SELF);
CreateObject(OBJECT_TYPE_ITEM, sResRef, lLoc, FALSE);
}

Hope that helps. Good luck.
               
               

               


                     Modifié par GhostOfGod, 17 août 2010 - 07:43 .
                     
                  


            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Creating an item using ONLY a specific local variable
« Reply #2 on: August 17, 2010, 02:26:34 pm »


               I'm assuming your wanting to take an item in hand and edit it to change it to an item you want?

(Wouldn't a forge serve this purpose better?)

If not, then your talking about a difficult script indeed..

You will need to spawn the base item (with the variables on it), and then AFTER it's spawned (or given to someone or put in something), we will need to read the variables on it, then after that information is returned we will need to start changing the item...

Your talking about a very hefty script here... Considering the amount of morphing of the item going on and changing it into what you want based upon those variables... I don't see the need for a system like this, when forge systems are already created which would be much easier to use...

Nevertheless, *cracks fingers*, I'm up for this challenge....

What I need from you is more information...  I suppose the simplest way is to create a custom function...  But I need parameters of the integers, and exactly what you want to create (e.g. what item properties your going to be adding) based upon which integers are on the items.. (Now you probably respect the parameters of this request)

Now, if you want to change an existing item into another item altogether (e.g. one off the palette) it would be easier to just have a box full of items, when the PC "acquires" this item to be changed, it would reference the box with the items, and just copy that item onto the pc destroying the original (e.g. a slay of hand trick) - PC get's item, it vanishes turning into another item altogether..  (Doesn't this make sense?)

What are you wanting exactly, so I can be more helpful, can you be more specific and provide more information please?
               
               

               


                     Modifié par Genisys, 17 août 2010 - 01:29 .
                     
                  


            

Legacy_Jacen Saracen

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Creating an item using ONLY a specific local variable
« Reply #3 on: August 17, 2010, 05:38:26 pm »


               Thanks for the replies.  Let me clarify further--



Let's say that we have 6 custom items:  4 weapons and 2 belts.  All of which were created in the toolset, with specific names, properties and tags.  However, there are no specific instances set into the module area yet.



The 4 weapons each have a local variable of "1".  For the purposes of this example, "1" means "weapon".  The 2 belts have a local variable of "2".



I want to randomly spawn one of the 6 items.  Let's say the chances of spawning something with the variable "1" is 95%.  The chances of spawning variable "2" is 5%.



Ok, now it gets complicated--

Each of the four weapons has a 2nd variable.  "1", "2", "3" and "4" respectively.  IF the 95% holds correct, than I want a 25% chance of spawning each of the four weapons, calling each weapon's second variable to do so.



Each of the two belts also has a 2nd variable.  "1" and "2".  IF the 5% holds true, I want a 50% chances of spawning either of the belts.



How do I do this?
               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
Creating an item using ONLY a specific local variable
« Reply #4 on: August 17, 2010, 07:06:46 pm »


               I think this system is somewhat wasteful of dataspace and thus system resources. I would suggest you create the custom items to have a resref that follows a modification of your scheme such that an example resref for your weapons would be

wsw11
wsw12
wsw13
wsw14

and your belts...

bel11
bel12

Provide them with the same TAG for simplicity too. Then the only task is a simple script to generate treasure along the lines you mentoned with each type of item getting percentage chances drawn from a default or even from variables stored on the nearest corpse (aka monster treasure types from DND).


NOTE variables take up resources, having lots of little ones take up LOTS of resource. Use system resources sparingly and you will NEVER run short.

Have fun.

Be well. Game on.
GM_ODA
66.232.100.90 cep2.1+ nwn 1.69 w/ both expansions
24x7 we bring the game
aldohral.forumotion.com
               
               

               


                     Modifié par ehye_khandee, 17 août 2010 - 06:07 .
                     
                  


            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Creating an item using ONLY a specific local variable
« Reply #5 on: August 17, 2010, 07:45:36 pm »


               Furthermore, if you really want to save resources follow these instructions...

In another module paint two barrels, make them plot and give them the tagnames, wpn_spawn & the other belt_spawn, paint a waypoint and give it the tagname spawn_way_01

Next place basic bioware standard items in the barrels, next change the items to the desired results, after that is all done, highlight the two barrels & waypoint, press Control + C, open up the module they will go into..

In an area where you want them to be (where the PC's NOR DMs cannot access them) select a space on the map and press Control + V, this will pain the barrels with the items into the module.. NO TAGNAMES ON ITEMS NEEDED...

Next you will make a script which will go in the OnOpen event of a container you create (like a Chest)

Here is the script...  (I didn't know how you were planning on spawning the items you never said..)

Therefore I will make this script for the OnOpen event for ANY Placeable Ojbect (With An Inventory) you place the script in the proper OnOpen Event, note however, this is a template, since other people should be able to use it as well..

Make SURE you change the variables below to the variables I told you to use above. (at the start of this post)

//////////////////////////////////////////////////////////////////////////////
//Script Name: spawn_tres_oo
//Template script - Save Under a New Name
/////////////////////////////////////////////////////////////////////////////
//Created By: Genisys (Guile)
//Created On: 8/17/10
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
This will be a Template Script for the OnOpen Event of a Placeable Object
You MUST Set the settings below for this to work how you want it to..

NOTE: If you set one chance to spawn treasure at 40 % and the other
chance to spawn treasure 2 at 80% then you may spawn 2 Items!
*/
///////////////////////////////////////////////////////////////////////////

//Set this to the tagname of the waypoint you will be using to reference
// the placeable objects in the module which holds the treasure..
const string WAY_PT_TAGNAME = "tagname";

//Set this to the tagname of the container which holds Treasure 1
const string TREASURE_1_TAGNAME = "tagname";

//Set this to the tagname of the container which holds Teasure 2
const string TREASURE_2_TAGNAME = "tagname";

//Set this to the % chance you want Treasure 1 to spawn.. (uses rolls of 0 or more)
const int SPAWN_TEASURE_1_CHANCE = 5; //Default = 5 (%) Chance of spawning
//0 = disabled (Always spawn it!)

//Set this to the % chance you want Treasure 2 to spawn.. (uses rolls 100 or less)
const int SPAWN_TREASURE_2_CHANCE = 20; //Default = 20 (%) Chance of Spawning
//0 = disabled (Always spawn it!)

//NOTE: This treasure will only spawn ONE TIME for EVERY PC on Every Restart
//or if the PC is playing single player (offline) and using a saved game, it will
//only spawn the treasure one time only (and never again)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////WARNING: DON'T TOUCH ANYHTING BELOW THIS LINE!!!/////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Declare Prototypes
int GetTreasureCount(object oBox);
void GetTreasure(int nInt, object oBox);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Main Script
void main()
{
object oPC = GetLastOpenedBy();
if(!GetIsPC(oPC) || GetIsDM(oPC) || GetIsDMPossessed(oPC))
{ return; }

object oWay = GetWaypointByTag(WAY_PT_TAGNAME);
object oT1 = GetNearestObjectByTag(TREASURE_1_TAGNAME,oWay);
object oT2 = GetNearestObjectByTag(TREASURE_2_TAGNAME,oWay);
int nInt, nT2C, nConv, nPercent;
int nTC1, nTC2, nTS1, nTS2;
object oS1, oS2;
nTC1 = GetTreasureCount(oT1);
nTC2 =GetTreasureCount(oT2);
nTS1 = Random(nTC1);
nTS2 = Random(nTC2);
int nChk;
nChk = GetLocalInt(oPC, GetTag(OBJECT_SELF));
if(nChk) { return; }
else { SetLocalInt(oPC, GetTag(OBJECT_SELF), TRUE); }
nConv = 100 - SPAWN_TREASURE_2_CHANCE; //Reverse the check (100 or less)
nInt = Random(99);
nT2C = Random(99);

if(nInt)
{
GetTreasure(nTS1, oT1); //Get a random item (1) from the chest..
}
if(nT2C >= nConv) //5% = 95 or higher needed on roll...
{
GetTreasure(nTS2, oT2); //Get one randome item from the 2nd treasure chest
}

//Main Script End
}

///////////////////////////////////////////////////////////////////////
//Define Prototype

int GetTreasureCount(object oBox)
{
int i = 0;
object oItem;
oItem = GetFirstItemInInventory(oBox);
while(GetIsObjectValid(oItem))
{
i +=1;
oItem = GetNextItemInInventory(oBox);
}

return i; //Tell us how many items were in the box!

//Prototype End
}

////////////////////////////////////////////////////////////////////////
//Define Prototype

void GetTreasure(int nInt, object oBox)
{
int i = 0;
object oItem;
oItem = GetFirstItemInInventory(oBox);
while(GetIsObjectValid(oItem))
{
i +=1;
if(i == nInt)
{
CopyItem(oItem, OBJECT_SELF, TRUE); //Put it in the box we are opening..
}
oItem = GetNextItemInInventory(oBox);
}

//Prototype End
}

You may want to destroy the placeable object, and respawn it later, but that would be another script request..
               
               

               


                     Modifié par Genisys, 17 août 2010 - 07:04 .
                     
                  


            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
Creating an item using ONLY a specific local variable
« Reply #6 on: August 17, 2010, 07:54:17 pm »


               Sounds easy enough, now that you've clarified what you're going for.  You could use the following, just replaces the resrefs with the real ones for you items.

// insert into your treasure generating script....
object oTarget = OBJECT_SELF; // this could change, depending on how you are generating treasure
int nRoll1 = d100(1);
int nRoll2 = d100(1);
if (nRoll1 < 96) // weapons
{
string sRR;
switch (Random(4) + 1)
{
case 1: sRR = "weapon1rr"; break;
case 2: sRR = "weapon2rr"; break;
case 3: sRR = "weapon3rr"; break;
case 4: sRR = "weapon4rr"; break;
}
object oNewItem = CreateItemOnObject(sRR, oTarget);
}
else // belts
{
string sRR;
switch (Random(2) + 1)
{
case 1: sRR = "belt1rr"; break;
case 2: sRR = "belt2rr"; break;
}
object oNewItem = CreateItemOnObject(sRR, oTarget);
}



The above code is very simplified and would need to be edited every time you added a new item.  I actually recommend using a more robust and easily expanded system, such as Silicon Scout's Treasure System (one I use myself).

{I really, really dislike the fact that these forums have no "code entry" functionality.  With all the text shoved to the left, it makes reading nwscript a lot more difficult and it's almost impossible to pick out comments.}
               
               

               


                     Modifié par The Amethyst Dragon, 17 août 2010 - 06:57 .
                     
                  


            

Legacy_Jacen Saracen

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Creating an item using ONLY a specific local variable
« Reply #7 on: August 18, 2010, 05:01:27 am »


               Thank you all for your responses.

I had no idea that local variables clogged up resources so much.  Genisys, I especially thank you for your solution.  I almost went with it.



Amethyst, I looked at Silicon Scout's solution, and I was absolutely floored for two reasons-- 1) that I had never come across it, and 2) that it seems that it will be absolutely perfect for my purposes!



Thanks again!
               
               

               
            

Legacy_Jacen Saracen

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Creating an item using ONLY a specific local variable
« Reply #8 on: August 19, 2010, 06:01:22 am »


               Amethyst,

I am attempting to adapt Silicon Scout's script package, and I had a couple of questions that maybe you can answer.  According to the readme, you must set local variables on the creatures to call the various merchants.  However, what if you want that local variable to be dependent on the PC's level, or some other event?  Can you define that local variable through a script?
               
               

               
            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
Creating an item using ONLY a specific local variable
« Reply #9 on: August 19, 2010, 06:45:50 am »


               

Jacen Saracen wrote...

Amethyst,
I am attempting to adapt Silicon Scout's script package, and I had a couple of questions that maybe you can answer.  According to the readme, you must set local variables on the creatures to call the various merchants.  However, what if you want that local variable to be dependent on the PC's level, or some other event?  Can you define that local variable through a script?


Sure, why not?  Instead of doing the script call to generate the treasure when the creature spawns, have it run once on some other event (with part of the script calculating the values for some of the variables, then adding them to the creature, then running the script call for treasure generation...perhaps at the very start of the onDeath script).

Doing this might prevent the creature from using the items itself (which I don't think is really fair to the poor NPC), but would be a reliable way to both assign the variables and get the loot.

You could also do it in the NPC's onSpawn script, just add in a couple of "void" functions that can be delayed by a second or two...one to calculate and add variables based on the nearest PC's level, the other to generate the loot items (and possibly equip them) a second later..

Hmmm...now I may have to revisit my own onSpawn scripts to see about adjusting percentages for some of the loot drops based on PC levels. ':?'  Why do you have to be giving me ideas when I'm already in the middle of two massive scripting projects?
               
               

               
            

Legacy_Jacen Saracen

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Creating an item using ONLY a specific local variable
« Reply #10 on: August 19, 2010, 07:01:08 am »


               *smirks*

I'm a glutton for punishment.

To give you an idea of what I am attempting, I am wanting to spawn random items dependent upon the PC's number of XP, NOT the PC levels.  I have a running scale of up to 1,770,000 XP divided into 135 "classes".  The "classes" can also be affected by the PC's intelligence.... the smarter you are, the higher your "class" is over the one granted by your XP.  The "class" can also be affected by the difficulty of the creature you killed.



For example, a level PC with 420,000 XP (halfway through level 29) would be "class" 54.  The PC has 22 intelligence, which ups the "class" to 62  And finally, because the creature was a boss, he drops items that are 10 "classes" ahead of your current level, in this case, 72.



Furthermore, these items are seperated into category percentages-- 6% chance of a potion, 3% chance of a weapon.... etc etc.....



I think this system will work, but I need it to account for all of the above variables....





As George Costanza would say..... "Ridickerous!!"
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Creating an item using ONLY a specific local variable
« Reply #11 on: August 19, 2010, 11:37:24 am »


               Ridickerous, lol you said a mouthful..