Aller au contenu

Photo

Rock Spawning Script


  • Veuillez vous connecter pour répondre
11 réponses à ce sujet

#1
Li'l Rose

Li'l Rose
  • Members
  • 30 messages

 I'm trying to make an on enter script that spawns rocks at certain waypoints. There are several of the waypoints in the area, and I would like the script to check each waypoint, and have a 5% chance of spawning a rock. However the script is not working as it should, and not spawning any rocks, even if I set the percentage to 99%.

 

Here is the script. Any help would be appreciated.

void main()
{
    object oRock;

    // Get the creature who triggered this event.
    object oPC = GetEnteringObject();

    // Only fire for (real) PCs.
    if ( !GetIsPC(oPC)  ||  GetIsDMPossessed(oPC) )
        return;

    // Only fire once.
    if ( GetLocalInt(OBJECT_SELF, "RoseSpawnSilver") == 1 )
        return;

    SetLocalInt(OBJECT_SELF, "RoseSpawnSilver", 1);

    string sAreaTag = GetTag(GetArea(oPC));

    if (sAreaTag == "McGrukkMines1A")
    {
        // If the PC's total level is at least 10.
        if ( GetHitDice(oPC) >= 10 )
        {
            oRock == GetFirstObjectInArea(OBJECT_SELF);
            {
                if ( (GetIsObjectValid(oRock)) && (GetObjectType(oRock) == OBJECT_TYPE_WAYPOINT) )
                {
                    if ( GetTag(oRock) == "WP_ROSE_ROCK" )
                    {
                        // If success on a 5% chance.
                        if ( Random(100) < 5 )
                        {
                            CreateObject(OBJECT_TYPE_PLACEABLE, "cnrrocksilv", GetLocation(oRock));
                        }
                    }
                }
                oRock == GetNextObjectInArea(OBJECT_SELF);
            }
        }
    }
}



#2
henesua

henesua
  • Members
  • 3 863 messages

I put this together for you. Haven't tested it, but it should work. My assumption is that this is an Area OnEnter event script, but it should work for triggers too.

void main()
{
    // Get the creature who triggered this event.
    object oPC = GetEnteringObject();

    // EXCLUSIONS
    // Only execute for (real) PCs.
    if ( !GetIsPC(oPC)  ||  GetIsDM(oPC) )
        return;
    // Only execute once.
    if (GetLocalInt(OBJECT_SELF, "RoseSpawnSilver"))
        return;

    SetLocalInt(OBJECT_SELF, "RoseSpawnSilver", TRUE); // this won't happen again

    // CONFIGURATION
    int percentage_chance_to_appear     = 5; // a number between 0 and 100
    int required_pc_level               = 10;
    string resref_of_object_created     = "cnrrocksilv";
    string tag_of_waypoint              = "WP_ROSE_ROCK";
    int debug_mode_active               = FALSE; // change to TRUE to get better feedback while testing

    // LOOP OVER EVERY WAYPOINT IN THE AREA
    object this_area    = GetArea(OBJECT_SELF);
    int nNth    = 0;
    object oWP  = GetObjectByTag(tag_of_waypoint, nNth);
    object oPLC;
    while(GetIsObjectValid(oWP))
    {
        // determine if we should create this object
        if(     GetArea(oWP)==this_area // must be same area as this one
            &&  GetHitDice(oPC) >= required_pc_level
            &&  Random(100)+1 <= percentage_chance_to_appear
          )
        {
            oPLC = CreateObject(OBJECT_TYPE_PLACEABLE, resref_of_object_created, GetLocation(oWP));
            // Comment out the following debug line when this is ready to go live
            if(debug_mode_active){SendMessageToPC(GetFirstPC(),"Created "+GetName(oPLC)+" ("+ObjectToString(oPLC)+")");}
        }
        else
        {
            // Comment out the following debug line when this is ready to go live
            if(debug_mode_active){SendMessageToPC(GetFirstPC(),"Waypoint Found "+GetName(oWP)+" but object not created.");}
        }

        oWP  = GetObjectByTag(tag_of_waypoint, ++nNth);
    }
}

  • Li'l Rose aime ceci

#3
Li'l Rose

Li'l Rose
  • Members
  • 30 messages

I will try that, thank you very much.



#4
Li'l Rose

Li'l Rose
  • Members
  • 30 messages

I just tried it, and it worked great. Thank you.  :wub:



#5
Failed.Bard

Failed.Bard
  • Members
  • 774 messages

oRock == GetFirstObjectInArea(OBJECT_SELF);

oRock == GetNextObjectInArea(OBJECT_SELF);

 

You used == instead of = in your script, which is likely why it wasn't working.  == is comparative, = is for assigning values.


  • henesua, meaglyn et Li'l Rose aiment ceci

#6
Li'l Rose

Li'l Rose
  • Members
  • 30 messages

Thanks, I always wondered why sometimes I needed =, and other times I needed  ==.



#7
Li'l Rose

Li'l Rose
  • Members
  • 30 messages

Well, I tried the script with these changes. With the percentage at 99%, it spawn one rock, and then it stop running.

 

Hmmm, the quote not show. Well, I tried it like Failed.Bard suggested.



#8
henesua

henesua
  • Members
  • 3 863 messages

the script I gave you, only runs once per "server" load which appears to be what you want. not clear on what you are saying here.



#9
Li'l Rose

Li'l Rose
  • Members
  • 30 messages

Yes, your script worked very well, and I thank you for that. However I am wanting the same script to work in several floors of the silver mine, but with different percentages depending on the area and character level. What I am wanting is that as players go deeper into the mine, the better chance of rocks spawning. Which is why I had the area check in the script. Is it possible to do this with one script, or should I just put a different script in each area?



#10
meaglyn

meaglyn
  • Members
  • 807 messages

Yes, you can do it in one script...

 

The simple change is to add the tag of the area to the variable that is used to make it only happen once. But if you want different values for the different areas you either need to initialize those values differently for each area (again probably based on the area tag) or use variables on the areas to provide the required settings.



#11
henesua

henesua
  • Members
  • 3 863 messages

all of the configurable stuff can be fed from local variables set on the area if you make the following change:

// CONFIGURATION
object this_area    = GetArea(OBJECT_SELF);  // move this up here so that we can reference this_area for local variables
int percentage_chance_to_appear = GetLocalInt(this_area,"ROCK_percentage_chance_to_appear"); 
if(!percentage_chance_to_appear){percentage_chance_to_appear=5;}
int required_pc_level= GetLocalInt(this_area,"ROCK_required_pc_level");
if(!required_pc_level){required_pc_level=10;}
string resref_of_object_created = GetLocalString(this_area,"ROCK_resref_of_object_created");
if(resref_of_object_created==""){resref_of_object_created="cnrrocksilv";}
string tag_of_waypoint = GetLocalString(this_area,"ROCK_tag_of_waypoint");
if(tag_of_waypoint==""){tag_of_waypoint="WP_ROSE_ROCK";}
int debug_mode_active = GetLocalInt(this_area,"ROCK_debug_mode_active");
if(debug_mode_active!=1){debug_mode_active=FALSE;}

// LOOP OVER EVERY WAYPOINT IN THE AREA
int nNth = 0;
object oWP = GetObjectByTag(tag_of_waypoint, nNth);
object oPLC;
while(GetIsObjectValid(oWP))

This means that you can set the following on each area with this script to change the details of the rock spawn:

  • ROCK_percentage_chance_to_appear   --   int   --   value from 1 to 100  (for no chance set a value of -1). If unset, default is 5
  • ROCK_required_pc_level    --    int    --    value of 1 or greater. If unset, default is 10.
  • ROCK_resref_of_object_created    --    string    --    resref of your rock placeable. If unset, default is "cnrrocksilv"
  • ROCK_tag_of_waypoint    --    string    --    tag of the waypoints in this area. If unset, default is "WP_ROSE_ROCK"
  • ROCK_debug_mode_active    --    int    --    set to 1 if you want to see debug strings. all other values will turn off debug


#12
Li'l Rose

Li'l Rose
  • Members
  • 30 messages

Thank you very much.  :D