[Pedido] Ve se fico bom meu codigo de X1 Please
#1

Ta bom o meu Codigo,da pra Diminuir + do que isso ? se dйr diz ai
pawn Код:
#include <a_samp>
#include <zcmd>

#define DuelColor     0x606060FF

new DualStarted;
new DualJoin;
new Dualers[2];
new pObject[MAX_PLAYERS];

public OnGameModeInit()
{
        Dualers[0] = -1;
        Dualers[1] = -1;
        return 1;
}


public OnPlayerConnect(playerid)
{
        LoadObjects(playerid);
        return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
        DestroyPlayerObject(playerid, pObject[playerid]);
        return 1;
}

public OnPlayerSpawn(playerid)
{
        SetPlayerPos(playerid, 1767.223, -2415.804, 24.710);
        SetPlayerVirtualWorld( playerid, 0 );
        SetPlayerInterior    ( playerid, 0 );
        ResetPlayerWeapons(playerid);
        return 1;
}


CMD:Duel(playerid, params[])
{
        new str[256];
        new pNome[MAX_PLAYERS];
        if(DualStarted == 1) return SendClientMessage( playerid, DuelColor, "*** ( DUEL ) *** Duelo esta Cheio ! " );
        if(playerid == Dualers[0]) return SendClientMessage( playerid, DuelColor, "*** (DUEL ) *** Voce ja esta no Duelo ! " );
        if(playerid == Dualers[1]) return SendClientMessage( playerid, DuelColor, "*** (DUEL ) *** Voce ja esta no Duelo ! " );
        if(DualJoin == 0)
        {
                    GetPlayerName(playerid, pNome[playerid], 40);
                    format(str, sizeof(str),"*** ( DUEL ) **** (%s) Entrou no Duelo ( Weapon One , Weapon Two ) !",pNome[playerid], 40);
                    SendClientMessageToAll(DuelColor, str);
                    SetPlayerPos         ( playerid, -1311.6111, -167.1187, 14.1484 );
                    SetPlayerFacingAngle ( playerid, 268.9476 );
                    SetPlayerVirtualWorld( playerid, 1 );
                    SetCameraBehindPlayer( playerid );
                    SetPlayerInterior    ( playerid, 1 );
                    SetPlayerHealth      ( playerid, 100 );
                    SetPlayerArmour      ( playerid, 100 );
                    //GivePlayerWeapon     ( playerid, 24, 9999); // Weapon One , ID 24 = Desert Eagle , Mude para ID da Arma
                    //GivePlayerWeapon     ( playerid, 34, 9999); // Weapon Two , ID 34 = Sniper , Mude para ID da Arma
                    TogglePlayerControllable( playerid, 0 );
                    Dualers[0] = playerid;
                    DualJoin = 1;
                    return 1;
        }
        if(DualJoin == 1)
        {
                    GetPlayerName(playerid, pNome[playerid], 40);
                    format(str, sizeof(str),"*** ( DUEL ) (%s) Aceitou o Duelo ( Weapon One , Weapon Two ) !",pNome[playerid]);
                    SendClientMessageToAll(DuelColor, str);
                    SetPlayerPos         ( playerid, -1219.0686, -167.9204, 14.1484 );
                    SetPlayerFacingAngle ( playerid, 89.6775 );
                    SetPlayerVirtualWorld( playerid, 1 );
                    SetCameraBehindPlayer( playerid );
                    SetPlayerInterior    ( playerid, 1 );
                    SetPlayerHealth      ( playerid, 100 );
                    SetPlayerArmour      ( playerid, 100 );
                    //GivePlayerWeapon     ( playerid, 24, 9999); // Weapon One , ID 24 = Desert Eagle , Mude para ID da Arma
                    //GivePlayerWeapon     ( playerid, 34, 9999); // Weapon Two , ID 34 = Sniper , Mude para ID da Arma
                    TogglePlayerControllable( playerid, 1 );
                    DualStarted = 1;
                    Dualers[1] = playerid;
        }
        return 1;
}

CMD:Leave(playerid, params[])
{
        if(DualStarted == 1) return SendClientMessage( playerid, DuelColor, "*** ( DUEL ) *** Voce nao pode sair do Duelo ! " );
        if(playerid == Dualers[0])
        {
            OnPlayerSpawn(playerid);
            TogglePlayerControllable( playerid, 1 );
            DualJoin = -0;
            DualStarted = 0;
            Dualers[0] = -1;
            Dualers[1] = -1;
            if(DualStarted == 0) return SendClientMessage( playerid, DuelColor, "*** ( DUEL ) *** Abriu Vaga no Duelo " );
            return 1;
        }
        if(playerid == Dualers[1])
        {
            OnPlayerSpawn(playerid);
            TogglePlayerControllable( playerid, 1 );
            DualJoin = -1;
            DualStarted = 0;
            Dualers[0] = -1;
            Dualers[1] = -1;
            if(DualStarted == 0) return SendClientMessage( playerid, DuelColor, "*** ( DUEL ) *** Abriu Vaga no Duelo " );
            return 1;
        }
        return 1;
}

CMD:Kill(playerid, params[])
{
        if(DualStarted == 1) return SendClientMessage( playerid, DuelColor, "*** ( DUEL )  Voce nao pode se Suicidar ! ***" );
        if(playerid == Dualers[0])
        {
            SetPlayerHealth      ( playerid, 0 );
            SetPlayerArmour      ( playerid, 0 );
            DualJoin = -0;
        }
        if(playerid == Dualers[1])
        {
            SetPlayerHealth      ( playerid, 0 );
            SetPlayerArmour      ( playerid, 0 );
            DualJoin = -1;
        }
        return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    SendDeathMessage(playerid,killerid,reason);
    new str[256];
    new Nome[MAX_PLAYERS];
    new Name[MAX_PLAYERS];
    if(playerid == Dualers[0])
    {
        OnPlayerSpawn(playerid);
        OnPlayerSpawn(killerid);
        GetPlayerName(killerid, Name[killerid], 40);
        GetPlayerName(playerid, Nome[playerid], 40);
        format(str, sizeof(str),"*** ( DUEL ) *** (%s) Ganhou no Duelo contra (%s).",Name[killerid], Nome[killerid]);
        SendClientMessageToAll(DuelColor, str);
        DualJoin = -0;
        DualJoin = -1;
        Dualers[0] = -1;
        Dualers[1] = -1;
    }
    if(playerid == Dualers[1])
    {
        OnPlayerSpawn(playerid);
        OnPlayerSpawn(killerid);
        GetPlayerName(killerid, Name[killerid], 40);
        GetPlayerName(playerid, Nome[playerid], 40);
        format(str, sizeof(str),"*** ( DUEL ) *** (%s) Ganhou no Duelo contra (%s).",Name[killerid], Nome[killerid]);
        SendClientMessageToAll(DuelColor, str);
        DualJoin = -0;
        DualJoin = -1;
        Dualers[0] = -1;
        Dualers[1] = -1;
    }
    return 1;
}


LoadObjects(playerid)
{
    pObject[playerid] = CreatePlayerObject( playerid, 7474, -1287.87, -166.27, 13.097, 0.00, 0.00,  45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7906, -1318.67, -172.79, 16.477, 0.00, 0.00, 135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7907, -1306.75, -184.64, 16.477, 0.00, 0.00, 135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7910, -1294.81, -196.55, 16.477, 0.00, 0.00, 135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7909, -1282.99, -208.35, 16.477, 0.00, 0.00, 135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7912, -1271.22, -220.14, 16.477, 0.00, 0.00, 135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7913, -1259.88, -219.55, 16.477, 0.00, 0.00,-135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7914, -1248.01, -207.68, 16.477, 0.00, 0.00,-135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7915, -1236.18, -195.85, 16.477, 0.00, 0.00,-135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7909, -1224.30, -183.95, 16.477, 0.00, 0.00,-135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7907, -1214.32, -174.07, 16.477, 0.00, 0.00,-135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7906, -1214.95, -162.24, 16.477, 0.00, 0.00, -45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7908, -1226.91, -150.35, 16.477, 0.00, 0.00, -45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7910, -1238.77, -138.40, 16.477, 0.00, 0.00, -45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7912, -1250.54, -126.61, 16.477, 0.00, 0.00, -45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7913, -1262.41, -114.69, 16.477, 0.00, 0.00, -45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7911, -1273.66, -115.70, 16.477, 0.00, 0.00,  45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7910, -1285.49, -127.64, 16.477, 0.00, 0.00,  45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7907, -1297.23, -139.50, 16.477, 0.00, 0.00,  45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7906, -1309.20, -151.42, 16.477, 0.00, 0.00,  45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7910, -1320.86, -163.34, 16.477, 0.00, 0.00,  45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 9188, -1318.67, -172.79, 23.125, 0.00, 0.00, 135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 9191, -1306.75, -184.64, 23.125, 0.00, 0.00, 135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 9190, -1294.81, -196.55, 23.125, 0.00, 0.00, 135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7914, -1282.99, -208.35, 23.125, 0.00, 0.00, 135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7913, -1271.22, -220.14, 23.125, 0.00, 0.00, 135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7907, -1259.88, -219.55, 23.125, 0.00, 0.00,-135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7906, -1248.01, -207.68, 23.125, 0.00, 0.00,-135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7913, -1236.18, -195.85, 23.125, 0.00, 0.00,-135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7915, -1224.30, -183.95, 23.125, 0.00, 0.00,-135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7914, -1214.32, -174.07, 23.125, 0.00, 0.00,-135.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7913, -1214.95, -162.24, 23.125, 0.00, 0.00, -45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7912, -1226.91, -150.35, 23.125, 0.00, 0.00, -45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7914, -1238.77, -138.40, 23.125, 0.00, 0.00, -45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7915, -1250.54, -126.61, 23.125, 0.00, 0.00, -45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7913, -1262.41, -114.69, 23.125, 0.00, 0.00, -45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7911, -1273.66, -115.70, 23.125, 0.00, 0.00,  45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7912, -1285.49, -127.64, 23.125, 0.00, 0.00,  45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7909, -1297.23, -139.50, 23.125, 0.00, 0.00,  45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7915, -1309.20, -151.42, 23.125, 0.00, 0.00,  45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 7910, -1320.86, -163.34, 23.125, 0.00, 0.00,  45.0 );
    pObject[playerid] = CreatePlayerObject( playerid, 8553, -1229.78, -147.04, 26.534, 90.2, -4.2, -41.08);
    pObject[playerid] = CreatePlayerObject( playerid, 8553, -1246.84, -129.77, 26.534, 90.2, -4.2, -41.08);
    pObject[playerid] = CreatePlayerObject( playerid, 8553, -1288.95, -130.23, 26.641, 90.2, -4.2,  48.92);
    pObject[playerid] = CreatePlayerObject( playerid, 8553, -1306.23, -147.28, 26.641, 90.2, -4.2,  48.92);
    pObject[playerid] = CreatePlayerObject( playerid, 8553, -1304.76, -187.97, 26.563, 90.2, -4.2, 138.92);
    pObject[playerid] = CreatePlayerObject( playerid, 8553, -1287.07, -205.76, 26.533, 90.2, -4.2, 138.92);
    pObject[playerid] = CreatePlayerObject( playerid, 8553, -1229.02, -189.27, 26.534, 90.2, -4.2,-130.22);
    pObject[playerid] = CreatePlayerObject( playerid, 8553, -1245.11, -205.65, 26.534, 90.2, -4.2,-130.22);
}
Reply
#2

Eu vejo nesse cуdigo, muita funзгo com parвmetros repetidos, ou seja, muita coisa que faz a mesma coisa repetida, isso vai contra o modelo de boa programaзгo chama DRY (Don't Repeat Yourself - Nгo se repita).

Cуdigos repetidos em vбrias partes, como

Код:
SetPlayerInterior    ( playerid, 1 );
SetPlayerHealth      ( playerid, 100 );
SetPlayerArmour      ( playerid, 100 );
Revise isso. Vocк pode criar funзхes para fazer uma mesma tarefa.
Reply
#3

Quote:
Originally Posted by Joao Pedro
Посмотреть сообщение
Eu vejo nesse cуdigo, muita funзгo com parвmetros repetidos, ou seja, muita coisa que faz a mesma coisa repetida, isso vai contra o modelo de boa programaзгo chama DRY (Don't Repeat Yourself - Nгo se repita).

Cуdigos repetidos em vбrias partes, como

Код:
SetPlayerInterior    ( playerid, 1 );
SetPlayerHealth      ( playerid, 100 );
SetPlayerArmour      ( playerid, 100 );
Revise isso. Vocк pode criar funзхes para fazer uma mesma tarefa.
Realmente, vocк poderia criar uma nativa "stock" para poder executar esta tarefa quando preciso! (:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)