Ironworks Gaming Forum

Ironworks Gaming Forum (http://www.ironworksforum.com/forum/index.php)
-   Neverwinter Nights 1 & 2 Also SoU & HotU Forum (http://www.ironworksforum.com/forum/forumdisplay.php?f=16)
-   -   scripting a container to *drop* by class (http://www.ironworksforum.com/forum/showthread.php?t=35545)

Legolas 07-12-2003 12:16 PM

Nope, I've no modules running on the 'net. I'm sure it would be fun, but if it's going to be a module it's going to be one of my own...
And at this rate, that's not going to happen. My only project is a single-player module based on the Hazardous Times threads from the RP section, and if you download that one you'll see I still have tons of work to do before that one is completed.

Although I do suppose that in multiplayer modules I could get away with far less detail, fewer scripts and the like, and I could keep parts of it 'under construction' a while too...

But I digress... I seriously doubt that was me. Probably one of those youngsters who decided to grab my name (COC in the making) or similar [img]smile.gif[/img]
I'm usually found going by the name of Golas, or Say NO to the Trouser Tyranny if it's one of the older characters I'm playing.

Legolas 07-12-2003 01:59 PM

Okay then, I think I've got it now. Instead of adding elses in ifs everywhere, I've added a single one right at the very end.

Quote:

int GetHighestClassRandom(object oCreature);
int GetHighestClassRandom(object oCreature)
{
int iClass1 = GetClassByPosition(1, oCreature);
int iClass2 = GetClassByPosition(2, oCreature);
int iClass3 = GetClassByPosition(3, oCreature);
int iLevel1 = GetLevelByClass(iClass1, oCreature);
int iLevel2 = GetLevelByClass(iClass2, oCreature);
int iLevel3 = GetLevelByClass(iClass3, oCreature);
int iRandom2 = Random(2);
int iRandom3 = Random(3);
{
if((iClass2 != CLASS_TYPE_INVALID) && (iClass3 != CLASS_TYPE_INVALID))
{
if((iLevel1 == iLevel2) && (iLevel1 == iLevel3))
{
if(iRandom3 == 0)
{return iClass1;}
else if(iRandom3 == 1)
{return iClass2;}
else if(iRandom3 == 2)
{return iClass3;}
}
else if((iLevel1 == iLevel2) && (iLevel1 'SMALLER THAN' iLevel3))
{return iClass3;}
else if((iLevel1 == iLevel2) && (iLevel1 'GREATER THAN' iLevel3))
{
if(iRandom2 == 0)
{return iClass1;}
else if(iRandom2 == 1)
{return iClass2;}
}
else if((iLevel1 == iLevel3) && (iLevel1 'SMALLER THAN' iLevel2))
{return iClass2;}
else if((iLevel1 == iLevel3) && (iLevel1 'GREATER THAN' iLevel2))
{
if(iRandom2 == 0)
{return iClass1;}
else if(iRandom2 == 1)
{return iClass3;}
}
else if((iLevel2 == iLevel3) && (iLevel1 'SMALLER THAN' iLevel3))
{
if(iRandom2 == 0)
{return iClass2;}
else if(iRandom2 == 1)
{return iClass3;}
}
else if((iLevel2 == iLevel3) && (iLevel1 'GREATER THAN' iLevel3))
{return iClass1;}
else if((iLevel1 'GREATER THAN' iLevel2) && (iLevel1 'GREATER THAN' iLevel3))
{return iClass1;}
else if((iLevel2 'GREATER THAN' iLevel1) && (iLevel2 'GREATER THAN' iLevel3))
{return iClass2;}
else if((iLevel3 'GREATER THAN' iLevel2) && (iLevel3 'GREATER THAN' iLevel1))
{return iClass3;}
}
else if((iClass2 != CLASS_TYPE_INVALID) && (iClass3 == CLASS_TYPE_INVALID))
{
if(iLevel1 == iLevel2)
{
if(iRandom2 == 0)
{return iClass1;}
else if(iRandom2 == 1)
{return iClass2;}
else if(iRandom2 == 2)
{return iClass1;}
}
else if (iLevel1 'SMALLER THAN' iLevel2)
{return iClass2;}
else if (iLevel1 'GREATER THAN' iLevel2)
{return iClass1;}
}
else if((iClass2 == CLASS_TYPE_INVALID) && (iClass3 == CLASS_TYPE_INVALID)) {return iClass1;}
}
{return CLASS_TYPE_INVALID;}

}
This script does nothing other than adding a new command to the list in the editor. It is the 'GetHighestClassRandom(object)' command, which returns the CLASS_TYPE_* with the most levels in it, or picks randomly between those tied for highest.
It has to be linked to every script you write that uses the GetHighestClassRandom command. You can do so by either repeating the above script in each of those other scripts, above the void main(), or by making this into it's own script (by saving it into an empty new script file, without the void main()) and then linking to it by typing #include "script name" above the void main() of the other scripts.

Then, you can use a script very similar to the one I used first to cover all the options.
Your OnOpen and OnDeath scripts for class related containers will look like one of the below:

Quote:

#include "get-highest-level-random-script's-name"
void main()
{
if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_ARCANE_ARCHER)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_ASSASSIN)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_BARBARIAN)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_BARD)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_BLACKGUARD)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_CLERIC)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_DRUID)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_FIGHTER)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_HARPER)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_INVALID)
{
PrintString("The GetHighestClassRandom thingy isn't working properly. Tell Leggy to test his scripts and do a better job in the future")
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_MONK)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_PALADIN)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_RANGER)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_ROGUE)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_SHADOWDANCER)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_SORCERER)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_WIZARD)
{
*Insert items here*
}
}
if you've stored the first script of the post in another file, or:

Quote:

int GetHighestClassRandom(object oCreature);
int GetHighestClassRandom(object oCreature)
{
int iClass1 = GetClassByPosition(1, oCreature);
int iClass2 = GetClassByPosition(2, oCreature);
int iClass3 = GetClassByPosition(3, oCreature);
int iLevel1 = GetLevelByClass(iClass1, oCreature);
int iLevel2 = GetLevelByClass(iClass2, oCreature);
int iLevel3 = GetLevelByClass(iClass3, oCreature);
int iRandom2 = Random(2);
int iRandom3 = Random(3);
{
if((iClass2 != CLASS_TYPE_INVALID) && (iClass3 != CLASS_TYPE_INVALID))
{
if((iLevel1 == iLevel2) && (iLevel1 == iLevel3))
{
if(iRandom3 == 0)
{return iClass1;}
else if(iRandom3 == 1)
{return iClass2;}
else if(iRandom3 == 2)
{return iClass3;}
}
else if((iLevel1 == iLevel2) && (iLevel1 'SMALLER THAN' iLevel3))
{return iClass3;}
else if((iLevel1 == iLevel2) && (iLevel1 'GREATER THAN' iLevel3))
{
if(iRandom2 == 0)
{return iClass1;}
else if(iRandom2 == 1)
{return iClass2;}
}
else if((iLevel1 == iLevel3) && (iLevel1 'SMALLER THAN' iLevel2))
{return iClass2;}
else if((iLevel1 == iLevel3) && (iLevel1 'GREATER THAN' iLevel2))
{
if(iRandom2 == 0)
{return iClass1;}
else if(iRandom2 == 1)
{return iClass3;}
}
else if((iLevel2 == iLevel3) && (iLevel1 'SMALLER THAN' iLevel3))
{
if(iRandom2 == 0)
{return iClass2;}
else if(iRandom2 == 1)
{return iClass3;}
}
else if((iLevel2 == iLevel3) && (iLevel1 'GREATER THAN' iLevel3))
{return iClass1;}
else if((iLevel1 'GREATER THAN' iLevel2) && (iLevel1 'GREATER THAN' iLevel3))
{return iClass1;}
else if((iLevel2 'GREATER THAN' iLevel1) && (iLevel2 'GREATER THAN' iLevel3))
{return iClass2;}
else if((iLevel3 'GREATER THAN' iLevel2) && (iLevel3 'GREATER THAN' iLevel1))
{return iClass3;}
}
else if((iClass2 != CLASS_TYPE_INVALID) && (iClass3 == CLASS_TYPE_INVALID))
{
if(iLevel1 == iLevel2)
{
if(iRandom2 == 0)
{return iClass1;}
else if(iRandom2 == 1)
{return iClass2;}
else if(iRandom2 == 2)
{return iClass1;}
}
else if (iLevel1 'SMALLER THAN' iLevel2)
{return iClass2;}
else if (iLevel1 'GREATER THAN' iLevel2)
{return iClass1;}
}
else if((iClass2 == CLASS_TYPE_INVALID) && (iClass3 == CLASS_TYPE_INVALID)) {return iClass1;}
}
{return CLASS_TYPE_INVALID;}

}
void main()
{
if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_ARCANE_ARCHER)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_ASSASSIN)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_BARBARIAN)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_BARD)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_BLACKGUARD)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_CLERIC)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_DRUID)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_FIGHTER)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_HARPER)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_INVALID)
{
PrintString("The GetHighestClassRandom thingy isn't working properly. Tell Leggy to test his scripts and do a better job in the future")
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_MONK)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_PALADIN)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_RANGER)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_ROGUE)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_SHADOWDANCER)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_SORCERER)
{
*Insert items here*
}
else if(GetHighestClassRandom(GetLastOpenedBy()) == CLASS_TYPE_WIZARD)
{
*Insert items here*
}
}
if you haven't.

As you can see, using #include is a lot more compact and well worth the effort if you are going to use this function in more than one or two scripts.

Now, if it does not work, just check the nwclient log file for further instructions. Phew [img]smile.gif[/img]

[ 07-12-2003, 02:09 PM: Message edited by: Legolas ]

robertthebard 07-12-2003 02:47 PM

once again, thanks for all your hard work, hopefully others will also use this to help with their modules. I appreciate the effort it took to work this out, i'll be sure to send you a copy of the mod, when it's done

Legolas 07-12-2003 02:57 PM

You're most welcome, and I'll be looking forward to it [img]smile.gif[/img]
I just hope it works as planned, I haven't tested it yet using the different classes available.


All times are GMT -4. The time now is 10:20 PM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
©2024 Ironworks Gaming & ©2024 The Great Escape Studios TM - All Rights Reserved