13.10.2011, 01:56
Bom attachei uma arma no meu carro, agora como faзo pra ela atirar?
enum info
{
id,
player
};
new objects[MAX_OBJECTS][info];
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
ShotExplosion(playerid);
return 1;
}
ShotExplosion(playerid)
{
new Float:CamX, Float:CamY, Float:CamZ, Float:VectorX, Float:VectorY,
Float:VectorZ, Float:ObjectX, Float:ObjectY, Float:ObjectZ, Float:Scale = 30.0,
Float:pos[3], slot = GetEmptySlot();
if(slot == -1) return true;
GetPlayerCameraPos(playerid, CamX, CamY, CamZ);
GetPlayerCameraFrontVector(playerid, VectorX, VectorY, VectorZ);
ObjectX = CamX + floatmul(VectorX, Scale);
ObjectY = CamY + floatmul(VectorY, Scale);
ObjectZ = CamZ + floatmul(VectorZ, Scale);
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
objects[slot][id] = CreateObject(18690, pos[0], pos[1], pos[2], 0.0, 0.0, 0.0);
MoveObject(objects[slot][id], ObjectX, ObjectY, ObjectZ, 35.0);
objects[slot][player] = playerid;
return 1;
}
public OnObjectMoved(objectid)
{
new InternalID = GetObjectInternalID(objectid);
if(InternalID != -1)
{
new Float:pos[3];
GetObjectPos(objectid, pos[0], pos[1], pos[2]);
CreateExplosion(pos[0], pos[1], pos[2], 10, 2.0);
DestroyObject(objectid);
}
return true;
}
GetObjectInternalID(objectid)
{
for(new i = 0; i < sizeof objects; ++i) if(objectid == objects[i][id]) return i;
return -1;
}
GetEmptySlot()
{
for(new i = 0; i < sizeof objects; ++i) if(!IsValidObject(objects[i][id])) return i;
return -1;
}