Author Topic: Thunderstorm in area  (Read 1812 times)

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Thunderstorm in area
« on: July 15, 2016, 10:22:38 pm »


               

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?



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Thunderstorm in area
« Reply #1 on: July 15, 2016, 10:41:10 pm »


               

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



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Thunderstorm in area
« Reply #2 on: July 18, 2016, 07:29:51 am »


               

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.



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Thunderstorm in area
« Reply #3 on: July 18, 2016, 10:47:50 am »


               

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



               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Thunderstorm in area
« Reply #4 on: July 18, 2016, 11:33:33 am »


               

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;
}
 
 


               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Thunderstorm in area
« Reply #5 on: July 18, 2016, 04:20:48 pm »


               

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.



               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Thunderstorm in area
« Reply #6 on: July 18, 2016, 10:42:07 pm »


               

Thanks for the help. '<img'>


 


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);

        }


        }


}

 



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Thunderstorm in area
« Reply #7 on: July 19, 2016, 03:17:08 am »


               

How about this....


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