[Duda]Problema Con Sistema De Inventario
#1

Buenas tengo un pequeсo problema con un sistema de inventario que estoy editando el tema es que todo anda bien al momento de guardar/sacar un item,pero el problema se genera que guarda tu archivo en una carpera llamada inventario pero tu pones /inventario y luego /guardararma 1 guardas tu arma,y los otros usuarios pueden ver tu arma e retirarla,pero luego tu tratas de retirar esa arma y se bugea y tampoco puedes volver a meter un arma en ese slot.

Aca les dejo los codigos pawn:

Код:
#include a_samp
#include zcmd
#include sscanf2
#include dof2

enum pInfo
{
        pArma01,
        pArma02,
        pArma03,
        pArma04,
        pBalas01,
        pBalas02,
        pBalas03,
        pBalas04
}
new status[MAX_PLAYERS][pInfo];

public OnFilterScriptExit(){DOF2_Exit();}
public OnPlayerConnect(playerid){CarregarBconta(playerid);return 1;}
public OnPlayerDisconnect(playerid){SalvarContas(playerid);return 1;}

CMD:inventario(playerid)
{
        new Arma1[128];
        new Arma2[128];
        new Arma3[128];
        new Arma4[128];
        new armaBala[4];
        switch(status[pInfo][pArma01])
        {
                case 3: Arma1 = "Porra";case 2: Arma1 = "Palo De Golf";case 4: Arma1 = "Cuchillo";case 5: Arma1 = "Bate De Beisbol";
                case 6: Arma1 = "Pala";case 9: Arma1 = "Motosierra";case 7: Arma1 = "Palo De Billar";case 8: Arma1 = "Katana";
                case 14: Arma1 = "Flores";case 10: Arma1 = "Consolador Morado";case 16: Arma1 = "Granadas";case 17: Arma1 = "Granadas De Humo";
                case 18: Arma1 = "Molotovs";case 11: Arma1 = "Consolador Pequeсo";case 22: Arma1 = "9MM";case 23: Arma1 = "9MM Silenciada";
                case 24: Arma1 = "Deser-Eagle";case 12: Arma1 = "Consolador Mediano";case 25: Arma1 = "Escopeta";case 29: Arma1 = "MP5";
                case 30: Arma1 = "AK47";case 13: Arma1 = "Consolador Pequeсo Negro";case 31: Arma1 = "M4";case 33: Arma1 = "Rifle";
                case 34: Arma1 = "Sniper";case 15: Arma1 = "Fierro";case 37: Arma1 = "Lanza Llamas";case 41: Arma1 = "Spray";
                case 42: Arma1 = "Extintor";case 26: Arma1 = "Escopeta Recortada";case 43: Arma1 = "Camara";case 46: Arma1 = "Paracaidas";
                case 27: Arma1 = "Escopeta De Combate";case 28: Arma1 = "Uzi";case 32: Arma1 = "Tec-9";case 35: Arma1 = "RPG-7";case 36: Arma1 = "Heat Seaker";
                case 38: Arma1 = "Mini-Gun";case 39: Arma1 = "Explosivos";case 40: Arma1 = "Detonador";
        }
        switch(status[pInfo][pArma02])
        {
                case 3: Arma2 = "Porra";case 2: Arma2 = "Palo De Golf";case 4: Arma2 = "Cuchillo";case 5: Arma2 = "Bate De Beisbol";
                case 6: Arma2 = "Pala";case 9: Arma2 = "Motosierra";case 7: Arma2 = "Palo De Billar";case 8: Arma2 = "Katana";
                case 14: Arma2 = "Flores";case 10: Arma2 = "Consolador Morado";case 16: Arma2 = "Granadas";case 17: Arma2 = "Granadas De Humo";
                case 18: Arma2 = "Molotovs";case 11: Arma2 = "Consolador Pequeсo";case 22: Arma2 = "9MM";case 23: Arma2 = "9MM Silenciada";
                case 24: Arma2 = "Deser-Eagle";case 12: Arma2 = "Consolador Mediano";case 25: Arma2 = "Escopeta";case 29: Arma2 = "MP5";
                case 30: Arma2 = "AK47";case 13: Arma2 = "Consolador Pequeсo Negro";case 31: Arma2 = "M4";case 33: Arma2 = "Rifle";
                case 34: Arma2 = "Sniper";case 15: Arma2 = "Fierro";case 37: Arma2 = "Lanza Llamas";case 41: Arma2 = "Spray";
                case 42: Arma2 = "Extintor";case 26: Arma2 = "Escopeta Recortada";case 43: Arma2 = "Camara";case 46: Arma2 = "Paracaidas";
                case 27: Arma2 = "Escopeta De Combate";case 28: Arma2 = "Uzi";case 32: Arma2 = "Tec-9";case 35: Arma2 = "RPG-7";case 36: Arma2 = "Heat Seaker";
                case 38: Arma2 = "Mini-Gun";case 39: Arma2 = "Explosivos";case 40: Arma2 = "Detonador";
        }
        switch(status[pInfo][pArma03])
        {
                case 3: Arma3 = "Porra";case 2: Arma3 = "Palo De Golf";case 4: Arma3 = "Cuchillo";case 5: Arma3 = "Bate De Beisbol";
                case 6: Arma3 = "Pala";case 9: Arma3 = "Motosierra";case 7: Arma3 = "Palo De Billar";case 8: Arma3 = "Katana";
                case 14: Arma3 = "Flores";case 10: Arma3 = "Consolador Morado";case 16: Arma3 = "Granadas";case 17: Arma3 = "Granadas De Humo";
                case 18: Arma3 = "Molotovs";case 11: Arma3 = "Consolador Pequeсo";case 22: Arma3 = "9MM";case 23: Arma3 = "9MM Silenciada";
                case 24: Arma3 = "Deser-Eagle";case 12: Arma3 = "Consolador Mediano";case 25: Arma3 = "Escopeta";case 29: Arma3 = "MP5";
                case 30: Arma3 = "AK47";case 13: Arma3 = "Consolador Pequeсo Negro";case 31: Arma3 = "M4";case 33: Arma3 = "Rifle";
                case 34: Arma3 = "Sniper";case 15: Arma3 = "Fierro";case 37: Arma3 = "Lanza Llamas";case 41: Arma3 = "Spray";
                case 42: Arma3 = "Extintor";case 26: Arma3 = "Escopeta Recortada";case 43: Arma3 = "Camara";case 46: Arma3 = "Paracaidas";
                case 27: Arma3 = "Escopeta De Combate";case 28: Arma3 = "Uzi";case 32: Arma3 = "Tec-9";case 35: Arma3 = "RPG-7";case 36: Arma3 = "Heat Seaker";
                case 38: Arma3 = "Mini-Gun";case 39: Arma3 = "Explosivos";case 40: Arma3 = "Detonador";
        }
        switch(status[pInfo][pArma04])
        {
                case 3: Arma4 = "Porra";case 2: Arma4 = "Palo De Golf";case 4: Arma4 = "Cuchillo";case 5: Arma4 = "Bate De Beisbol";
                case 6: Arma4 = "Pala";case 9: Arma4 = "Motosierra";case 7: Arma4 = "Palo De Billar";case 8: Arma4 = "Katana";
                case 14: Arma4 = "Flores";case 10: Arma4 = "Consolador Morado";case 16: Arma4 = "Granadas";case 17: Arma4 = "Granadas De Humo";
                case 18: Arma4 = "Molotovs";case 11: Arma4 = "Consolador Pequeсo";case 22: Arma4 = "9MM";case 23: Arma4 = "9MM Silenciada";
                case 24: Arma4 = "Deser-Eagle";case 12: Arma4 = "Consolador Mediano";case 25: Arma4 = "Escopeta";case 29: Arma4 = "MP5";
                case 30: Arma4 = "AK47";case 13: Arma4 = "Consolador Pequeсo Negro";case 31: Arma4 = "M4";case 33: Arma4 = "Rifle";
                case 34: Arma4 = "Sniper";case 15: Arma4 = "Fierro";case 37: Arma4 = "Lanza LLamas";case 41: Arma4 = "spray";
                case 42: Arma4 = "Extintor";case 26: Arma4 = "Escopeta Recortada";case 43: Arma4 = "Camara";case 46: Arma4 = "Paracaidas";
                case 27: Arma4 = "Escopeta De Combate";case 28: Arma4 = "Uzi";case 32: Arma4 = "Tec-9";case 35: Arma4 = "RPG-7";case 36: Arma4 = "Heat Seaker";
                case 38: Arma4 = "Mini-Gun";case 39: Arma4 = "Explosivos";case 40: Arma4 = "Detonador";
        }
        armaBala[0] = status[pInfo][pBalas01];
        armaBala[1] = status[pInfo][pBalas02];
        armaBala[2] = status[pInfo][pBalas03];
        armaBala[3] = status[pInfo][pBalas04];
        new _string[128];
        format(_string, 128, "[INV]{00FF00} SLOT 1 - Arma: {FF0000}%s {FFFFFF}|{00FF00} Municiуn: {FF0000}%d",Arma1, armaBala[0]);
        SendClientMessage(playerid, -1, _string);
        format(_string, 128, "[INV]{00FF00} SLOT 2 - Arma: {FF0000}%s {FFFFFF}|{00FF00} Municiуn: {FF0000}%d",Arma2, armaBala[1]);
        SendClientMessage(playerid, -1, _string);
        format(_string, 128, "[INV]{00FF00} SLOT 3 - Arma: {FF0000}%s {FFFFFF}|{00FF00} Municiуn: {FF0000}%d",Arma3, armaBala[2]);
        SendClientMessage(playerid, -1, _string);
        format(_string, 128, "[INV]{00FF00} SLOT 4 - Arma: {FF0000}%s {FFFFFF}|{00FF00} Municiуn: {FF0000}%d",Arma4, armaBala[3]);
        SendClientMessage(playerid, -1, _string);
        return true;
}

CMD:guardararma(playerid, params[])
{
        new _string[128];
        new SLOT;
        if(sscanf(params,"i",SLOT)) return SendClientMessage(playerid, -1, "{FF0000}[INV-Modo] {00FF00}/guardararma {FF0000}[SLOT]");
        {
            new
                pMinhaArma,
                pMinhasBalas;

            if(!GetPlayerWeapon(playerid)) return SendClientMessage(playerid, -1, "{FF0000}No tienes un arma !");
            pMinhaArma = GetPlayerWeapon(playerid);
            pMinhasBalas = GetPlayerAmmo(playerid);
            switch(SLOT)
                {
                case 1:
                        {
                    if(status[pInfo][pArma01] > 0) return SendClientMessage(playerid, -1, "{FF0000}Ese slot esta ocupado.");
                    status[pInfo][pArma01] = pMinhaArma;
                    status[pInfo][pBalas01] = pMinhasBalas;

                    format(_string, 128, "{00FF00}Has colocado un arma en el slot 1.");
                    SendClientMessage(playerid, -1, _string);
                    RemovePlayerWeapon(playerid, GetPlayerWeapon(playerid));
                    return 1;
                }
                case 2:
                        {
                    if(status[pInfo][pArma02] > 0) return SendClientMessage(playerid, -1, "{FF0000}Ese slot esta ocupado.");
                    status[pInfo][pArma02] = pMinhaArma;
                    status[pInfo][pBalas02] = pMinhasBalas;

                    format(_string, 128, "{00FF00}Has colocado un arma en el slot 2.");
                    SendClientMessage(playerid, -1, _string);
                    RemovePlayerWeapon(playerid, GetPlayerWeapon(playerid));
                    return 1;

                }
                case 3:
                        {
                    if(status[pInfo][pArma03] > 0) return SendClientMessage(playerid, -1, "{FF0000}Ese slot esta ocupado.");
                    status[pInfo][pArma03] = pMinhaArma;
                    status[pInfo][pBalas03] = pMinhasBalas;

                    format(_string, 128, "{00FF00}Has colocado un arma en el slot 3.");
                    SendClientMessage(playerid, -1, _string);
                    RemovePlayerWeapon(playerid, GetPlayerWeapon(playerid));
                    return 1;

                }
                case 4:
                        {
                    if(status[pInfo][pArma04] > 0) return SendClientMessage(playerid, -1, "{FF0000}Ese slot esta ocupado.");
                    status[pInfo][pArma04] = pMinhaArma;
                    status[pInfo][pBalas04] = pMinhasBalas;

                    format(_string, 128, "{00FF00}Has colocado un arma en el slot 4.");
                    SendClientMessage(playerid, -1, _string);
                    RemovePlayerWeapon(playerid, GetPlayerWeapon(playerid));
                    return 1;
                }
                default: SendClientMessage(playerid, -1, "Slots [1-4].");
            }
        }
    return 1;
}

CMD:retirararma(playerid, params[])
{
        new _string[128];
        new SLOT;
        if(sscanf(params,"i",SLOT)) return SendClientMessage(playerid, -1, "{FF0000}[INV-Modo] {00FF00}/retirararma {FF0000}[SLOT]");
        {
            switch(SLOT)
                {
                case 1:
                        {
                    if(status[pInfo][pArma01] == 0) return SendClientMessage(playerid, -1, "{FF0000}El slot esta vacio.");
                                GivePlayerWeapon(playerid, status[pInfo][pArma01], status[pInfo][pBalas01]);
                    status[pInfo][pArma01] = 0;
                    status[pInfo][pBalas01] = 0;
                format(_string, 128, "{00FF00}Has retirado un arma del slot 1!");
                SendClientMessage(playerid, -1, _string);
                    return 1;
                }
                case 2:
                        {
                    if(status[pInfo][pArma01] == 0) return SendClientMessage(playerid, -1, "{FF0000}El slot esta vacio.");
                                GivePlayerWeapon(playerid, status[pInfo][pArma02], status[pInfo][pBalas02]);
                    status[pInfo][pArma02] = 0;
                    status[pInfo][pBalas02] = 0;
                format(_string, 128, "{00FF00}Has retirado un arma del slot 2!");
                SendClientMessage(playerid, -1, _string);
                    return 1;

                }
                case 3:
                        {
                    if(status[pInfo][pArma03] == 0) return SendClientMessage(playerid, -1, "{FF0000}El slot esta vacio.");
                                GivePlayerWeapon(playerid, status[pInfo][pArma03], status[pInfo][pBalas03]);
                    status[pInfo][pArma03] = 0;
                    status[pInfo][pBalas03] = 0;
                format(_string, 128, "{00FF00}Has retirado un arma del slot 3!");
                SendClientMessage(playerid, -1, _string);
                    return 1;

                }
                case 4:
                        {
                    if(status[pInfo][pArma04] == 0) return SendClientMessage(playerid, -1, "{FF0000}El slot esta vacio.");
                                GivePlayerWeapon(playerid, status[pInfo][pArma04], status[pInfo][pBalas04]);
                    status[pInfo][pArma04] = 0;
                    status[pInfo][pBalas04] = 0;
                format(_string, 128, "{00FF00}Has retirado un arma del slot 4!");
                SendClientMessage(playerid, -1, _string);
                    return 1;
                }
                default: SendClientMessage(playerid, -1, "Slots [1-4].");
            }
        }
    return 1;
}


forward RemovePlayerWeapon(playerid, weaponid);
public RemovePlayerWeapon(playerid, weaponid)
{
        if(!IsPlayerConnected(playerid) || weaponid < 0 || weaponid > 50) return;
        new saveweapon[13], saveammo[13];
        for(new slot = 0; slot < 13; slot++)
        GetPlayerWeaponData(playerid, slot, saveweapon[slot], saveammo[slot]);
        ResetPlayerWeapons(playerid);
        for(new slot; slot < 13; slot++)
        {
                if(saveweapon[slot] == weaponid || saveammo[slot] == 0)
                continue;
                GivePlayerWeapon(playerid, saveweapon[slot], saveammo[slot]);
        }
        GivePlayerWeapon(playerid, 0, 1);
}

stock CarregarBconta(playerid)
{
        status[pInfo][pArma01] = DOF2_GetInt(PlayersB(playerid), "pArma01");
        status[pInfo][pArma02] = DOF2_GetInt(PlayersB(playerid), "pArma02");
        status[pInfo][pArma03] = DOF2_GetInt(PlayersB(playerid), "pArma03");
        status[pInfo][pArma04] = DOF2_GetInt(PlayersB(playerid), "pArma04");
        status[pInfo][pBalas01] = DOF2_GetInt(PlayersB(playerid), "pBalas01");
        status[pInfo][pBalas02] = DOF2_GetInt(PlayersB(playerid), "pBalas02");
        status[pInfo][pBalas03] = DOF2_GetInt(PlayersB(playerid), "pBalas03");
        status[pInfo][pBalas04] = DOF2_GetInt(PlayersB(playerid), "pBalas04");
        return 1;
}

stock PlayersB(playerid)
{
    new arquivo[40], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, 32);
    format(arquivo, 40, "Inventario/%s.ini", name);
    return arquivo;
}

stock SalvarContas(playerid)
{
    if(!DOF2_FileExists(PlayersB(playerid))) DOF2_CreateFile(PlayersB(playerid));
    else
    {
        DOF2_SetInt(PlayersB(playerid), "pArma01", status[pInfo][pArma01]);
        DOF2_SetInt(PlayersB(playerid), "pArma02", status[pInfo][pArma02]);
        DOF2_SetInt(PlayersB(playerid), "pArma03", status[pInfo][pArma03]);
        DOF2_SetInt(PlayersB(playerid), "pArma04", status[pInfo][pArma04]);
        DOF2_SetInt(PlayersB(playerid), "pBalas01", status[pInfo][pBalas01]);
        DOF2_SetInt(PlayersB(playerid), "pBalas02", status[pInfo][pBalas02]);
        DOF2_SetInt(PlayersB(playerid), "pBalas03", status[pInfo][pBalas03]);
        DOF2_SetInt(PlayersB(playerid), "pBalas04", status[pInfo][pBalas04]);
        DOF2_SaveFile();
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)