Note: LucasForums Archive Project
The content here was reconstructed by scraping the Wayback Machine in an effort to restore some of what was lost when LF went down. The LucasForums Archive Project claims no ownership over the content or assets that were archived on archive.org.

This project is meant for research purposes only.

[K1] Editing Script Problem

Page: 1 of 1
 kamikazees
12-15-2006, 2:25 AM
#1
Ok so I've got a noob problem with my first-ever try at messing with scripts. I admit I have no idea what I'm doing, but the dozens of articles I've read here got me to be able to handle the .2da files and KOTOR Tool, and I am almost ready to take on scripting. For my first task, I decided to edit a watered-down version of Talchia's hardcore mod for K1. Didn't seem too difficult, right?

I found the .nss code in a kind post from Darth333, and as you see below I'm trying to increase hp, str, dex, wis and con of all enemies based on PC lvl. If the PC is lvl 8-11, for example, I've tried to set up enemy "beasts" to get +25hp, +4 dex, wis and con, and +6 str (I set dex, wis and con lower so the saves wouldn't increase so fast - go consulars!). Anyway, it seemed to compile fine, KOTOR Tool spit out a .ncs file. I ran a control test without the mod in the dantooine courtyard against kath hounds (hard difficulty). They had about 45hps and base saves of 3f/5r/-2w. Then I re-loaded the game with the script. At lvl 9, I expected their stats to reflect the above increases, which was about a +2 to saves and such. Instead, they had +10 to each base save (13f/15r/8w), about 200 more hps, and they also walloped me (although my PC wouldn't die). Mad dogs! So what did I do wrong? Help please and thank you!

Oh, and all credits go to Talchia for her brilliant scripting. I just wish I could understand it:


////////////>>>>>>HARDCORE MOD V 1.0<<<<<<<<<<////////////////////////////
//Buffs the Target up, based on a script from Preston Watamaniuk/Bioware //
// //
// Note: Boss enemys like Darth Bandon and Malak will get also the //
// increase, so be carefull with tweaks. Also the ability increase //
// is limited to 20, everything above will be ignored and //
// count as 20. //
// //
//::///////////////////////////////////////////////////////////////////:://
//:: Created By: Talchia <http://home.t-online.de/home/Talchia/>) :://
//:: Created On: December 30, 2003 :://
//::///////////////////////////////////////////////////////////////////:://
int nCharLevel = GetHitDice(GetFirstPC());
effect eStatA, eStatB, eFP, eVP, eLink, eStatC, eStatD, eLink2; int nVP; int nValid;
//Jedi
if(GetLevelByClass(CLASS_TYPE_JEDICONSULAR) > 0 ||
GetLevelByClass(CLASS_TYPE_JEDIGUARDIAN) > 0 ||
GetLevelByClass(CLASS_TYPE_JEDISENTINEL) > 0)
{
//Set up the effects based on the character level
if(nCharLevel >= 8 && nCharLevel <= 11)
{
eStatA = EffectAbilityIncrease(ABILITY_DEXTERITY, 4);
eStatB = EffectAbilityIncrease(ABILITY_WISDOM, 4);
eStatC = EffectAbilityIncrease(ABILITY_STRENGTH, 6);
eStatD = EffectAbilityIncrease(ABILITY_CONSTITUTION, 4);
eFP = EffectTemporaryForcePoints(10);
nVP = 35;
}
else if(nCharLevel >= 12 && nCharLevel <= 15)
{
eStatA = EffectAbilityIncrease(ABILITY_DEXTERITY, 8);
eStatB = EffectAbilityIncrease(ABILITY_WISDOM, 8);
eStatC = EffectAbilityIncrease(ABILITY_STRENGTH, 10);
eStatD = EffectAbilityIncrease(ABILITY_CONSTITUTION, 8);
eFP = EffectTemporaryForcePoints(25);
nVP = 60;
}
else if(nCharLevel >= 16)
{
eStatA = EffectAbilityIncrease(ABILITY_DEXTERITY, 12);
eStatB = EffectAbilityIncrease(ABILITY_WISDOM, 12);
eStatC = EffectAbilityIncrease(ABILITY_STRENGTH, 14);
eStatD = EffectAbilityIncrease(ABILITY_CONSTITUTION, 12);
eFP = EffectTemporaryForcePoints(50);
nVP = 85;
}
else
{
nValid >= 2;
}
if(nValid <= 1)
{
eLink = EffectLinkEffects(eStatA, eStatB);
eLink = EffectLinkEffects(eLink, eFP);
eLink = EffectLinkEffects(eLink, eStatC);
eLink = EffectLinkEffects(eLink, eStatD);
}
}
//BEASTS
else if(GetSubRace(OBJECT_SELF) == 2) //SUBRACE_BEAST
{
if(nCharLevel >= 8 && nCharLevel <= 11)
{
eStatA = EffectAbilityIncrease(ABILITY_DEXTERITY, 4);
eStatB = EffectAbilityIncrease(ABILITY_WISDOM, 4);
eStatC = EffectAbilityIncrease(ABILITY_STRENGTH, 6);
eStatD = EffectAbilityIncrease(ABILITY_CONSTITUTION, 4);
nVP = 25;
}
else if(nCharLevel >= 12 && nCharLevel <= 15)
{
eStatA = EffectAbilityIncrease(ABILITY_DEXTERITY, 8);
eStatB = EffectAbilityIncrease(ABILITY_WISDOM, 8);
eStatC = EffectAbilityIncrease(ABILITY_STRENGTH, 10);
eStatD = EffectAbilityIncrease(ABILITY_CONSTITUTION, 8);
nVP = 50;
}
else if(nCharLevel >= 16)
{
eStatA = EffectAbilityIncrease(ABILITY_DEXTERITY, 12);
eStatB = EffectAbilityIncrease(ABILITY_WISDOM, 12);
eStatC = EffectAbilityIncrease(ABILITY_STRENGTH, 14);
eStatD = EffectAbilityIncrease(ABILITY_CONSTITUTION, 12);
nVP = 75;
}
else
{
nValid >= 2;
}
if(nValid <= 1)
{
eLink = EffectLinkEffects(eStatA, eStatB);
eLink = EffectLinkEffects(eLink, eStatC);
eLink = EffectLinkEffects(eLink, eStatD);
}
}
//DROIDS
else if(GetRacialType(OBJECT_SELF) == RACIAL_TYPE_DROID)
{
if(nCharLevel >= 8 && nCharLevel <= 11)
{
eStatA = EffectAbilityIncrease(ABILITY_DEXTERITY, 4);
eStatB = EffectAbilityIncrease(ABILITY_WISDOM, 4);
eStatC = EffectAbilityIncrease(ABILITY_STRENGTH, 6);
eStatD = EffectAbilityIncrease(ABILITY_CONSTITUTION, 4);
nVP = 50;
}
else if(nCharLevel >= 12 && nCharLevel <= 15)
{
eStatA = EffectAbilityIncrease(ABILITY_DEXTERITY, 8);
eStatB = EffectAbilityIncrease(ABILITY_WISDOM, 8);
eStatC = EffectAbilityIncrease(ABILITY_STRENGTH, 10);
eStatD = EffectAbilityIncrease(ABILITY_CONSTITUTION, 8);
nVP = 75;
}
else if(nCharLevel >= 16)
{
eStatA = EffectAbilityIncrease(ABILITY_DEXTERITY, 12);
eStatB = EffectAbilityIncrease(ABILITY_WISDOM, 12);
eStatC = EffectAbilityIncrease(ABILITY_STRENGTH, 14);
eStatD = EffectAbilityIncrease(ABILITY_CONSTITUTION, 12);
nVP = 100;
}
else
{
nValid >= 2;
}
if(nValid <= 1)
{
eLink = EffectLinkEffects(eStatA, eStatB);
eLink = EffectLinkEffects(eLink, eStatC);
eLink = EffectLinkEffects(eLink, eStatD);
}
}
else
{
//Other Class
if(nCharLevel >= 8 && nCharLevel <= 11)
{
eStatA = EffectAbilityIncrease(ABILITY_STRENGTH, 6);
eStatB = EffectAbilityIncrease(ABILITY_DEXTERITY, 4);
eStatC = EffectAbilityIncrease(ABILITY_WISDOM, 4);
eStatD = EffectAbilityIncrease(ABILITY_CONSTITUTION, 4);
nVP = 25;
}
else if(nCharLevel >= 12 && nCharLevel <= 15)
{
eStatA = EffectAbilityIncrease(ABILITY_STRENGTH, 10);
eStatB = EffectAbilityIncrease(ABILITY_DEXTERITY, 8);
eStatC = EffectAbilityIncrease(ABILITY_WISDOM, 8);
eStatD = EffectAbilityIncrease(ABILITY_CONSTITUTION, 8);
nVP = 50;
}
else if(nCharLevel >= 16)
{
eStatA = EffectAbilityIncrease(ABILITY_STRENGTH, 14);
eStatB = EffectAbilityIncrease(ABILITY_DEXTERITY, 12);
eStatC = EffectAbilityIncrease(ABILITY_WISDOM, 12);
eStatD = EffectAbilityIncrease(ABILITY_CONSTITUTION, 12);
nVP = 75;
}
else
{
nValid >= 2;
}
if(nValid <= 1)
{
eLink = EffectLinkEffects(eStatA, eStatB);
eLink = EffectLinkEffects(eLink, eStatC);
eLink = EffectLinkEffects(eLink, eStatD);
}
}
if(nVP > 0)
{
if(nValid <= 1 && !GetPlayerRestrictMode())
{
nVP = GetMaxHitPoints(OBJECT_SELF) + nVP;
SetMaxHitPoints(OBJECT_SELF, nVP);

}
}
if(nValid <= 1 && !GetPlayerRestrictMode())
{
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eLink, OBJECT_SELF);
}
}
 stoffe
12-15-2006, 8:49 AM
#2
Is that the whole script you compiled? It shouldn't compile since there is no main() or StartingConditional() function in it, and there is one } block delimiter that doesn't have a starting { as far as I can see on a quick glance. I'm not familiar with how the hardcore mod for K1 is designed.

You could try this somewhat rearranged version of what you posted and see if it still produces weird results. This assumes that you run the script with ExecuteScript() from somewhere (presumably one of the AI scripts) once for each character who should be affected by it.


int ST_PickValueByType(int iJedi, int iBeast, int iDroid, int iStandard);


void main() {
// Don't do this in the Space/Environment suit scenes.
if (GetPlayerRestrictMode())
return;

int nCharLevel = GetHitDice(GetFirstPC());
int iDex, iWis, iStr, iCon, iFP, iVP;

// Adjustments for Player Level 8 - 11
if ((nCharLevel >= 8) && (nCharLevel <= 11)) {
// Jedi, Beast, Droid, Other
// ---- ----- ----- -----
iDex = ST_PickValueByType(4, 4, 4, 4); // Dexterity
iWis = ST_PickValueByType(4, 4, 4, 4); // Wisdom
iStr = ST_PickValueByType(6, 6, 6, 6); // Strength
iCon = ST_PickValueByType(4, 4, 4, 4); // Constitution
iFP = ST_PickValueByType(10, 0, 0, 0); // Force Points
iVP = ST_PickValueByType(35, 25, 50, 25); // Vitality Points
}
// Adjustments for Player Level 12 - 15
else if ((nCharLevel >= 12) && (nCharLevel <= 15)) {
// Jedi, Beast, Droid, Other
// ---- ----- ----- -----
iDex = ST_PickValueByType(8, 8, 8, 8); // Dexterity
iWis = ST_PickValueByType(8, 8, 8, 8); // Wisdom
iStr = ST_PickValueByType(10, 10, 10, 10); // Strength
iCon = ST_PickValueByType(8, 8, 8, 8); // Constitution
iFP = ST_PickValueByType(25, 0, 0, 0); // Force Points
iVP = ST_PickValueByType(60, 50, 75, 50); // Vitality Points
}
// Adjustments for Player Level 16 - 20
else if (nCharLevel >= 16) {
// Jedi, Beast, Droid, Other
// ---- ----- ----- -----
iDex = ST_PickValueByType(12, 12, 12, 12); // Dexterity
iWis = ST_PickValueByType(12, 12, 12, 12); // Wisdom
iStr = ST_PickValueByType(14, 14, 14, 14); // Strength
iCon = ST_PickValueByType(12, 12, 12, 12); // Constitution
iFP = ST_PickValueByType(50, 0, 0, 0); // Force Points
iVP = ST_PickValueByType(85, 75, 100, 75); // Vitality Points
}

if ((iStr != 0) || (iDex != 0) || (iCon != 0) || (iWis != 0) || (iFP != 0) || (iVP != 0)) {
effect eStats = EffectAbilityIncrease(ABILITY_STRENGTH, iStr);
eStats = EffectLinkEffects(eStats, EffectAbilityIncrease(ABILITY_DEXTERITY, iDex));
eStats = EffectLinkEffects(eStats, EffectAbilityIncrease(ABILITY_CONSTITUTION, iCon));
eStats = EffectLinkEffects(eStats, EffectAbilityIncrease(ABILITY_WISDOM, iWis));
if (iFP > 0)
eStats = EffectLinkEffects(eStats, EffectTemporaryForcePoints(iFP));

// Apply Vitality bonuses.
if (iVP > 0)
SetMaxHitPoints(OBJECT_SELF, GetMaxHitPoints(OBJECT_SELF) + iVP);

// Apply Ability and Force point bonuses.
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eStats, OBJECT_SELF);
}
}


int ST_PickValueByType(int iJedi, int iBeast, int iDroid, int iStandard) {
if ((GetLevelByClass(CLASS_TYPE_JEDICONSULAR) > 0)
|| (GetLevelByClass(CLASS_TYPE_JEDIGUARDIAN) > 0)
|| (GetLevelByClass(CLASS_TYPE_JEDISENTINEL) > 0))
{
return iJedi;
}
else if (GetSubRace(OBJECT_SELF) == 2) {
return iBeast;
}
else if (GetRacialType(OBJECT_SELF) == RACIAL_TYPE_DROID) {
return iDroid;
}

return iStandard;
}
 kamikazees
12-15-2006, 12:27 PM
#3
Thank you very much for taking the time to review my problem and reply so quickly! To answer your first question, no, that is not the entire script. It's the entire hardcore mod I think (edited), but not the whole script. The whole script is k_ai_master.nss from K1. The portion I posted replaces lines 154-158 of that script, as I understand it. I'm pretty sure it compiled correctly, as I followed all those compiling posts very closely.

I appreciate your taking the time to rewrite the script too. Wow. Ok so I'd like to just copy and paste that version over the edited portion of my script to see if that fixes it (I'd just extract k_ai_master.nss again and post yours over lines 154-158, then compile). I see, however, that you've got some of it in green color. Does that mean something special?

Finally, I don't know what it means to "run ExecuteScript() once for each character." I suppose I should have disclosed that I think cell phones with cameras are too high tech for me! Joking aside, all I'm doing with the compiled file (once KOTOR gives me the completed k_ai_master.ncs file), is dropping it into my Override folder. Is that enough?

Here's where I found the source for Talchia's mod: http://www.lucasforums.com/showthread.php?t=168732&highlight=talchia)
 stoffe
12-15-2006, 12:51 PM
#4
I appreciate your taking the time to rewrite the script too. Wow. Ok so I'd like to just copy and paste that version over the edited portion of my script to see if that fixes it (I'd just extract k_ai_master.nss again and post yours over lines 154-158, then compile).

I suggest doing like this instead:
Copy&paste the modified script I posted above into a new NSS file and save it as "ta_hardcore.nss".
Compile this new script, which should produce a "ta_hardcore.ncs" file. Put this in the override folder.
In "k_ai_master", replace the chunk of code you originally posted (NOT the whole content of "k_ai_master"!), except the } at the end, with the following lines:

if (!IsObjectPartyMember(OBJECT_SELF) && !GetLocalBoolean(OBJECT_SELF, 63)) {
ExecuteScript("ta_hardcore", OBJECT_SELF);
SetLocalBoolean(OBJECT_SELF, 63, TRUE);
}

Recompile this modified "k_ai_master" script and put the resulting NCS file in the override folder.


From what I can see in the thread you linked to there is no blocker that ensures the code is only run once. Since it's run from the OnPerception event that means it likely runs at least 3 times since the creature would perceive your main character and your two sidekicks at the very least (in addition to any other creatures/characters who happen to be nearby). The above should hopefully take care of that.

It will also keep the hardcore mod code in a separate script so you won't have to recompile the whole AI script whenever you want to tweak it. Changing and recompiling the "ta_hardcore" script will then be enough if you want to modify the bonuses further.



I see, however, that you've got some of it in green color. Does that mean something special?


Text coming after // are code comments, that are just there to explain things for a human reader. The game does nothing with such text (it's stripped out when the NSS file is compiled to NCS). I just color them green to make them more distinguishable from the actual script code when reading the script. :)
 kamikazees
12-15-2006, 1:21 PM
#5
I bet you are right that it's running more than once (although I was alone when testing). I think I remember reading in a thread that the k_ai_master.ncs script doesn't allow more than a +20stat/+200hp adjustment, so even if my messed up script ran a dozen times, it would only give those hounds +20/+200. That's exactly what they had now that I think about it (+10 to all saves, +200hp). As soon as I get home I'll try your ideas. I bet they work.

As an aside, your mods rock. I'm warmly reminded of your AI script everytime a TSL dark jedi force chokes me now. :) Superb and thanks again.

EDIT: Yahoo! It worked perfectly. Now as I get better I can scale it up. Thanks, Stoffe! Perfect!!!
Page: 1 of 1