SA-MP Forums Archive
[Ajuda] Otimizaзгo desde cуdigo - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+---- Thread: [Ajuda] Otimizaзгo desde cуdigo (/showthread.php?tid=398047)



Otimizaзгo desde cуdigo - Mr_Taxi - 08.12.2012

pawn Code:
public OnPlayerUpdate(playerid)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(IsPlayerInArea(playerid, 1008,1632,1212,1806))
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            armasAtivadas = false;
        }
    }
    else
    {
        armasAtivadas = true;
        if(armasAtivadas == true)
        {
            if(GetVehicleModel(vehicleid) == 415)
            {

                Bazuca1 = CreateObject(360, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                Bazuca2 = CreateObject(360, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                Minigun1 = CreateObject(362, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                Minigun2 = CreateObject(362, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);

                AttachObjectToVehicle(Bazuca1, vehicleid, 1026.5,1795.4,10.8,0.0,0.0,0.0);
                AttachObjectToVehicle(Bazuca2, vehicleid, 0.2, -0.2, 0.7, 0.0, 0.0, 90.0);
                AttachObjectToVehicle(Minigun1, vehicleid, 0.0, 0.0, 0.7, 0.0, 0.0, 90.0);
                AttachObjectToVehicle(Minigun2, vehicleid, -0.2, -0.2, 0.7, 0.0, 0.0, 90.0);
                return 1;
            }
        }
    }
    return true;
}
Sу que a OnPlayerUpdate й chamada vбrias vezes por segundo nй ? E isso simplesmente laga o servidor deixando injogavel...
O que eu queria saber era o seguinte: Qual a public eu posso usar pra deixar isso atualizando, seilб, 1 vez a cada 2 ou 3 segundos ? qual a public ?

fllws (:


Re: Otimizaзгo desde cуdigo - [JD]BlackFire - 08.12.2012

usa OnPlayerStateChange , somente atualiza quando o jogador entrar no veнculo, ou use timers.


Re: Otimizaзгo desde cуdigo - zSuYaNw - 08.12.2012

Tente assim:
pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER){

        static vehicleid;
        vehicleid = GetPlayerVehicleID(playerid);
       
       
        if(IsPlayerInArea(playerid, 1008,1632,1212,1806)){
            if(IsPlayerInAnyVehicle(playerid)){
                armasAtivadas = false;
            }
        }
        else
        {
            armasAtivadas = true;
            if(armasAtivadas == true)
            {
                if(GetVehicleModel(vehicleid) == 415)
                {

                    Bazuca1 = CreateObject(360, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                    Bazuca2 = CreateObject(360, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                    Minigun1 = CreateObject(362, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                    Minigun2 = CreateObject(362, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);

                    AttachObjectToVehicle(Bazuca1, vehicleid, 1026.5,1795.4,10.8,0.0,0.0,0.0);
                    AttachObjectToVehicle(Bazuca2, vehicleid, 0.2, -0.2, 0.7, 0.0, 0.0, 90.0);
                    AttachObjectToVehicle(Minigun1, vehicleid, 0.0, 0.0, 0.7, 0.0, 0.0, 90.0);
                    AttachObjectToVehicle(Minigun2, vehicleid, -0.2, -0.2, 0.7, 0.0, 0.0, 90.0);
                    return 1;
                }
            }
        }
    }
    return true;
}