Jump to content

Home

[HELP] My Script works.... But not how i expected


Holty1-5

Recommended Posts

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

Link to comment
Share on other sites

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! ;)

Link to comment
Share on other sites

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 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).

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ) == "[color=LimeGreen]YOUR_BOMABLOOD_TAG_HERE[/color]" )

DestroyObject( oDestroy, 0.00, FALSE, 0.00 );

oDestroy = GetNextItemInInventory( GetFirstPC() );

object oItem=CreateItemOnObject( "[color=LimeGreen]YOUR_STIM_TAG_HERE[/color]", GetFirstPC());

}

}


 

Hope this helps! :D

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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! ;)

Link to comment
Share on other sites

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!!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...