Any script for randomizing an enemy/entity spawn with a ranged area/coord?

Mr.Q!

Well-known member
Topic.
What I am experiencing is people know where an enemy/boss is going to pop out at certain times, so players wait for them and perform meaty attacks on them for guaranteed damage.
 
Topic.
What I am experiencing is people know where an enemy/boss is going to pop out at certain times, so players wait for them and perform meaty attacks on them for guaranteed damage.

You can certainly do it, but yes, it would have to be scripted. IIRC, both @Bloodbane and @Kratus have such systems already. Tagging them to see.

DC
 
Topic.
What I am experiencing is people know where an enemy/boss is going to pop out at certain times, so players wait for them and perform meaty attacks on them for guaranteed damage.
I suggest taking a look at my SOR2X game. In the chars/random folder, there's some dummy enemies used to spawn other enemies applying some randomness.
There you will find random names, palettes, and you can also add random positions following the same logic.

EDIT: You can also try changing the position directly in the level spawn using inline scripts. The concept would be something like this:

Code:
spawn        Galsia
@script       
void main()
{
    if(random >= chance){
        changeentityproperty(self, "position", x+amount, z, y);
    }
}
@end_script
flip        1
coords        350 150 0
at            0
 
Last edited:
I'm not sure how enemies are spawned in your game.
If they are spawned using enemy spawner, you'd need to modify that spawner to apply position randomizer.
If they are spawned in the level directly, you could use this spawnscript to randomize their position.
RandXY.c:
C:
void main()
{
    void self = getlocalvar("self");
    int Minz = openborvariant("PLAYER_MIN_Z");
    int Maxz = openborvariant("PLAYER_MAX_Z");
    int XPos = openborvariant("xpos"); //Get screen edge's position
    int Screen = openborvariant("hResolution"); // Get screen width
    int r = rand()%50;
    int zW = Maxz - Minz;
    int zM = Minz + zW/2;
    float dz = zM + zW*r/100;
    int W = 60;

    if(r%2 == 1){
      changeentityproperty(self, "position", XPos + Screen + W, dz);
    } else {
      changeentityproperty(self, "position", XPos - W, dz);
    }
}

Declare it like this:
Code:
spawn   Enemy
spawnscript data/scripts/RandXZ.c
health  20
coords  400 206
at      0

With this declared, Enemy could appear from either left or right edge and at randomized z coord.
 
My bad, I didn't give more information.

Given the image attached to this post (very rough sketch):

Ok so he is getting owned each time he spawns despite having no bbox, and I don't want to add an attack to him, so a spawnscript would be nice, yes, but in a way that it doesn't necessarily spawn outside the screen but within a range starting from his real spawning coord position in the stage .txt file...Something like:


  • Blue area is the walkable ground
  • Yellow are are walls
  • Red circle is where the enemy is currently spawning. Imagine he is a ninja so he just teleports there, with a proper anim spawn.
Imagine a stage with a walkable area of 130 minz, 220 maxz, 500pixels long:

Spawn NinjaOwnedByMeatyAttack
spawnscript <--- A script that checks current spawning coord an randomize within a range from said point, like (minus50 Xpixels, plus50 Xpixels, minus30 Zpixels, plus30 Zpixels)
coords 250 180 0
at 0

Sorry if I am explaining this badly :ROFLMAO:
 

Attachments

  • bor - 0000.png
    bor - 0000.png
    70 KB · Views: 3
@Mr.Q!

Basically you'd want to start with code that defines a cube based on adjustable coordinates. That way you can just provide the bounding for each spawn as needed. I would give the system a default size so you can shortcut for most uses.

Then within that cube, you can run RNG to get a spot within it.

So on spawn in the designated position, the cube generates centered on the entity, a random spot inside of the cube gets selected and then entity is moved there instantly. On screen, it would appear the entity spawns into a random place within around the general area.

Not too complex really. Just a bit of geometry work and some optimization to minimize the the math.

Unfortunately I'm way too tied up this week to write the code. Interviewing for academic work. Mid next week I could look at making you a sample if no one beats me to it.

DC
 
Ranged cube.... are you spawning enemies onscreen instead offscreen? that spawnscript above is for spawning enemies offscreen BTW.
 
Yes, I mean, if should just pay attention to the spawning coord in the stage .txt and starting from there, a randomized spawning range acting as a 'cube' like DC said, so it shouldn't matter if it's onscreen or offscreen . This can actually have lots of uses for npc's, weather stuff, environment, etc.
 
Back
Top Bottom