03.07.2012, 17:34
(
Last edited by ipsBruno; 10/07/2012 at 01:48 AM.
)
OnObjectShooted
Como prometido neste topico segue aqui a include que estou desenvolvendo sobre detectar tiros em um determinado objeto[ame]http://www.youtube.com/watch?v=8t3SZwa8YF4[/ame]
Modo de uso. Exemplo
Code:
// --------- new objVAR; // ------ main() { objVAR = CreateObject(2587, 128.7418,-85.9495,1.4297, 0.0, 0.0, 96.0); registerObject(objVAR); } // ------ public OnObjectShooted(playerid, objectid) { if(objVAR == objectid) { SendClientMessage(playerid,-1, "vocк acertouno objeto"); } return true; }
registerObject(objetoid)
Depois cada vez que ele tomar um tiro sera chamado a callback OnObjectShooted com id do jogador e do objeto atirado
-
Codigo da Include
pawn Code:
#define registerObject(%0) \
gObjectsShoot[++gObjectsShooted] = %0
new
gObjectsShooted,
gObjectsShoot[MAX_OBJECTS];
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if((newkeys & KEY_FIRE || oldkeys & KEY_FIRE )) {
static
Float:x,
Float:y,
Float:z,
objectid;
static
Float:xPos,
Float:yPos,
Float:zPos,
Float:distancia,
Float:aPos;
for(new i; i < gObjectsShooted; i++) {
objectid = gObjectsShoot[i];
GetObjectPos(objectid, x, y, z);
if(IsPlayerInRangeOfPoint(playerid, 200.0, x, y, z)) {
GetPlayerPos(playerid, xPos, yPos, zPos);
GetPlayerFacingAngle(playerid, aPos);
distancia = floatsqroot(floatpower(floatabs(xPos-x), 2) + floatpower(floatabs(yPos-y), 2) + floatpower(floatabs(zPos-z), 2));
xPos += (distancia * floatsin(-aPos, degrees)),
yPos += (distancia * floatcos(-aPos, degrees));
distancia = floatsqroot(floatpower(floatabs(xPos-x), 2) + floatpower(floatabs(yPos-y), 2));
if(1.0 > distancia){
CallLocalFunction("OnObjectShooted", "dd", playerid, objectid);
}
}
}
}
return (funcidx("HOOKKeyStateChange") != -1) ? CallLocalFunction("HOOKKeyStateChange","iii",playerid, newkeys, oldkeys) : 0;
}
#if defined _ALS_OnPlayerKeyStateChange
#undef OnPlayerKeyStateChange
#else
#define _ALS_OnPlayerKeyStateChange
#endif
#define OnPlayerKeyStateChange HOOKKeyStateChange
forward OnObjectShooted(playerid, objectid);