lfnetwork.com mark read register faq members calendar

Thread: Treasure pool editing
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 07-24-2013, 12:30 AM   #1
TriggerGod
Senior Member
 
TriggerGod's Avatar
 
Join Date: Mar 2008
Location: hiding
Posts: 2,415
Helpful! 
Treasure pool editing

So, I've been trying my best to code the treasure pools to add some new items into the treasure pool, so I edited k_inc_treas_k2.nss. I'm new to the language, but I thought I had the hang of it now.

Spoilered for long (I had to remove the comments at the top to appease the character count, but if you needed to see them, just look at the source file). Full, unabridged, modified script:

Show spoiler


The edited, relevant bits:

Code:
        //in GetItemPrefix
        case 451: return("a_atrisl_");
        case 461: return("a_atrisd_");

[..]

                                //in GetTreasureSpecific
                                case 451:
                                {
                                    nItemLevel = nItemLevel / 2;
                                    if(nItemLevel < 1) nItemLevel = 1;
                                    sItemLevel = IntToString(nItemLevel);
                                    if(nItemLevel < 10) sItemLevel = "0" + sItemLevel;
                                    break;
                                }
                                case 461:
                                {
                                    nItemLevel = nItemLevel / 2;
                                    if(nItemLevel < 1) nItemLevel = 1;
                                    sItemLevel = IntToString(nItemLevel);
                                    if(nItemLevel < 10) sItemLevel = "0" + sItemLevel;
                                    break;
                                }

[..]

//in PlaceTreasureJedi
 //add new atris style robes to certain areas, credits otherwise
        else if(nRoll == 5) 
        {
            if(!GetLocalBoolean(oContainer,57) && (GetModuleName() == "262TEL") || (GetModuleName() == "506OND") || (GetModuleName() == "602DAN") || (GetModuleName() == "610DAN") nItemType = 450;
            else nItemType = 900;
        }
        else if(nRoll == 6) 
        {
            if(!GetLocalBoolean(oContainer,57) && (GetModuleName() == "511DXN") || (GetModuleName() == "702KOR") || (GetModuleName() == "851NIH") || (GetModuleName() == "852NIH") || (GetModuleName() == "903MAL") || (GetModuleName() == "905MAL") || (GetModuleName() == "906MAL") nItemType = 460;
            else nItemType = 900;
        }

[..end of code]
I tried using Achille's code, so that if the "dice" were to roll a 5 or a 6, instead of giving credits immediately, it would first check if it were were in one of the areas I listed, and then it would put down either a light or a dark robe. However, I get a syntax error while compiling, telling me my error is at the nItemType's, specifically the ones at the tail-end of my huge if-statements.

So, I guess my question is two-fold: what is wrong with my code (I don't see what is actually wrong with my nItemType's), and is there an easier way to do what I described (injecting custom items into the loot system, but only having them show up in certain areas)?
TriggerGod is offline   you may: quote & reply,
Old 07-24-2013, 01:12 AM   #2
Fair Strides 2
Witty Programmer
 
Fair Strides 2's Avatar
 
Join Date: Jan 2012
Location: Oregon, United States
Posts: 585
Current Game: Master of Orion 2
Helpful! 
Quote:
Originally Posted by TriggerGod View Post
So, I've been trying my best to code the treasure pools to add some new items into the treasure pool, so I edited k_inc_treas_k2.nss. I'm new to the language, but I thought I had the hang of it now.

Spoilered for long (I had to remove the comments at the top to appease the character count, but if you needed to see them, just look at the source file). Full, unabridged, modified script:
if(!GetLocalBoolean(oContainer,57) && (GetModuleName() == "262TEL") || (GetModuleName() == "506OND") || (GetModuleName() == "602DAN") || (GetModuleName() == "610DAN") nItemType = 450;
else nItemType = 900;
}
else if(nRoll == 6)
{
if(!GetLocalBoolean(oContainer,57) && (GetModuleName() == "511DXN") || (GetModuleName() == "702KOR") || (GetModuleName() == "851NIH") || (GetModuleName() == "852NIH") || (GetModuleName() == "903MAL") || (GetModuleName() == "905MAL") || (GetModuleName() == "906MAL") nItemType = 460;
else nItemType = 900;
}
[/CODE]
Can't think of an easier way to do what you're doing, since you'd have to mess with module onenter scripts...

BUT I think I see the issue with your code: you didn't set up the if statement correctly. An if statement has a set of parantheses for it to check( in this case, the current module) and then a set of {} telling it what to do.

You didn't include those;if you put everything between the if and the else, including the ";", then it should work. If not, I'll try to help more.


All of my mods are available on Deadlystream.

Always remember modders: "Quality= Effort*Time"

KSE 3.3.4 is LIVE!!! Check it out here.

Check out WalkSwitch, the Walkmesh-changing tool!
Fair Strides 2 is offline   you may: quote & reply,
Old 07-24-2013, 01:44 AM   #3
TriggerGod
Senior Member
 
TriggerGod's Avatar
 
Join Date: Mar 2008
Location: hiding
Posts: 2,415
Helpful! 
I can definitely try that once I get a chance again, but my knowledge of coding (both from 3 years of advanced courses of Java and from looking at the source codes) says that you don't need to include braces in your ifs, if the statement within is only one line.

This code

Code:
if (a > b)
{
    a*c;
}
and this code

Code:
if(a > b)
    a*c;
would have the same outcome of a being multiplied by c. In the case of this, I simply took the same "layout" of the source code, and used it in my own added code. Which is the same as forsaking the enter hit altogether after the if statement and replacing it with a space. If all the previous ifs and else-ifs compiled without issue, I don't quite see why it would be different for mine. And it is only bringing syntax errors on the long if lines, not on its elses.
TriggerGod is offline   you may: quote & reply,
Old 07-24-2013, 02:08 AM   #4
Fair Strides 2
Witty Programmer
 
Fair Strides 2's Avatar
 
Join Date: Jan 2012
Location: Oregon, United States
Posts: 585
Current Game: Master of Orion 2
Helpful! 
Quote:
Originally Posted by TriggerGod View Post
I can definitely try that once I get a chance again, but my knowledge of coding (both from 3 years of advanced courses of Java and from looking at the source codes) says that you don't need to include braces in your ifs, if the statement within is only one line.

This code

Code:
if (a > b)
{
    a*c;
}
and this code

Code:
if(a > b)
    a*c;
would have the same outcome of a being multiplied by c. In the case of this, I simply took the same "layout" of the source code, and used it in my own added code. Which is the same as forsaking the enter hit altogether after the if statement and replacing it with a space. If all the previous ifs and else-ifs compiled without issue, I don't quite see why it would be different for mine. And it is only bringing syntax errors on the long if lines, not on its elses.
In that case, I'd modify your if statements. You have them doing multiple checks for the module, but I don't think it looks quite right. Try having it as:

Code:
if(!GetLocalBoolean(oContainer,57) && GetModuleName() == "262TEL" || "506OND" || "602DAN" || "610DAN"))
You'll notice that I put an extra ")" on the end. That is required. You have to have a matching number of "(" and ")".


All of my mods are available on Deadlystream.

Always remember modders: "Quality= Effort*Time"

KSE 3.3.4 is LIVE!!! Check it out here.

Check out WalkSwitch, the Walkmesh-changing tool!
Fair Strides 2 is offline   you may: quote & reply,
Old 07-24-2013, 02:38 AM   #5
JCarter426
Senior Member
 
JCarter426's Avatar
 
Join Date: Feb 2008
Location: Look to your left.
Posts: 1,636
I don't think it likes having both an and and an or in the same if. I recall having a similar problem once; I restructured the script and eventually it worked.

And while we're on the subject, you don't need braces between each case.


JCarter426 is offline   you may: quote & reply,
Old 07-24-2013, 02:46 AM   #6
TriggerGod
Senior Member
 
TriggerGod's Avatar
 
Join Date: Mar 2008
Location: hiding
Posts: 2,415
Helpful! 
While your modified code is wrong (you have one mismatched parenthesis), you did make me realize that I missed a close parenthesis in each of those two lines, and now my script will compile as normal.

e:

Quote:
Originally Posted by JCarter426 View Post
I don't think it likes having both an and and an or in the same if. I recall having a similar problem once; I restructured the script and eventually it worked.

And while we're on the subject, you don't need braces between each case.
As I've learned, better safe than sorry. I don't code in C, and I definitely don't code in this, so nyeh.

My excuse is that I was just copying the "robes" lines from that part (case 441) so double nyeh.
TriggerGod is offline   you may: quote & reply,
Old 07-24-2013, 05:31 PM   #7
Disturbed205
Rookie
 
Disturbed205's Avatar
 
Join Date: Mar 2009
Location: Knoxville, TN
Posts: 40
Current Game: The Elder Scrolls V
This looks like C or C++, I've never modded before so I was unaware what language KOTOR used.

Quote:
Originally Posted by Fair Strides 2 View Post
In that case, I'd modify your if statements. You have them doing multiple checks for the module, but I don't think it looks quite right. Try having it as:

Code:
if(!GetLocalBoolean(oContainer,57) && GetModuleName() == "262TEL" || "506OND" || "602DAN" || "610DAN"))
You'll notice that I put an extra ")" on the end. That is required. You have to have a matching number of "(" and ")".
If this is C++, then no, this would not function correctly. Here, "262TEL" will always evaluate to true.

if statements always have to be wrote out like
Code:
 if (GetModuleName() == "x" || GetModuleName() == "xxx"  || GetModuleName() == "2x")
Though in this case with the rolls it looks like it would be much easier to just use a switch case, instead of else if's.


Quote:
Originally Posted by TriggerGod View Post
This code

Code:
if (a > b)
{
    a*c;
}
and this code

Code:
if(a > b)
    a*c;
Yes, these are both the same code. You do not need braces if it's just one line.
Disturbed205 is offline   you may: quote & reply,
Old 07-24-2013, 11:14 PM   #8
Fair Strides 2
Witty Programmer
 
Fair Strides 2's Avatar
 
Join Date: Jan 2012
Location: Oregon, United States
Posts: 585
Current Game: Master of Orion 2
Helpful! 
Quote:
Originally Posted by Disturbed205 View Post
This looks like C or C++, I've never modded before so I was unaware what language KOTOR used.
This is no programming language. The language shares some aspects of C, but that's about it. From the NWNLexicon(which uses the same scripting language):

if/else Statement

if statements are used to control the flow of code execution. This is best illustrated with an example:

int bAlpha = FALSE;
int bBravo = FALSE;
if (bAlpha)
Code:
{
     // statement 1 ...
} 
else if (bBravo) 
{
     // statement 2 ...
}
else
{
     // statement 3 ...
     // in this example, this is the code that is executed becase
     // both bAlpha and bBravo are FALSE
}

If bAlpha evaluates to TRUE then statement 1 will execute. If it evaluates to FALSE then it will skip to the next if else and evaluate bBravo. If neither bAlpha or bBravo evaluates to TRUE then statement 3 will execute as the default (catch-all).



if statements can also be used alone without if else or else statements:

int bCondition = TRUE;
if (bCondition) PrintString("TRUE!");

If bCondition evaluates to FALSE it will skip PrintString("TRUE!") and move on to the next line of code.
and

Code:
&& Short circuit logical AND. 
|| Short circuit logical OR. 

...

It should be noted that && and || are considered short-circuit operators: that is, in an && conditional the first condition to evaluate as FALSE from left-to-right stops evaluation of the remaining statements, and in an || conditional the first condition to evaluate as TRUE from left-to-right stops evaluation of the remaining statements. What does this mean? Suppose you had two functions and either function returns TRUE or FALSE:

...
Following the last half of that paragraph, the function checks all of those "||"(or) parts and returns TRUE at the first match, or FALSE if none match. So it will work, as me and Fallen Guardian, and many other scripters can attest.


All of my mods are available on Deadlystream.

Always remember modders: "Quality= Effort*Time"

KSE 3.3.4 is LIVE!!! Check it out here.

Check out WalkSwitch, the Walkmesh-changing tool!
Fair Strides 2 is offline   you may: quote & reply,
Old 07-24-2013, 11:55 PM   #9
JCarter426
Senior Member
 
JCarter426's Avatar
 
Join Date: Feb 2008
Location: Look to your left.
Posts: 1,636
It's mostly C#, actually, but the compiler has some eccentricities, many of which could be figments of my imagination. But it's not C++.


JCarter426 is offline   you may: quote & reply,
Old 07-25-2013, 01:05 AM   #10
Disturbed205
Rookie
 
Disturbed205's Avatar
 
Join Date: Mar 2009
Location: Knoxville, TN
Posts: 40
Current Game: The Elder Scrolls V
Quote:
Originally Posted by Fair Strides 2 View Post
This is no programming language. The language shares some aspects of C, but that's about it. From the NWNLexicon(which uses the same scripting language):
I mean, it pretty much is a programming language, yeah.

Quote:
if/else Statement

if statements are used to control the flow of code execution. This is best illustrated with an example:
Yes, I'm aware, but it seems like a switch case would still be simpler and more elegant here, but if It's based from C# then there are some things I'm definitely not familiar with.

Quote:


Following the last half of that paragraph, the function checks all of those "||"(or) parts and returns TRUE at the first match, or FALSE if none match. So it will work, as me and Fallen Guardian, and many other scripters can attest.
That may be, I'm just speaking out of knowledge of C++/C that your specific example of syntax will cause the first to evaluate to true every time.Probably best practice not to do it.

Quote:
Originally Posted by JCarter426 View Post
It's mostly C#, actually, but the compiler has some eccentricities, many of which could be figments of my imagination. But it's not C++.
Good to know, thanks. Never worked with C# but I'm pretty good with C++ and mildly knowledgeable with C and LISP, so maybe I'll try to learn scripting. I'll have to read up on some tutorials
Disturbed205 is offline   you may: quote & reply,
Old 07-25-2013, 01:14 AM   #11
VarsityPuppet
Master of Puppets
 
VarsityPuppet's Avatar
 
Join Date: May 2009
Location: MN
Posts: 1,253
Current Game: Chrono Trigger
Contest winner - Modding Forum Veteran Veteran Modder Helpful! 
Reminded me more of Java than C#, but that just might be just small details (since they are basically the same thing).

VarsityPuppet is offline   you may: quote & reply,
Old 07-25-2013, 01:22 AM   #12
Fair Strides 2
Witty Programmer
 
Fair Strides 2's Avatar
 
Join Date: Jan 2012
Location: Oregon, United States
Posts: 585
Current Game: Master of Orion 2
Helpful! 
Quote:
Originally Posted by Disturbed205 View Post
I mean, it pretty much is a programming language, yeah.

Yes, I'm aware, but it seems like a switch case would still be simpler and more elegant here, but if It's based from C# then there are some things I'm definitely not familiar with.

That may be, I'm just speaking out of knowledge of C++/C that your specific example of syntax will cause the first to evaluate to true every time.Probably best practice not to do it.



Good to know, thanks. Never worked with C# but I'm pretty good with C++ and mildly knowledgeable with C and LISP, so maybe I'll try to learn scripting. I'll have to read up on some tutorials
Okay. Just wanted to defend my stand on coding schemes. I have used that coding scheme successfully before, and since HarIII threw that up there, I went in and supported his coding scheme. An example of a working example of this is a custom function I made:

Code:
int GetWeaponType(int BaseWeapon)
// Returns the weapon type of BaseWeapon, where BaseWeapon
// is equal to BASE_ITEM_* in the nwscript file.

// Interpreting the return value:
//	0 == ERROR (Invalid BASE_ITEM_*)
// 	1 == Melee weapons
//	2 == Blaster Pistols
//	3 == Blaster Rifles
//	4 == Heavy Weapons
//	5 == Lightsabers
//	6 == Wristlauncher
{
	if(BaseWeapon == 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 78 || 79 || 80 || 81 || 82 || 83 || 93)
	{
		return 1;
	}
	if(BaseWeapon == 12 || 13 || 14 || 15 || 16 || 17)
	{
		return 2;
	}
	if(BaseWeapon == 18 || 19 || 20 || 21 || 22)
	{
		return 3;
	}
	if(BaseWeapon == 23 || 24)
	{
		return 4;
	}
	if(BaseWeapon == 8 || 9 || 10)
	{
		return 5;
	}
	if(BaseWeapon == 91)
	{
		return 6;
	}
	return 0;
}
And if you want to learn, I'd suggest starting here.


All of my mods are available on Deadlystream.

Always remember modders: "Quality= Effort*Time"

KSE 3.3.4 is LIVE!!! Check it out here.

Check out WalkSwitch, the Walkmesh-changing tool!
Fair Strides 2 is offline   you may: quote & reply,
Old 08-05-2013, 05:13 AM   #13
Hassat Hunter
Forumite
 
Join Date: Jan 2010
Posts: 557
I see you're using the vanilla random items script. Why not use TSLRCM's instead? All those free fixes just for grabs .

Anyway, after making the script you need to re-compile approximately 100 scripts over various modules to make it work. You can make it easier on yourself just compiling the non-module ones, but then you miss out a lot of potential NPC's for your items.
Hassat Hunter is offline   you may: quote & reply,
Old 08-05-2013, 01:24 PM   #14
TriggerGod
Senior Member
 
TriggerGod's Avatar
 
Join Date: Mar 2008
Location: hiding
Posts: 2,415
Helpful! 
Quote:
Originally Posted by Hassat Hunter View Post
I see you're using the vanilla random items script. Why not use TSLRCM's instead? All those free fixes just for grabs .
Actually, what I ended up doing (or rather, will end up doing, once I get back to that particular project) is editing the k_plc_tresmil series of scripts, which should (not sure on this) require significantly less re-compile. The only problem is, is that DeNCS won't decompile your versions of the k_plc_tresmil series, so I can't tell if you've modified it further or not. If you guys did modify it, and you had a copy of the source code laying about, would you be able to shoot it my way so that I could make it compatible? If you guys didn't modify it, then there should be absolutely no problems with my editing of those files
TriggerGod is offline   you may: quote & reply,
Old 08-12-2013, 03:27 AM   #15
Hassat Hunter
Forumite
 
Join Date: Jan 2010
Posts: 557
Yeah, we did modify a bunch of files. Mostly in the modules, but also some of the generic dropscripts.
Maybe I should upload them, I got all handy here anyway. Was kinda waiting to see if not needing more fixes for TSLRCM, but that doesn't seem likely anymore anyway, don't see anyone mentioning issues with the random loot that I can see...
Hassat Hunter is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > Knights of the Old Republic > Editing / Modding > Holowan Laboratories > Treasure pool editing

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:56 AM.

LFNetwork, LLC ©2002-2011 - All rights reserved.
Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.