Author Topic: Help with on open script.  (Read 349 times)

Legacy_SHOVA

  • Hero Member
  • *****
  • Posts: 893
  • Karma: +0/-0
Help with on open script.
« on: July 19, 2010, 04:58:40 pm »


               Hello scripters, I need a second or third look at this on open script.

 location lTarget;
object oSpawn;
object oTarget;


//Put this script OnOpen
#include "nw_i0_generic"
#include "x0_i0_treasure"
void main()
{
object oPC = GetLastOpenedBy();
if (!GetIsPC(oPC)) return;
    if (GetLocalInt(OBJECT_SELF,"NW_DO_ONCE") != 0)
    {
       return;
    }
SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",1);
if (d100()<=30)
   {
   SendMessageToPC(oPC, "Nothing here.");
   }
else
   {
   CTG_CreateTreasure(TREASURE_TYPE_LOW, GetLastOpener(), OBJECT_SELF);
if (d100()>40)
   return;
int nInt;
nInt = d10();
if (nInt==1)
   {
   oTarget = oPC;
     ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie001", lTarget);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==2)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie002", lTarget);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==3)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie003", lTarget);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==4)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie004", lTarget);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==5)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie005", lTarget);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
 if (nInt==6)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie006", lTarget);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==7)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie007", lTarget);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==8)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie008", lTarget);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==9)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie009", lTarget);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==10)
   {
   oTarget = oPC;
   ActionSpeakString("From the dust within, Stinking Insects comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "carrionbeetle01", lTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "carrionbeetle01", lTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "carrionbeetle01", lTarget);

   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   } }
DelayCommand(600.0f, CTG_SetIsTreasureGenerated(OBJECT_SELF, FALSE));
DelayCommand( 600.0, SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",0));
}



What I want to accomplish, is 30% there is nothing, 70% there is treasure type low, with a 40% possibility that 1 of 10 random things will spawn. I want it to only do this once,  then after 10 minutes, it can do it again.

thanks in advance!
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Help with on open script.
« Reply #1 on: July 19, 2010, 06:03:25 pm »


               how about
if (nInt<=10)
{
 //do this..
}

or just use a case/switch statement.

switch(nInt)
{
 case 1  (Set variable changes & spawns here)

}

//do the other general commands here

The case/switch statement would reduce coding, just an idea.
               
               

               


                     Modifié par Genisys, 19 juillet 2010 - 05:07 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Help with on open script.
« Reply #2 on: July 20, 2010, 02:43:12 am »


               

SHOVA wrote...



What I want to accomplish, is 30% there is nothing, 70% there is treasure type low, with a 40% possibility that 1 of 10 random things will spawn. I want it to only do this once,  then after 10 minutes, it can do it again.

thanks in advance!



By looking at your script I can see you are not getting the outcome you want.  Here is a paraphrase of your script. to make it easier to see what is going wrong. 

--------------------------

if (GetLocalInt(OBJECT_SELF,"NW_DO_ONCE") != 0)  return;

SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",1);

if (d100()<=30)   SendMessageToPC(oPC, "Nothing here.");
else
{

// to this point we are OK we are creating low tresure if at a 70% rate.   
CTG_CreateTreasure(TREASURE_TYPE_LOW, GetLastOpener(), OBJECT_SELF);

// This line here is your problem in the code. When the expression evaluates as true it returnsfrom the script. The problem with is that your delay commands at the end will never get set.  In effect this object will never generate tresure again
if (d100()>40)return; 
int nInt;
nInt = d10();
// a bunch of if ststments to handle the random on the D10.
}
DelayCommand(600.0f, CTG_SetIsTreasureGenerated(OBJECT_SELF, FALSE));
DelayCommand( 600.0, SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",0));
}



----------------------------------------------

The fastest fix without a lot of rewriting would be to change the  code at fault to.

-------------------------
int nInt = 0;
if (d100()>40)  nInt = d10();
-------------------------

This way if your 40% hits nInt will be set into a 1 to 10 range; if it does not hit it will stay 0 and not triger any of you if statments.
               
               

               


                     Modifié par Lightfoot8, 20 juillet 2010 - 02:06 .
                     
                  


            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Help with on open script.
« Reply #3 on: July 20, 2010, 03:22:58 am »


               switch(nInt)

{



case 1:

{

 //Treasure Code Here

}

case 2:

{

 //treasure code here

}

case 3:

{

 //treasure code here

}

case 4:

{

 //treasure code here

}

case 5:

{

 //treasure code here

}

case 6:

{

 //treasure code here

}

case 7:

{

 //treasure code here

}

case 8:

{

 //treasure code here

}

case 9:

{

 //treasure code here

}

case 10:

{

 //treasure code here

}



//End Case/Switch Statement

}
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Help with on open script.
« Reply #4 on: July 20, 2010, 03:33:10 am »


               Yes Genisys,

 You already stated to turn it into a case statment.  But that would not fix the Original logic problem.
               
               

               
            

Legacy_SHOVA

  • Hero Member
  • *****
  • Posts: 893
  • Karma: +0/-0
Help with on open script.
« Reply #5 on: July 20, 2010, 02:50:13 pm »


               Lightfoot, thanks a bunch! you were right about the logic, it was only spawning treasure once. I have changed the script to:

location lTarget;
object oSpawn;
object oTarget;

//Put this script OnOpen
#include "nw_i0_generic"
#include "x0_i0_treasure"
void main()
{
object oPC = GetLastOpenedBy();
if (!GetIsPC(oPC)) return;
   if (GetLocalInt(OBJECT_SELF,"NW_DO_ONCE") != 0)  return;
SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",1);
int nInt;
nInt = d12();
if (nInt==1)
   {
   SendMessageToPC(oPC, "Nothing here.");
    }
if (nInt==2)
   {
     CTG_CreateTreasure(TREASURE_TYPE_LOW, GetLastOpener(), OBJECT_SELF);
   }
if (nInt==3)
   {
   oTarget = oPC;
     ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie001", lTarget);
   CTG_CreateTreasure(TREASURE_TYPE_LOW, GetLastOpener(), OBJECT_SELF);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==4)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie002", lTarget);
   CTG_CreateTreasure(TREASURE_TYPE_LOW, GetLastOpener(), OBJECT_SELF);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==5)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie003", lTarget);
    CTG_CreateTreasure(TREASURE_TYPE_LOW, GetLastOpener(), OBJECT_SELF);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==6)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie004", lTarget);
     CTG_CreateTreasure(TREASURE_TYPE_LOW, GetLastOpener(), OBJECT_SELF);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==7)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie005", lTarget);
    CTG_CreateTreasure(TREASURE_TYPE_LOW, GetLastOpener(), OBJECT_SELF);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
 if (nInt==8)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie006", lTarget);
    CTG_CreateTreasure(TREASURE_TYPE_LOW, GetLastOpener(), OBJECT_SELF);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==9)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie007", lTarget);
    CTG_CreateTreasure(TREASURE_TYPE_LOW, GetLastOpener(), OBJECT_SELF);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==10)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie008", lTarget);
    CTG_CreateTreasure(TREASURE_TYPE_LOW, GetLastOpener(), OBJECT_SELF);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==11)
   {
   oTarget = oPC;
    ActionSpeakString("From the dust within, rotting flesh comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "s_zombie009", lTarget);
    CTG_CreateTreasure(TREASURE_TYPE_MED, GetLastOpener(), OBJECT_SELF);
oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
   }
if (nInt==12)
   {
   oTarget = oPC;
   ActionSpeakString("From the dust within, Stinking Insects comes forth.");
   lTarget = GetLocation(oTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "carrionbeetle01", lTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "carrionbeetle01", lTarget);
   oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "carrionbeetle01", lTarget);
   CTG_CreateTreasure(TREASURE_TYPE_LOW, GetLastOpener(), OBJECT_SELF);
   oTarget = oSpawn;
   SetIsTemporaryEnemy(oPC, oTarget);
   AssignCommand(oTarget, ActionAttack(oPC));
   AssignCommand(oTarget, DetermineCombatRound(oPC));
}
DelayCommand(600.0f, CTG_SetIsTreasureGenerated(OBJECT_SELF, FALSE));
DelayCommand(600.0, SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",0))} 

In the old, it was respawning treasure, but it was not always giving the message there is nothing, or it was spawning the critters and not spawning the treasure. I also did not like the 30% nothing as it turned out to be to limited in the over all treasure distibrution.

 Genisys, thanks, but I do not think the switch case is the way I want to do this.