Author Topic: Simple Treasure Spawn System  (Read 345 times)

Legacy_Snarkblat

  • Full Member
  • ***
  • Posts: 104
  • Karma: +0/-0
Simple Treasure Spawn System
« on: July 17, 2011, 04:57:06 pm »


               I'm trying to create simple treasure spawning system that fires on the OnEnter script of an area. The treasure containers appear at waypoints marked WP_TREASURE.

The treasure container is a sarcophagus and it's userdefined script allows for random trapping and locking. It is by default trapped and unlocked, but I want the udef script to untrap and lock it.

void main()
{

if (d100()<=50)
   {SetLocked(OBJECT_SELF, TRUE);
   }

if (d100()<=75)
   {SetTrapActive(OBJECT_SELF, FALSE);
   }
}


The on enter script is what's giving me trouble. I need it to spawn the containers at each waypoint, not just one. I know the nNth++ function should be used but I'm having trouble implementing it in the script.

//Spawn Treasure
void main()
{

object oPC = GetEnteringObject();

//do once
if (!GetIsPC(oPC)) return;
int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));
if (DoOnce==TRUE) return;
SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);


object oSpawn;
location lTarget;
object oTarget;

int nNth;

//the waypoint tag
oTarget= GetObjectByTag("WP_TREASURE", nNth);
nNth++;

lTarget = GetLocation(oTarget);

//the object resref
oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "sarco003", lTarget);
nNth++;

}



So far the script spawns only one container, and it is always trapped. ':unsure:'

Suggestions?
               
               

               


                     Modifié par Snarkblat, 17 juillet 2011 - 03:58 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Simple Treasure Spawn System
« Reply #1 on: July 17, 2011, 05:18:52 pm »


               Try it more like this (I am a bit sleepy and heading to work so there could be errors but it does compile):


//Spawn Treasure
void main()
{
    object oPC = GetEnteringObject();
    if (!GetIsPC(oPC)) return;
    //do once
    int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));
    if (DoOnce  ==  TRUE) return;
    SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);

    object oSpawn;
    location lTarget;
    object oTarget;
    int nNth = 1;

    //the waypoint tag
    oTarget = GetObjectByTag("WP_TREASURE", nNth);
    while (GetIsObjectValid(oTarget))
    {
        lTarget = GetLocation(oTarget);
        oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "sarco003", lTarget);
        if (d100()<=50)
        {
            SetLocked(oSpawn, TRUE);
        }
        if (d100()<=75)
        {
            SetTrapActive(oSpawn, FALSE);
        }
        nNth++;
        oTarget = GetObjectByTag("WP_TREASURE", nNth);
    }
}


Hope that helps. Good luck.
               
               

               


                     Modifié par GhostOfGod, 17 juillet 2011 - 04:21 .
                     
                  


            

Legacy_CID-78

  • Sr. Member
  • ****
  • Posts: 261
  • Karma: +0/-0
Simple Treasure Spawn System
« Reply #2 on: July 17, 2011, 05:19:10 pm »


               there is no loop so obviously it only create one chest. why don't you simply make a do once onopen script like most tresure systems. and populate the chest

in your system you only spawn the same chest each time. there is no random treasure involved.

the whole system seem a bit poitless. you could easily just have placed the chest in the toolset, instead of the waypoint.
               
               

               
            

Legacy_Snarkblat

  • Full Member
  • ***
  • Posts: 104
  • Karma: +0/-0
Simple Treasure Spawn System
« Reply #3 on: July 17, 2011, 05:26:18 pm »


               Thank you GhostofGod. I implemented the script and it did exactly what I was looking for.

CID, the onopen script of the chest is the bioware standard treasure script, it gives random items. I wanted the object to be randomly trapped and locked, and I couldn't do that unless I spawned the item in the area. I could fire a heartbeat but that would eat up too much CPU.

Obviously, there will be different container types I was just testing this in one area. But thank you for your concern.
               
               

               
            

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0
Simple Treasure Spawn System
« Reply #4 on: July 18, 2011, 01:29:14 am »


               What about generating random treasure from a placable in an area every time the player enters?
               
               

               
            

Legacy_Taino

  • Sr. Member
  • ****
  • Posts: 268
  • Karma: +0/-0
Simple Treasure Spawn System
« Reply #5 on: July 18, 2011, 02:09:20 am »


               

Groove Widdit wrote...

What about generating random treasure from a placable in an area every time the player enters?

Would that be a hrtbeat script?
               
               

               
            

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0
Simple Treasure Spawn System
« Reply #6 on: July 19, 2011, 12:01:39 am »


               i don't think so - then it would generate treasure every six seconds.
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Simple Treasure Spawn System
« Reply #7 on: July 19, 2011, 01:55:42 am »


               If using the Bioware Treasure Scripts (or a variation of them as I do), then you can use the OnClosed Event to generate a random trap and even set random DCs and random unlock DCs. Here's an example of one I did for fixed placeables awhile back:

void main()
{
if (GetLocalInt(OBJECT_SELF,"CHEST")== 1) return;
SetLocalInt(OBJECT_SELF,"CHEST",1);
DelayCommand(604.0, SetLocked(OBJECT_SELF, TRUE));
DelayCommand(604.0, SetLockUnlockDC(OBJECT_SELF,25+d12()));
int nInt;
nInt = d10();
object oTarget;
oTarget = (OBJECT_SELF);

if (nInt==1)
{
DelayCommand(606.0, CreateTrapOnObject(TRAP_BASE_TYPE_STRONG_ACID, oTarget, STANDARD_FACTION_HOSTILE, "", ""));
DelayCommand(607.0, SetTrapActive(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDisarmable(oTarget, TRUE));
DelayCommand(607.0, SetTrapOneShot(oTarget, TRUE));
DelayCommand(607.0, SetTrapRecoverable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectDC(oTarget, 15+d12()));
DelayCommand(607.0, SetTrapDisarmDC(oTarget, 25+d12()));
DelayCommand(610.0, SetLocalInt(OBJECT_SELF,"CHEST",0));
}
else if (nInt==2)
{
DelayCommand(606.0, CreateTrapOnObject(TRAP_BASE_TYPE_STRONG_ELECTRICAL, oTarget, STANDARD_FACTION_HOSTILE, "", ""));
DelayCommand(607.0, SetTrapActive(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDisarmable(oTarget, TRUE));
DelayCommand(607.0, SetTrapOneShot(oTarget, TRUE));
DelayCommand(607.0, SetTrapRecoverable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectDC(oTarget, 15+d12()));
DelayCommand(607.0, SetTrapDisarmDC(oTarget, 25+d12()));
DelayCommand(610.0, SetLocalInt(OBJECT_SELF,"CHEST",0));
}
else if (nInt==3)
{
DelayCommand(606.0, CreateTrapOnObject(TRAP_BASE_TYPE_STRONG_FIRE, oTarget, STANDARD_FACTION_HOSTILE, "", ""));
DelayCommand(607.0, SetTrapActive(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDisarmable(oTarget, TRUE));
DelayCommand(607.0, SetTrapOneShot(oTarget, TRUE));
DelayCommand(607.0, SetTrapRecoverable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectDC(oTarget, 15+d12()));
DelayCommand(607.0, SetTrapDisarmDC(oTarget, 25+d12()));
DelayCommand(610.0, SetLocalInt(OBJECT_SELF,"CHEST",0));
}
else if (nInt==4)
{
DelayCommand(606.0, CreateTrapOnObject(TRAP_BASE_TYPE_STRONG_FROST, oTarget, STANDARD_FACTION_HOSTILE, "", ""));
DelayCommand(607.0, SetTrapActive(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDisarmable(oTarget, TRUE));
DelayCommand(607.0, SetTrapOneShot(oTarget, TRUE));
DelayCommand(607.0, SetTrapRecoverable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectDC(oTarget, 15+d12()));
DelayCommand(607.0, SetTrapDisarmDC(oTarget, 25+d12()));
DelayCommand(610.0, SetLocalInt(OBJECT_SELF,"CHEST",0));
}
else if (nInt==5)
{
DelayCommand(606.0, CreateTrapOnObject(TRAP_BASE_TYPE_STRONG_GAS, oTarget, STANDARD_FACTION_HOSTILE, "", ""));
DelayCommand(607.0, SetTrapActive(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDisarmable(oTarget, TRUE));
DelayCommand(607.0, SetTrapOneShot(oTarget, TRUE));
DelayCommand(607.0, SetTrapRecoverable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectDC(oTarget, 15+d12()));
DelayCommand(607.0, SetTrapDisarmDC(oTarget, 25+d12()));
DelayCommand(610.0, SetLocalInt(OBJECT_SELF,"CHEST",0));
}
else if (nInt==6)
{
DelayCommand(606.0, CreateTrapOnObject(TRAP_BASE_TYPE_STRONG_HOLY, oTarget, STANDARD_FACTION_HOSTILE, "", ""));
DelayCommand(607.0, SetTrapActive(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDisarmable(oTarget, TRUE));
DelayCommand(607.0, SetTrapOneShot(oTarget, TRUE));
DelayCommand(607.0, SetTrapRecoverable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectDC(oTarget, 15+d12()));
DelayCommand(607.0, SetTrapDisarmDC(oTarget, 25+d12()));
DelayCommand(610.0, SetLocalInt(OBJECT_SELF,"CHEST",0));
}
else if (nInt==7)
{
DelayCommand(606.0, CreateTrapOnObject(TRAP_BASE_TYPE_STRONG_NEGATIVE, oTarget, STANDARD_FACTION_HOSTILE, "", ""));
DelayCommand(607.0, SetTrapActive(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDisarmable(oTarget, TRUE));
DelayCommand(607.0, SetTrapOneShot(oTarget, TRUE));
DelayCommand(607.0, SetTrapRecoverable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectDC(oTarget, 15+d12()));
DelayCommand(607.0, SetTrapDisarmDC(oTarget, 25+d12()));
DelayCommand(610.0, SetLocalInt(OBJECT_SELF,"CHEST",0));
}
else if (nInt==8)
{
DelayCommand(606.0, CreateTrapOnObject(TRAP_BASE_TYPE_STRONG_SONIC, oTarget, STANDARD_FACTION_HOSTILE, "", ""));
DelayCommand(607.0, SetTrapActive(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDisarmable(oTarget, TRUE));
DelayCommand(607.0, SetTrapOneShot(oTarget, TRUE));
DelayCommand(607.0, SetTrapRecoverable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectDC(oTarget, 15+d12()));
DelayCommand(607.0, SetTrapDisarmDC(oTarget, 25+d12()));
DelayCommand(610.0, SetLocalInt(OBJECT_SELF,"CHEST",0));
}
else if (nInt==9)
{
DelayCommand(606.0, CreateTrapOnObject(TRAP_BASE_TYPE_STRONG_SPIKE, oTarget, STANDARD_FACTION_HOSTILE, "", ""));
DelayCommand(607.0, SetTrapActive(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDisarmable(oTarget, TRUE));
DelayCommand(607.0, SetTrapOneShot(oTarget, TRUE));
DelayCommand(607.0, SetTrapRecoverable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectDC(oTarget, 15+d12()));
DelayCommand(607.0, SetTrapDisarmDC(oTarget, 25+d12()));
DelayCommand(610.0, SetLocalInt(OBJECT_SELF,"CHEST",0));
}
else if (nInt==10)
{
DelayCommand(606.0, CreateTrapOnObject(TRAP_BASE_TYPE_STRONG_TANGLE, oTarget, STANDARD_FACTION_HOSTILE, "", ""));
DelayCommand(607.0, SetTrapActive(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDisarmable(oTarget, TRUE));
DelayCommand(607.0, SetTrapOneShot(oTarget, TRUE));
DelayCommand(607.0, SetTrapRecoverable(oTarget, TRUE));
DelayCommand(607.0, SetTrapDetectDC(oTarget, 15+d12()));
DelayCommand(607.0, SetTrapDisarmDC(oTarget, 25+d12()));
DelayCommand(610.0, SetLocalInt(OBJECT_SELF,"CHEST",0));
}
}


               
               

               


                     Modifié par kalbaern, 19 juillet 2011 - 12:57 .
                     
                  


            

Legacy_Snarkblat

  • Full Member
  • ***
  • Posts: 104
  • Karma: +0/-0
Simple Treasure Spawn System
« Reply #8 on: July 19, 2011, 06:42:21 pm »


               Thank you kalbearn that's very interesting. But wouldn't putting the trapping/locking script on the OnClosed event defeat the purpose of it being locked? Maybe I misunderstood.
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Simple Treasure Spawn System
« Reply #9 on: July 22, 2011, 12:11:35 am »


               

Snarkblat wrote...

Thank you kalbearn that's very interesting. But wouldn't putting the trapping/locking script on the OnClosed event defeat the purpose of it being locked? Maybe I misunderstood.


Putting it in the OnClosed Event ensures it randomly relocks and retraps the container after it is first used. So, you'd need to also prelock and trap the container when placed in the toolset.
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Simple Treasure Spawn System
« Reply #10 on: July 22, 2011, 12:42:18 am »


               Here's another option based on GoG's script. Untested but should compile and assumes his worked fine too. '<img'>

//Spawn Treasure
void main()
{
object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;
//do once
int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));
if (DoOnce == TRUE) return;
SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);

object oSpawn;
location lTarget;
object oTarget;
int nNth = 1;
int nTrap;
switch(Random(10))
{
case 0: nTrap = TRAP_BASE_TYPE_DEADLY_ACID; break;
case 1: nTrap = TRAP_BASE_TYPE_DEADLY_ACID_SPLASH; break;
case 2: nTrap = TRAP_BASE_TYPE_DEADLY_ELECTRICAL; break;
case 3: nTrap = TRAP_BASE_TYPE_DEADLY_FIRE; break;
case 4: nTrap = TRAP_BASE_TYPE_DEADLY_FROST; break;
case 5: nTrap = TRAP_BASE_TYPE_DEADLY_GAS; break;
case 6: nTrap = TRAP_BASE_TYPE_DEADLY_HOLY; break;
case 7: nTrap = TRAP_BASE_TYPE_DEADLY_NEGATIVE; break;
case 8: nTrap = TRAP_BASE_TYPE_DEADLY_SONIC; break;
case 9: nTrap = TRAP_BASE_TYPE_DEADLY_SPIKE; break;
}
//the waypoint tag
oTarget = GetObjectByTag("WP_TREASURE", nNth);
while (GetIsObjectValid(oTarget))
{
lTarget = GetLocation(oTarget);
oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "sarco003", lTarget);
if (d100()<=50)
{
SetLocked(oSpawn, TRUE);
SetLockUnlockDC(oSpawn, 20+d20());//Sets Lock DC to 21-40
}
if (d100()<=75)
{
CreateTrapOnObject(nTrap, oSpawn, STANDARD_FACTION_HOSTILE, "", "");
DelayCommand(0.6, SetTrapActive(oSpawn, TRUE));
DelayCommand(0.6, SetTrapDetectable(oSpawn, TRUE));
DelayCommand(0.6, SetTrapDisarmable(oSpawn, TRUE));
DelayCommand(0.6, SetTrapOneShot(oSpawn, FALSE));
DelayCommand(0.6, SetTrapRecoverable(oSpawn, TRUE));
DelayCommand(0.6, SetTrapDetectDC(oSpawn, 10+d20())); //Sets Detect Trap DC to 11-30
DelayCommand(0.6, SetTrapDisarmDC(oSpawn, 20+d20())); //Sets Disarm Trap DC to 21-40
}
nNth++;
oTarget = GetObjectByTag("WP_TREASURE", nNth);
}
}


Let me know if it works (if even used). It's set for Deadly traps, but commented well enough (I hope) that changing lock and trap DCs to what you prefer is easy enough. The delayed commands are just to ensure that the trap exists inorder to set the other options.
               
               

               


                     Modifié par kalbaern, 21 juillet 2011 - 11:43 .
                     
                  


            

Legacy_Snarkblat

  • Full Member
  • ***
  • Posts: 104
  • Karma: +0/-0
Simple Treasure Spawn System
« Reply #11 on: July 24, 2011, 03:10:29 pm »


               That's brilliant, kalbaern. I will test later when I get home.