The Exiled

Shunned by Man, Accepted by Gods
* FAQ    * Search   * Members
* Login   * Register
It is currently Thu Mar 28, 2024 5:58 pm 

 View unanswered posts | View active topics


 Board index » General Area » Modding
Post new topic Reply to topic Users browsing this forum: No registered users and 5 guests
Author
Message
TE-Noxwizard


User avatar
Joined: Tue Jun 07, 2005 5:59 pm
Posts: 942
Location: Texas
Post Posted: Tue Sep 05, 2006 7:08 pm    Post subject: Using a camera to check deploy area
Reply with quote
 
This function checks the deploy area when you use it in a deployable item. It spawns a camera at your desired deployment height, then rotates 360 degrees and checks for objects in the way. If you have an object that decends, you can use the %vert to define how high you want to look striaght up above the deployment area.
Code:
// Function to check deploy area/landing path
// Spawn a camera, rotate all the way around and check for objects
// -Noxwizard
// %pos - deploy position
// %height - height to deploy camera
// %radius - how far to look around
// %vert - how high to look up (dropships)

function checkarea(%client,%pos,%height,%radius,%vert)
{
   %camera = newObject("Camera","Turret",cameraturret,true);
   GameBase::setPosition(%camera,Vector::add(%pos,"0 0 " @ %height));

    // Look up
   if(GameBase::getLOSInfo(%camera,%vert,"1.5708 0 0"))
   {
      %name = GameBase::getDataName($los::object);

      if(!%name)
         %name = getObjectType($los::object);
        if(%name == "SimTerrain")
            Client::sendMessage(%client,0,"You are underground."); //Not likely, but possible
        else
         Client::sendMessage(%client,0,%name@" in way, "@Vector::getDistance($los::position, GameBase::getPosition(%client))@" meters up.");
      DeleteObject(%camera);
      return false;
   }
    // Look around
    for(%i = 0; %i < 6.3; %i = %i + 0.1)
    {
       if(GameBase::getLOSInfo(%camera,%radius,"0 0 " @ %i))
       {
          %name = GameBase::getDataName($los::object);

          if(!%name)
             %name = getObjectType($los::object);
            if(%name == "SimTerrain")
                Client::sendMessage(%client,0,"You are too close to hills.");
            else
             Client::sendMessage(%client,0,%name@" in way, "@Vector::getDistance($los::position, GameBase::getPosition(%client))@" meters up.");
          DeleteObject(%camera);
          return false;
       }
     }
    // Now that the circle has completed, deploy
    DeleteObject(%camera);
    return true;
}

Code Explaination:

This creates a camera at the player's position at the height defined:
Code:
%camera = newObject("Camera","Turret",cameraturret,true);
GameBase::setPosition(%camera,Vector::add(%pos,"0 0 " @ %height));

This has the camera look straight up for your defined height:
Code:
GameBase::getLOSInfo(%camera,%vert,"1.5708 0 0")

Put that into an if statement and we can check if there's an object in the camera's line-of-sight. If there's something in the way, we'll get it's name and tell the client that it's in the way, and how high up it is. Unless it's terrain. ;)
Code:
   if(GameBase::getLOSInfo(%camera,%vert,"1.5708 0 0"))
   {
      %name = GameBase::getDataName($los::object);

      if(!%name)
         %name = getObjectType($los::object);
        if(%name == "SimTerrain")
            Client::sendMessage(%client,0,"You are underground."); //Not likely, but possible
        else
         Client::sendMessage(%client,0,%name@" in way, "@Vector::getDistance($los::position, GameBase::getPosition(%client))@" meters up.");
      DeleteObject(%camera);
      return false;
   }

Now this part's a bit different. We want it to look all the way around, so we will have it look in a lot of directions, by adding 0.1, looking, adding another 0.1, looking, and so on. To do that we use a for loop. We went it to look all the way around, which will be from 0 to 6.28. It's 6.28, because that's just the way circles are handled, instead of degrees it's radians, 6.28 is the same as 360 degrees.
Code:
    // Look around
    for(%i = 0; %i < 6.3; %i = %i + 0.1)
    {
       if(GameBase::getLOSInfo(%camera,%radius,"0 0 " @ %i))
       {
          %name = GameBase::getDataName($los::object);

          if(!%name)
             %name = getObjectType($los::object);
            if(%name == "SimTerrain")
                Client::sendMessage(%client,0,"You are too close to hills.");
            else
             Client::sendMessage(%client,0,%name@" in way, "@Vector::getDistance($los::position, GameBase::getPosition(%client))@" meters up.");
          DeleteObject(%camera);
          return false;
       }
     }

So, if there's something in the way, it reports a false value, which will immediately stop checking. If it makes it through all those checks without seeing an object, it will report a true.

To use this, put this in your deployment code:
Code:
// check for other airbases/buildings/etc  -Noxwizard
%pos = $los::position;
if(!checkarea(%client,%pos,95,20,20))
    return false;

What that does is checks the area you've defined. So this spawns a camera up 95 meters above you, then looks up 20 meters, then looks around in a 20 meter radius. If it doesn't find anything, it'll go onto the next items in the deploy code. If it does find something, it will halt the deployment.



Image
Image
 Top Offline
Profile WWWICQYIM
Author
Message
TE-Hammy


User avatar
Joined: Thu Jul 14, 2005 5:43 pm
Posts: 3204
Post Posted: Wed Sep 06, 2006 2:36 pm    Post subject:
Reply with quote
 
uhh... GO NOX! woo!


This is not the sandwich you are looking for. Move along.
Image
Ze Sechs-fire wrote:
[22:00] [df]Braveskin: Can AfroMuffin spend the night at my house?
[22:00] [df]Braveskin: I have movize
[22:00] Hammy: No. You'll touch him.
[22:00] Hammy: With gusto.
[22:00] Hammy: He's not even a day old, pedophile.
[22:00] Hammy: >:l
[22:00] [df]Braveskin: plez!!
 Top Offline
Profile
Author
Message
TE-4ev3r


User avatar
Joined: Sat Jul 16, 2005 3:18 pm
Posts: 1251
Location: That sunshiny state.
Post Posted: Wed Sep 06, 2006 6:30 pm    Post subject:
Reply with quote
 
So, this basically checks the item area limit, and will negate the Item in Way thing if nothing is spotted?


Image
Image
 Top Offline
Profile
Author
Message
TE-Noxwizard


User avatar
Joined: Tue Jun 07, 2005 5:59 pm
Posts: 942
Location: Texas
Post Posted: Wed Sep 06, 2006 9:09 pm    Post subject:
Reply with quote
 
Think of it like sonar. The camera makes a circle, if a blip shows up, it stops the deployment.

I might add a container box fill, which will create a box with given dimensions and detect objects in it. I will still need the camera since the container doesn't detect terrain.



Image
Image
 Top Offline
Profile WWWICQYIM
Display posts from previous:  Sort by  
Post new topic Reply to topic Board index » General Area » Modding
Previous topic :: Next topic  
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group