PDA

View Full Version : [HELP] My Script works.... But not how i expected


Holty1-5
05-14-2010, 06:43 PM
void main() {
object oDestroy = GetFirstItemInInventory( GetFirstPC() );
while( GetIsObjectValid( oDestroy ) ) {
if( GetTag( oDestroy ) == "rancorblood" )
DestroyObject( oDestroy, 0.00, FALSE, 0.00 );
oDestroy = GetNextItemInInventory( GetFirstPC() );
object oItem=CreateItemOnObject( "rancorstim", GetFirstPC());
}
}

See the above script
heres what its ment to do
Take away the Item RancorBlood and give you 1 rancor stim

But for some Unknown reason i Was Given 11 Stims not 1


What going on? Is it a Scripting Error? Help?

~Holty

newbiemodder
05-14-2010, 07:29 PM
I'm not a scripting guru, but I think this line

object oItem=CreateItemOnObject( "rancorstim", GetFirstPC());

should read

object oItem=CreateItemOnObject( "rancorstim", GetFirstPC(),1,0);

Istorian
05-15-2010, 03:30 AM
Well, I'm not a scripting guru, either, but, I think there is a certain logic problem here..This script checks the PC's inventory for every item that has the tag "rancorblood", and for each one it finds, it gives you 1 rancor stim. Thus, if you have 11 rancor blood in the inventory, the script destroys all of them, and you get 11 rancor stims in the inventory...

Try this one, instead, where the command to create the "rancorstim" is out of the while loop:

void main() {

object oDestroy = GetFirstItemInInventory( GetFirstPC() );

while( GetIsObjectValid( oDestroy ) ) {

if( GetTag( oDestroy ) == "rancorblood" )

DestroyObject( oDestroy, 0.00, FALSE, 0.00 );

oDestroy = GetNextItemInInventory( GetFirstPC() );

}

object oItem=CreateItemOnObject( "rancorstim", GetFirstPC());

}

Hope this helps! ;)

Holty1-5
05-15-2010, 04:48 PM
Well Guys thanks for the Help, I'll try Newbiemodders,

@Istorian
I understand that Loop thing but the Odd bit was i only Had 1 of the Blood item and it gave me 11 stims :P talk about Bonus :D

Darth333
05-15-2010, 04:55 PM
Well Guys thanks for the Help, I'll try Newbiemodders,

@Istorian
I understand that Loop thing but the Odd bit was i only Had 1 of the Blood item and it gave me 11 stims :P talk about Bonus :D

It depends on how the script is fired...the same happened (http://img.photobucket.com/albums/v144/Darth333/849a4a9a.jpg) to me when I first started modding kotor back in 2004 :p I don't recall this happening when running a script from a dlg file but it happens when opening containers and entering new areas. Add a variable to make sure the item is not already in the inventory or does not already exist (but I could be wrong as it's been a while since I've done any kotor modding).

Holty1-5
05-15-2010, 05:16 PM
Lol at The Pic xD

When i did the Exchange Newbiemodder suggest i didnt get 11 stims

I got 9 :D lol

I'll keep playin around with it and see what happens

logan23
05-17-2010, 01:33 AM
Code:

void main() {

object oDestroy = GetFirstItemInInventory( GetFirstPC() );

while( GetIsObjectValid( oDestroy ) ) {

if( GetTag( oDestroy ) == "rancorblood" )

DestroyObject( oDestroy, 0.00, FALSE, 0.00 );

oDestroy = GetNextItemInInventory( GetFirstPC() );

}

object oItem=CreateItemOnObject( "rancorstim", GetFirstPC());

}

Hope this helps!

This helps with limiting the stim creation to 1.
The only issue is if I have 2 boma blood items and then go through this script it only gives me one Stim. Is there a way to make it give the number of stim based on the number of bomablood items?

Thanks

Logan

Istorian
05-17-2010, 08:01 AM
You mean you want to get as many stims as the number of boma blood items you have in the inventory? or in a different rate? (e.g. 1 stim for every 2 boma blood items)

logan23
05-17-2010, 08:06 AM
Trying to get 2 bomablood = 2 boma stims, ....and so on... basically the number of bomablood will equal the number of boma stims...

Thanks

Istorian
05-17-2010, 08:33 AM
Well, I think that this will give you the result you'd like! ;)



void main() {

object oDestroy = GetFirstItemInInventory( GetFirstPC() );

while( GetIsObjectValid( oDestroy ) ) {

if( GetTag( oDestroy ) == "YOUR_BOMABLOOD_TAG_HERE" )

DestroyObject( oDestroy, 0.00, FALSE, 0.00 );

oDestroy = GetNextItemInInventory( GetFirstPC() );

object oItem=CreateItemOnObject( "YOUR_STIM_TAG_HERE", GetFirstPC());

}

}




Hope this helps! :D

logan23
05-17-2010, 10:27 AM
I believe thats the same script that was originally shown in first post. If so it ends up cashing kotor2 ,as if its trying to give you unlimited items,
Correct if im wrong about the two scripts. Im look at this on my cell so cant see whole page at once. Thanks

Istorian
05-18-2010, 07:02 AM
Actually it is, but even though I'm not a scripting guru or something like that, as far as I'm concerned, it works. I also made a quick module and tested it, and it works fine in my game...If it crashes in yours let me know, and I'll see what I can do! ;)

logan23
05-19-2010, 08:46 AM
I will do some testing with he script you have and place it in a new dlg file, and also try different .uti's to see the core of the freeze.

Thanks

logan23
05-21-2010, 10:28 PM
Nope it crashes.

I tested if it is the item , but it did not matter

Now this is for kotor2. I do not know if this matters.

Let me know if you have any other ideas.


Edit: Never mind I found a way using a script that i found on the forums:

int DestroyOneItem(object oItem) {
if (GetIsObjectValid(oItem)) {
int nStack = GetItemStackSize(oItem);

if (nStack > 1)
SetItemStackSize(oItem, nStack - 1);
else
DestroyObject(oItem);

return TRUE;
}
return FALSE;
}

void main () {
object oPC = GetFirstPC();

object oSaber = GetItemPossessedBy(oPC, "bomablood");
if (DestroyOneItem(oSaber))
return;

//oSaber = GetItemPossessedBy(oPC, "g_w_lghtsbr01");
//if (DestroyOneItem(oSaber))
//return;
}

I then will just place a create a boma stim on the next dlg line to keep it clean.

I just have to send the PC back to the beginning dlg line so that you can keep going over an over.

Will later look at shrinking the script so you don't have to do one at a time but this will solve it and make if work.

Thanks everyone!!