About CalcExplosionCoverage(location, handle, mask)
by Wonglee · in Torque Game Engine · 05/19/2005 (2:02 am) · 3 replies
In my game players can drop bombs anywhere, then the players who are in the cross-shaped area will die.
Now I wanna make the player who is behind a wall not affected by the explosion, but it seems doesn't work. Everytime the player died either he is behind the wall or not.
the following is part of my codes:
function damagesearch()
{
$foundedobjhandle = ContainerFindFirst(16384, $bombpos, 5, 1, 20) || ContainerFindFirst(16384, $bombpos, 1, 5, 20);
%checkresult = checkdamage();
if (%checkresult)
$foundedobjhandle.applydamage(20);
while ($foundedobjhandle = ContainerFindNext())
{
if ($foundedobjhandle){
%checkresult = checkdamage();
if (%checkresult)
$foundedobjhandle.applydamage(20);
}
else
break;
}
}
function checkdamage()
{
%temppos = $foundedobjhandle.getTransform();
%checkresult = CalcExplosionCoverage(%temppos, $foundedobjhandle, TypeMasks::StaticTSObjectType | $TypeMasks::PlayerObjectType);
return %checkresult;
}
I wanna use the %checkresult to determin whether apply the damage. If it is 1, the player dies.
$foundedobjhandle is the handle of the player who is in the area
Now I wanna make the player who is behind a wall not affected by the explosion, but it seems doesn't work. Everytime the player died either he is behind the wall or not.
the following is part of my codes:
function damagesearch()
{
$foundedobjhandle = ContainerFindFirst(16384, $bombpos, 5, 1, 20) || ContainerFindFirst(16384, $bombpos, 1, 5, 20);
%checkresult = checkdamage();
if (%checkresult)
$foundedobjhandle.applydamage(20);
while ($foundedobjhandle = ContainerFindNext())
{
if ($foundedobjhandle){
%checkresult = checkdamage();
if (%checkresult)
$foundedobjhandle.applydamage(20);
}
else
break;
}
}
function checkdamage()
{
%temppos = $foundedobjhandle.getTransform();
%checkresult = CalcExplosionCoverage(%temppos, $foundedobjhandle, TypeMasks::StaticTSObjectType | $TypeMasks::PlayerObjectType);
return %checkresult;
}
I wanna use the %checkresult to determin whether apply the damage. If it is 1, the player dies.
$foundedobjhandle is the handle of the player who is in the area
About the author
#2
I'm not sure what it is you're hoping to do here, but this is almost certainly the wrong way to do it. '||' is a logical OR operator, so unless I'm Really Confused, $foundobjhandle will be 'true' or 'false'. Passing either one as an object handle is likely to do some Very Strange Things.
And if I may make some suggestions:
1) Enclose your code in 'code' tags to keep extra spacing. The forum will automatically strip out all spaces after the first one:
To do so, you need to enclose your source code in the aptly-named "code" tags. This forum uses [] to wrap tags, so it looks something like:
[-code-]
...put code here...
[/-code-]
Strip out the '-' around the 'code' tags and you'll be in business. Sadly the "Click _here_ to learn how" link appears to be broken, or it could explain in greater detail.
2) Mixed upper and lower case letters make it easier to read your code:
foundobjhandle -> foundObjHandle. You'll notice that TGE's script functions and constants all use the same kind of mixed case to enhance readability. Without it, some variable names can become Very Confusing. Pretty much anything with "as" followed by a word starting with 's' is going to get you in trouble. ;) I can't think of any cases where words could have two different legitimate interpretations that are clarified by adding upperCaseLetters to your variable names... but if you keep naming variables this way, you WILL find one.
05/19/2005 (9:50 am)
$foundedobjhandle =
ContainerFindFirst(16384, $bombpos, 5, 1, 20) ||
ContainerFindFirst(16384, $bombpos, 1, 5, 20);I'm not sure what it is you're hoping to do here, but this is almost certainly the wrong way to do it. '||' is a logical OR operator, so unless I'm Really Confused, $foundobjhandle will be 'true' or 'false'. Passing either one as an object handle is likely to do some Very Strange Things.
And if I may make some suggestions:
1) Enclose your code in 'code' tags to keep extra spacing. The forum will automatically strip out all spaces after the first one:
the quick brown foxbecomes: "the quick brown fox"
To do so, you need to enclose your source code in the aptly-named "code" tags. This forum uses [] to wrap tags, so it looks something like:
[-code-]
...put code here...
[/-code-]
Strip out the '-' around the 'code' tags and you'll be in business. Sadly the "Click _here_ to learn how" link appears to be broken, or it could explain in greater detail.
2) Mixed upper and lower case letters make it easier to read your code:
foundobjhandle -> foundObjHandle. You'll notice that TGE's script functions and constants all use the same kind of mixed case to enhance readability. Without it, some variable names can become Very Confusing. Pretty much anything with "as" followed by a word starting with 's' is going to get you in trouble. ;) I can't think of any cases where words could have two different legitimate interpretations that are clarified by adding upperCaseLetters to your variable names... but if you keep naming variables this way, you WILL find one.
Wonglee
I misunderstood the meaning of the firest argument
The following is the reference:
CalcExplosionCoverage(location, handle, mask)
Parameters:
location Where the target object is.
handle Target object.
mask Object type mask of objects that may block the explosion.
Return:
Numeric 1 = affected, 0 = unaffected.
Description:
Determines if an object at a location was affected by an explosion. Listed object types will be taken into consideration in the calculation, if they would block the explosion force.
Usage:
%coverage = CalcExplosionCoverage(%location, %targetObject, $TypeMasks::InteriorObjectType | TypeMasks::TerrainObjectType | $TypeMasks::VehicleObjectType);
location Where the target object is. handle Target object
their explanation is too easy to confuse!!!
especially to english learner!!!
It took me 5 hours, finally i found i misunderstood the argument.......
depressed......