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.

Remove Item script

Page: 1 of 1
 moda
01-24-2010, 1:04 AM
#1
i cant think of a way to remove 500 chemicals of a character with scripting.

i tried a while loop, and remove item script command but it wouldn't registered the chem_00001 item as valid for removal.

please helps
 harIII
01-24-2010, 12:41 PM
#2
This should do the job:


void main() {
object oDestroy = GetFirstItemInInventory( GetFirstPC() );
while( GetIsObjectValid( oDestroy ) ) {
if( GetTag( oDestroy ) == "chem_00001" )
DestroyObject( oDestroy, 0.00, FALSE, 0.00 );
oDestroy = GetNextItemInInventory( GetFirstPC() );
}
}
 moda
01-24-2010, 4:14 PM
#3
but i need to destroy 500 chemicals not 1
 harIII
01-24-2010, 5:18 PM
#4
It should just keep going through your inventory and if the item matches the tag (in this case chem_00001) and destroys it.
 moda
01-24-2010, 5:52 PM
#5
yes but that will destroy all chemicals in my inventory

edit heres my current code



void main()
{

object oPC = GetSpellTargetObject();
int nSubtract = 1;
int nRand = d3( 1 );
int int3 = 1;
int inte = 1;
int destroy = 500;
object oDestroy = GetFirstItemInInventory( GetFirstPC() );

while( GetIsObjectValid( oDestroy ) ) {
if( GetTag( oDestroy ) == "chem_00001" )
if (GetItemStackSize(oDestroy) <= 500)
{

switch( nRand ) {
case 1:
AdjustCreatureAttributes( oPC, ABILITY_STRENGTH, nSubtract );
break;
case 2:
AdjustCreatureAttributes( oPC, ABILITY_DEXTERITY, nSubtract );
break;
case 3:
AdjustCreatureAttributes( oPC, ABILITY_CONSTITUTION, nSubtract );
break;
}
switch( nRand ) {
case 1:
AdjustCreatureAttributes( oPC, ABILITY_STRENGTH, nSubtract );
break;
case 2:
AdjustCreatureAttributes( oPC, ABILITY_DEXTERITY, nSubtract );
break;
case 3:
AdjustCreatureAttributes( oPC, ABILITY_CONSTITUTION, nSubtract );
break;
}
int nRand2 = d3( 1 );
switch( nRand2 ) {
case 1:
AdjustCreatureAttributes( oPC, ABILITY_WISDOM, -1 );
break;
case 2:
AdjustCreatureAttributes( oPC, ABILITY_CHARISMA, -1 );
break;
case 3:
AdjustCreatureAttributes( oPC, ABILITY_INTELLIGENCE, -1 );
break;
}
while (inte > destroy){
while( GetIsObjectValid( oDestroy ) ) {
if( GetTag( oDestroy ) == "chem_00001" )
DestroyObject( oDestroy, 0.00, FALSE, 0.00 );
destroy = destroy -1;
oDestroy = GetNextItemInInventory( GetFirstPC() );
}
}
}
}
}
 harIII
01-24-2010, 5:59 PM
#6
Try this, I'm not sure if it will compile though

void main() {
object oDestroy = GetFirstItemInInventory( GetFirstPC() );
int count = 0;

while(GetIsObjectValid( oDestroy ) ) {
if( count <= 500 && GetTag( oDestroy ) == "chem_00001" )
count++;
DestroyObject( oDestroy, 0.00, FALSE, 0.00 );
oDestroy = GetNextItemInInventory( GetFirstPC() );
}
}
 moda
01-24-2010, 6:21 PM
#7
as you can see my code is a tad heavy on nested statements, but that was the way i learned back in the day
 harIII
01-24-2010, 7:42 PM
#8
For me my philosophy is whatever gets the job done, if it's 10 lines or 100 lines of code, just so long as it does the what you need.
 moda
01-24-2010, 9:39 PM
#9
which it doesnt :(/// the logic is flawless it just doesnt work
 moda
01-25-2010, 6:21 AM
#10
i tried rewriting it as

void main()
{

object oPC = GetSpellTargetObject();
int nSubtract = 1;
int nRand = d3( 1 );
int int3 = 1;
object oDestroy = GetFirstItemInInventory( GetFirstPC() );
int count = 0;

while(GetIsObjectValid( oDestroy ) ) {
if( count <= 500 && GetTag( oDestroy ) == "chem_00001" )
count++;
DestroyObject( oDestroy, 0.00, FALSE, 0.00 );
oDestroy = GetNextItemInInventory( GetFirstPC() );
}
if(count =500){


switch( nRand ) {
case 1:
AdjustCreatureAttributes( oPC, ABILITY_STRENGTH, nSubtract );
break;
case 2:
AdjustCreatureAttributes( oPC, ABILITY_DEXTERITY, nSubtract );
break;
case 3:
AdjustCreatureAttributes( oPC, ABILITY_CONSTITUTION, nSubtract );
break;
}
switch( nRand ) {
case 1:
AdjustCreatureAttributes( oPC, ABILITY_STRENGTH, nSubtract );
break;
case 2:
AdjustCreatureAttributes( oPC, ABILITY_DEXTERITY, nSubtract );
break;
case 3:
AdjustCreatureAttributes( oPC, ABILITY_CONSTITUTION, nSubtract );
break;
}
int nRand2 = d3( 1 );
switch( nRand2 ) {
case 1:
AdjustCreatureAttributes( oPC, ABILITY_WISDOM, -1 );
break;
case 2:
AdjustCreatureAttributes( oPC, ABILITY_CHARISMA, -1 );
break;
case 3:
AdjustCreatureAttributes( oPC, ABILITY_INTELLIGENCE, -1 );
break;
}
}
}




but it now just destroys all items in my inventory
Page: 1 of 1