2024-03-03, 04:32 PM
Here's a basic outline of how you can implement this:
Create the rocket object when fired from a vehicle.
Track the movement of the rocket using OnPlayerObjectMoved.
Check for collisions between the rocket and nearby vehicles in the callback.
Here's an example code to demonstrate this:
Create the rocket object when fired from a vehicle.
Track the movement of the rocket using OnPlayerObjectMoved.
Check for collisions between the rocket and nearby vehicles in the callback.
Here's an example code to demonstrate this:
PHP Code:
forward OnPlayerObjectMoved(playerid, objectid);
public OnPlayerObjectMoved(playerid, objectid)
{
new Float:x, Float:y, Float:z;
GetObjectPos(objectid, x, y, z); // Get the current position of the object
new Float:minX, Float:maxX, Float:minY, Float:maxY, Float:minZ, Float:maxZ;
GetObjectBoundingBox(objectid, minX, minY, minZ, maxX, maxY, maxZ); // Get the bounding box of the object
new Float:vX, Float:vY, Float:vZ;
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i) && i != playerid)
{
GetPlayerPos(i, vX, vY, vZ); // Get the position of each player
// Check if the player's position is within the bounding box of the rocket object
if (vX >= minX && vX <= maxX && vY >= minY && vY <= maxY && vZ >= minZ && vZ <= maxZ)
{
// Player i collided with the rocket object
// You can perform actions here, such as damaging the vehicle or player
SendClientMessage(playerid, COLOR_RED, "Rocket collided with a vehicle!");
// Destroy the rocket object
DestroyObject(objectid);
return 1;
}
}
}
return 0;
}