Aller au contenu

Photo

Thunderstorm in area


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

#1
Imperator

Imperator
  • Members
  • 64 messages

I'm trying to make it so certain areas can have an event which fires onheartbeat, which will generate a random location(s) within that area and create a call lightning visual effect on an invisible object that gets created by the create random location method, then after it fires it'll destroy the invisible object and continue on.

 

I thought I saw a get random location within area function in the toolset but I can't seem to find it any longer >.>

 

Anyone interested in this enough to help me?



#2
Tarot Redhand

Tarot Redhand
  • Members
  • 2 666 messages

I seem to remember that there is something that is at least similar (if not matches) what you want in the Unearthed Gold collection that I gathered together a few years back.

 

TR


  • Imperator aime ceci

#3
KMdS!

KMdS!
  • Members
  • 189 messages

Here is a quick random location generator for an area.

location RandomLocationInArea(object oArea)
{
    int iRandomX = Random(GetAreaSize(AREA_WIDTH, oArea));
    int iRandomY = Random(GetAreaSize(AREA_HEIGHT, oArea));
    vector v = Vector(IntToFloat(iRandomX)+0.5f, IntToFloat(iRandomY)+0.5f, 0.0f);
    return Location(oArea,v, 0.0f);
}

Pass the area you wish a random location returned. Checks for the areas size and returns a random location within the limits of the areas dimensions with a 0.5 meter buffer around the edge of the area.


  • Imperator aime ceci

#4
Tarot Redhand

Tarot Redhand
  • Members
  • 2 666 messages

Isn't there a chance with that routine that the location returned will be inside something, such as a placeable or a tileset feature?

 

TR



#5
Baaleos

Baaleos
  • Members
  • 1 315 messages

Unfortunately there is no 'get is walkable' method to determine whether the position occurs within geometry.

Further more it assumes that the land is flat and always at an elevation of 0.0 on the z axes.

On a mountain tile-set, this is unlikely to be the case.

 

The only way to solve this, is to spawn a creature at the 'proposed' location, then get the creatures location, and then destroy the creature.

Done correctly, you can spawn, get the creatures location, and destroy it - so fast that the players never see the creature in the first place.

You can also make the creature have an invisible model just to be sure.

 

The reason you do this, is because creature spawning will automatically default to the nearest walkable location nearest to the provided spawning location.

This will provide you 

1. A position that is walkable

2. A correct Z elevation for the X and Y coordinate.

 

The only concerns I would mention, is that Spawning and Destroying of objects are computationally expensive.

I wouldn't recommend calling it rapidly.

 

 

 
location GetRealLocation(location l)
{
 
object o = CreateObject() // Your create creature step: choose a resref of the creature and provide l as the location.
location lActual = GetLocation(o);
DestroyObject(0.25,o);  //Destroy the object
return lActual;
}
 
 

  • Tarot Redhand aime ceci

#6
KMdS!

KMdS!
  • Members
  • 189 messages

The above code was meant to be used as a "get random location" to feed to the CreateObject function so as to allow the spawning of an invis object placeable in a random location that would be used as the target of the lightning strike as Baaleos mentioned above. Retrieving the location of the created object would then provide a valid location for the actual strike where the function above might not.

 

ie use function for the createobject spawn point, retrieve spawns location for a valid actual point for targeting the desired effect.


  • Imperator aime ceci

#7
Imperator

Imperator
  • Members
  • 64 messages

Thanks for the help. :)

 

This is what I have so far, it works well in an empty area but I need to make it so the lightning bolts only hit "InvisObj" <- the tag of the invisible placeable I have. When I try to put if(oZap!=GetObjectByTag("InvisObj")) it gives me an error during testing and doesn't work at all. Anyone know how to fix?

 

location RandomLocationInArea(object oArea)
{
    int iRandomX = Random(GetAreaSize(AREA_WIDTH, oArea)*10);
    int iRandomY = Random(GetAreaSize(AREA_HEIGHT, oArea)*10);
    vector v = Vector(IntToFloat(iRandomX)+0.5f, IntToFloat(iRandomY)+0.5f, 0.0f);
    return Location(oArea, v, 0.0f);
}


void main()
{

object oArea = GetArea(OBJECT_SELF);
        {
        int iCount=0;
        object oZap = GetFirstObjectInArea(oArea);
        effect eVFX;

            while(GetIsObjectValid(oZap))
            {


            if(GetObjectType(oZap)!=OBJECT_TYPE_PLACEABLE)
            {
                oZap = GetNextObjectInArea(oArea);
                continue;
            }


            ++iCount;
            eVFX = EffectVisualEffect(VFX_IMP_LIGHTNING_M);
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oZap);
            eVFX = EffectVisualEffect(VFX_COM_CHUNK_STONE_MEDIUM);
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oZap);

            effect eElectric = EffectDamage(d12(3), DAMAGE_TYPE_ELECTRICAL, DAMAGE_POWER_NORMAL);
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eElectric, oZap);
            oZap = GetNextObjectInArea(oArea);
            }

        int i;
        object oRandomTarget = OBJECT_INVALID;
        for(i=0; i<(-iCount+1); i++)
        {
            oRandomTarget = CreateObject(OBJECT_TYPE_PLACEABLE, "invisobj2", RandomLocationInArea(oArea));
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oRandomTarget);
            SetIsDestroyable(1,0,0);
            //DestroyObject(oRandomTarget, 1.0);
        }

        }

}
 



#8
KMdS!

KMdS!
  • Members
  • 189 messages

How about this....

    if(GetTag(oZap) != "InvisObj")


  • Imperator aime ceci