[Include] OnObjectShooted
#1

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;
}
Falta terminar algumas coisas importantes. Como permitir a definicao do tamanho do objeto. Mas basta criar o objeto normalmente e depois registrar ele

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);
Por Bruno da Silva
Reply


Messages In This Thread
OnObjectShooted - by ipsBruno - 03.07.2012, 17:34
Re: OnObjectShooted - by ViictorDaay- - 03.07.2012, 18:12
Re: OnObjectShooted - by FireCat - 03.07.2012, 19:05
Re: OnObjectShooted - by ipsBruno - 03.07.2012, 19:11
Re: OnObjectShooted - by CidadeNovaRP - 03.07.2012, 19:58
Re: OnObjectShooted - by dPlaYer_ - 03.07.2012, 20:34
Re: OnObjectShooted - by leonardo1434 - 03.07.2012, 20:37
Re: OnObjectShooted - by FireCat - 07.07.2012, 22:21
Re: OnObjectShooted - by SlashPT - 08.07.2012, 13:02
Re: OnObjectShooted - by FireCat - 08.07.2012, 13:56

Forum Jump:


Users browsing this thread: 2 Guest(s)