:S arh, i can't work out how to use c_scan to detect entities.
Can anyone show me an example.
Sure.
c_scan scans an area in a sphere or a part of a sphere (an arc, circle, cone, etc).
It will trigger any entity with "enable_scan."
c_scan has four parameters, c_scan(position,angle,areaOfEffect,mode).
Position is where it starts.
Angle gives its direction
Area of effect is a vector. X is the horizontal arc range in degrees (360 for a circle or sphere). Y is the vertical arc range in degrees (360 for a circle or sphere. Z is the radius.
Mode is the flag which you wish to use:
IGNORE_ME Ignores the me entity; to be combined with SCAN_ENTS.
IGNORE_YOU Ignores the you entity; to be combined with SCAN_ENTS.
IGNORE_PASSABLE A7.2 LC Ignores entities with the PASSABLE flag; to be combined with SCAN_ENTS.
IGNORE_FLAG2 A7.2 LC Ignores entities with FLAG2; to be combined with SCAN_ENTS.
SCAN_ENTS Scans for entities within the cone, and triggers their EVENT_SCAN event.
SCAN_POS Scans for camera positions placed in the level.
SCAN_PATHS Scans for path start positions.
SCAN_NODES Scans for path node positions.
SCAN_LIGHTS Scans for static lights.
SCAN_LIMIT Finds only entities with ENABLE_SCAN set, or only static lights whose range can reach the scan origin. Can be combined with SCAN_ENTS and SCAN_LIGHTS.
SCAN_FLAG2 A7.2 LC Opposite of IGNORE_FLAG2: Finds only entities with FLAG2.
Combined with an OR, |, symbol, just like in the other c_ instructions.
Here's an example: This is a function called in my tank game that causes a barrel to explode, doing damage to anything nearby:
function scanExpl(ENTITY* ent)
{
ANGLE scanAng; //the angle the scan range fires at
scanAng.pan = 360; //360 degrees
wait(1); //wait to avoid dangerous instructions (this is called after an event)
c_scan(my.x,scanAng.pan,vector(360,360,300),IGNORE_PASSABLE | IGNORE_ME | SCAN_ENTS | SCAN_LIMIT);
//scan from the gas tank, ignoring the gas tank, doing a full sphere with a 300 unit radius
vec_scale(normal,10); // produce an explosion into the normal direction
wait(1);
effect(effect_explo,500,ent.x,normal);
ent_create("sphere.mdl",ent.x,explo); //create the explosion sphere
random_seed(0);
int iNum = integer(random(100));
if(iNum < 10)
ent_create("wrench2.mdl",my.x,wrench);
wait(1);
ent_remove(me); //remove the gas tank
}
When this function is called, it defines an angle, the pan is assigned the value 360 for a circular scan. Then there is wait(1) because I'm using event triggers and c_scan is a dangerous instruction and this keeps that error from occuring.
Then I call c_scan at the object's position, a 360 direction, a full sphere with a radius of 300 units, and with the mode set to ignore passable, ignore itself. SCAN_ENTS triggers the entities with ENABLE_SCAN set and SCAN_LIMIT detects only entitys with ENABLE_SCAN.
After the c_scan, the barrel explodes, with a particle and a model effect, then with a random number, it decides whether or not it will drop a wrench (power up that fixes a tank) and then removes itself.
And this is the other half of c_scan, enabling an entity to react. This code makes the player tank take damage, either itself or its shield, if it is in range of the scan.
function pEvents()
{
if(event_type == EVENT_SCAN)
{
if(!player.shielded)
{
my.health -= 20 * player.armor * god;
player.armor += 0.1; //take away a fifth of the armor
}
else
{
shield.health -= 20;
}
}
}
action pTank()
{
//...set parameters and such
player = my; //set the pointer
set(my,FLAG2 | SHADOW | METAL | CAST); //set some flags
my.emask |= (ENABLE_SCAN); //allows the tank to recieve c_scans
my.event = pEvents; //called if the tank is hit by a c_scan
//...code continues on
my.emask is set to ENABLE_SCAN, allowing the tank to be detected by c_scan and calling "pEvents()" when it is hit by a scan.
pEvents() then checks if the event_type is EVENT_SCAN and if so, it then applies damage to either the player or the shield.
This code is tested and does work.