06.10.2013, 19:06
Hey , Guy I want to make object have health you can help me ?
I Want to set object have Health 10,000 HP How to make that
I Want to set object have Health 10,000 HP How to make that
BulletCollisionSphere() Parameters (playerid, weapon, Float:sx, Float:sy, Float:sz, Float:fScale = 30.0, Float:radius = 1.0) playerid - id of player to check weapon - weapon (only used to check for sniper) Float:sx - Positon of sphere X Float:sy - Positon of sphere Y Float:sz - Positon of sphere Z Float:fScale = 30.0 - (Optional) Scales the vector (Higher values detect from further away) Float:radius - (Optional) Radiuss of the sphere
BulletCollisionBox() - Returns true if a player is aiming at and intersects a box Parameters (playerid, weapon, Float:b1x, Float:b1y, Float:b1z, Float:b2x, Float:b2y, Float:b2z, Float:fScale = 30.0) playerid - id of player to check weapon - weapon (only used to check for sniper) b1x - Bound box min X b1y - Bound box min Y b1z - Bound box min Z b1x - Bound box max X b1y - Bound box max Y b1z - Bound box max Z Float:fScale = 30.0 - (Optional) Scales the vector (Higher values detect from further away)
new OldAmmo[MAX_PLAYERS], OldWeap[MAX_PLAYERS];
new CurrAmmo[MAX_PLAYERS], CurrWeap[MAX_PLAYERS];
// Used for detecting when a player shoots
// Note: - hackers will locked ammo will not be able to trigger this
// - You must hook this callback yourself
forward OnPlayerShoot(playerid,weaponid,ammo);
public OnPlayerUpdate(playerid)
{
// Get the current weapon and ammo
CurrWeap[playerid] = GetPlayerWeapon(playerid);
CurrAmmo[playerid] = GetPlayerAmmo(playerid);
// Player still has old weapon does this weapon now have less ammo?
if(CurrWeap[playerid] == OldWeap[playerid] && CurrAmmo[playerid] < OldAmmo[playerid])
{
CallLocalFunction( "OnPlayerShoot", "iii", playerid, CurrWeap[playerid], CurrAmmo[playerid]);
}
OldWeap[playerid] = CurrWeap[playerid];
OldAmmo[playerid] = CurrAmmo[playerid];
return 1;
}
// Checks if a players bullet intersects a sphere
stock BulletCollisionSphere(playerid, weapon, Float:sx, Float:sy, Float:sz, Float:fScale = 30.0, Float:radius = 1.0)
{
new
Float:fP[3],
Float:fV[3],
Float:object[3],
Float:sphere[3];
sphere[0] = sx, sphere[1] = sy, sphere[2] = sz;
GetPlayerCameraPos(playerid, fP[0], fP[1], fP[2]);
GetPlayerCameraFrontVector(playerid, fV[0], fV[1], fV[2]);
// Compensate (This is not perfect yet any ideas anyone?)
if(weapon != 34)
{
new Float:FacingA;
GetPlayerFacingAngle(playerid, FacingA);
FacingA -= 90.0;
if(FacingA < 0.0) FacingA += 360.0;
else if(FacingA > 360.0) FacingA -= 360.0;
fP[0] = (fP[0] + 0.6 * floatsin(-FacingA,degrees));
fP[2] += 1.2;
}
object[0] = fP[0] + floatmul(fV[0], fScale);
object[1] = fP[1] + floatmul(fV[1], fScale);
object[2] = fP[2] + floatmul(fV[2], fScale);
// Check if line intersects sphere
if(RaySphere(fP, object, sphere, radius)) return 1;
return 0;
}
// Checks if a players bullet intersects a bounding box
stock BulletCollisionBox(playerid, weapon, Float:b1x, Float:b1y, Float:b1z, Float:b2x, Float:b2y, Float:b2z, Float:fScale = 30.0)
{
new
Float:fP[3],
Float:fV[3],
Float:object[3],
Float:sphere[3];
new Float:b1[3];
new Float:b2[3];
b1[0] = b1x;
b1[1] = b1y;
b1[2] = b1z;
b2[0] = b2x;
b2[1] = b2y;
b2[2] = b2z;
GetPlayerCameraPos(playerid, fP[0], fP[1], fP[2]);
GetPlayerCameraFrontVector(playerid, fV[0], fV[1], fV[2]);
// Compensate (This is not perfect yet any ideas anyone?)
if(weapon != 34)
{
new Float:FacingA;
GetPlayerFacingAngle(playerid, FacingA);
FacingA -= 90.0;
if(FacingA < 0.0) FacingA += 360.0;
else if(FacingA > 360.0) FacingA -= 360.0;
fP[0] = (fP[0] + 0.6 * floatsin(-FacingA,degrees));
fP[2] += 1.2;
}
object[0] = fP[0] + floatmul(fV[0], fScale);
object[1] = fP[1] + floatmul(fV[1], fScale);
object[2] = fP[2] + floatmul(fV[2], fScale);
// Check if line intersects box
if(CheckLineBox( b1, b2, fP, object)) return 1;
return 0;
}
stock RaySphere(Float:p1[3],Float:p2[3],Float:sc[3],Float:r)
{
new Float:a, Float:b, Float:c;
new Float:bb4ac;
new Float:dp[3];
dp[0] = p2[0] - p1[0];
dp[1] = p2[1] - p1[1];
dp[2] = p2[2] - p1[2];
a = dp[0] * dp[0] + dp[1] * dp[1] + dp[2] * dp[2];
b = 2 * (dp[0] * (p1[0] - sc[0]) + dp[1] * (p1[1] - sc[1]) + dp[2] * (p1[2] - sc[2]));
c = sc[0] * sc[0] + sc[1] * sc[1] + sc[2] * sc[2];
c += p1[0] * p1[0] + p1[1] * p1[1] + p1[2] * p1[2];
c -= 2 * (sc[0] * p1[0] + sc[1] * p1[1] + sc[2] * p1[2]);
c -= r * r;
bb4ac = b * b - 4 * a * c;
if(bb4ac < 0) return 0;
return 1;
}
// returns true if line (L1, L2) intersects with the box (B1, B2)
// returns intersection point in Hit
stock CheckLineBox( Float:B1[3], Float:B2[3], Float:L1[3], Float:L2[3])
{
if (L2[0] < B1[0] && L1[0] < B1[0]) return false;
if (L2[0] > B2[0] && L1[0] > B2[0]) return false;
if (L2[1] < B1[1] && L1[1] < B1[1]) return false;
if (L2[1] > B2[1] && L1[1] > B2[1]) return false;
if (L2[2] < B1[2] && L1[2] < B1[2]) return false;
if (L2[2] > B2[2] && L1[2] > B2[2]) return false;
if (L1[0] > B1[0] && L1[0] < B2[0] &&
L1[1] > B1[1] && L1[1] < B2[1] &&
L1[2] > B1[2] && L1[2] < B2[2]) return true;
new Float:Hit[3];
if ( (GetBoxIntersection( L1[0]-B1[0], L2[0]-B1[0], L1, L2, Hit) && InBox( Hit, B1, B2, 1 ))
|| (GetBoxIntersection( L1[1]-B1[1], L2[1]-B1[1], L1, L2, Hit) && InBox( Hit, B1, B2, 2 ))
|| (GetBoxIntersection( L1[2]-B1[2], L2[2]-B1[2], L1, L2, Hit) && InBox( Hit, B1, B2, 3 ))
|| (GetBoxIntersection( L1[0]-B2[0], L2[0]-B2[0], L1, L2, Hit) && InBox( Hit, B1, B2, 1 ))
|| (GetBoxIntersection( L1[1]-B2[1], L2[1]-B2[1], L1, L2, Hit) && InBox( Hit, B1, B2, 2 ))
|| (GetBoxIntersection( L1[2]-B2[2], L2[2]-B2[2], L1, L2, Hit) && InBox( Hit, B1, B2, 3 ))) return true;
return false;
}
stock GetBoxIntersection(Float:fDst1, Float:fDst2, Float:P1[3], Float:P2[3], Float:hit[3])
{
if ( (fDst1 * fDst2) >= 0.0) return 0;
if ( fDst1 == fDst2) return 0;
new Float:fdst = -fDst1/(fDst2-fDst1);
hit[0] = P1[0] + (P2[0]-P1[0]) * (fdst);
hit[1] = P1[1] + (P2[1]-P1[1]) * (fdst);
hit[2] = P1[2] + (P2[2]-P1[2]) * (fdst);
return 1;
}
stock InBox( Float:Hit[3], Float:B1[3], Float:B2[3], Axis)
{
if ( Axis==1 && Hit[2] > B1[2] && Hit[2] < B2[2] && Hit[1] > B1[1] && Hit[1] < B2[1]) return 1;
if ( Axis==2 && Hit[2] > B1[2] && Hit[2] < B2[2] && Hit[0] > B1[0] && Hit[0] < B2[0]) return 1;
if ( Axis==3 && Hit[0] > B1[0] && Hit[0] < B2[0] && Hit[1] > B1[1] && Hit[1] < B2[1]) return 1;
return 0;
}