[FilterScript] Base sistema de Administraзгo
#1

Bom fiz uma base de sistema de administraзгo quando era bem iniciante com pawn, postei ano passado na pastebin, como criei minha conta nгo faz muito tempo resolvi compartilhar com vocкs, mais para frente vou atualiza-lo e otimizar mais ele ele conta com 16 comandos й uma base simples, conta tambйm com salvamento do sistema tem que criar a pasta Admins, lembrando que fiz quando iniciei com pawn, mais para frente vou otimizar ele e deixa-lo mais bonito e elegante, os comandos podem ser visualizados pelo /comandosadmin ele й feito em zcmd + sscanf e conta com strtok tambйm.

Pastebin


Crйditos : Fбbio Stralioti
Criador do ZCMD > Zeex
Criador SSCANF > ******
Reply
#2

A usar sscanf e depois aparassem comados assim:

pawn Код:
CMD:pinfo(playerid, params[])
{
 if(pAdmin[playerid][Level] >= 1) return SendClientMessage(playerid, -1, "Vocк nгo й um Administrador");
 new tmp[256], idx, string[128];
 tmp = strtok(params, idx);
 
        new id;
        if(!IsNumeric(tmp))
                id = ReturnPlayerID(tmp);
        else
                id = strval(tmp);
 
        if(!strlen(tmp))
            return SendClientMessage(playerid, -1, "Uso: /pinfo [id]");
 
        if(!IsPlayerConnected(id))
                return SendClientMessage(playerid, -1, "ID invбlido!");
 
        format(string, sizeof(string), "|__________ Informaзхes de %s __________|", GetName(id));
        SendClientMessage(playerid, -1,string);
 
        new ip[24];
        new Float:health;
        new Float:armour;
        new ammo = GetPlayerAmmo(id);
        new ping = GetPlayerPing(id);
        new money = GetPlayerMoney(id);
        new level = GetPlayerScore(id);
 
    GetPlayerHealth(id,health);
        GetPlayerArmour(id,armour);
        GetPlayerIp(id, ip, sizeof ip);
 
        format(string, sizeof(string), "IP: %s", ip);
        SendClientMessage(playerid, -1,string);
        format(string, sizeof(string), "Level: %d", level);
        SendClientMessage(playerid, -1,string);
        format(string, sizeof(string), "Vida: %.1f", health);
        SendClientMessage(playerid, -1,string);
        format(string, sizeof(string), "Colete: %.1f", armour);
        SendClientMessage(playerid, -1,string);
        format(string, sizeof(string), "Muniзгo da arma na mгo: %d", ammo);
        SendClientMessage(playerid, -1,string);
        format(string, sizeof(string), "Ping: %d", ping);
        SendClientMessage(playerid, -1,string);
        format(string, sizeof(string), "Dinheiro: %d", money);
        SendClientMessage(playerid, -1,string);
        return 1;
}
prox atualizacao, nao precisa:

pawn Код:
strtok(const string[], &index)
{
        new length = strlen(string);
        while ((index < length) && (string[index] <= ' '))
        {
                index++;
        }
 
        new offset = index;
        new result[20];
        while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
        {
                result[index - offset] = string[index];
                index++;
        }
        result[index - offset] = EOS;
        return result;
}
 
stock strtok2(const string[], &index)
{
 new lenGT = strlen(string);
 while ((index < lenGT) && (string[index] <= ' '))
{
 index++;
}
 new offset = index;
 new result[70];
 while ((index < lenGT) && ((index - offset) < (sizeof(result) - 1)))
{
 result[index - offset] = string[index];
 index++;
}
 result[index - offset] = EOS;
 return result;
}
 
stock ReturnPlayerID(PlayerName[])
{
                new found=0, id;
                for(new i=0; i <= MAX_PLAYERS; i++)
                {
                        if(IsPlayerConnected(i))
                        {
                                new foundname[MAX_PLAYER_NAME+1];
                                GetPlayerName(i, foundname, MAX_PLAYER_NAME+1);
                                new namelen = strlen(foundname);
                                new bool:searched=false;
                        for(new pos=0; pos <= namelen; pos++)
                                {
                                        if(searched != true)
                                        {
                                                if(strfind(foundname,PlayerName,true) == pos)
                                                {
                                        found++;
                                                        id = i;
                                                }
                                        }
                                }
                        }
                }
 
                if(found == 1)
                        return id;
                else
                        return INVALID_PLAYER_ID;
}
estude os especificadores da sscanf e entendera o que quero dizer.

pra que isto:

pawn Код:
stock GetLevelAdmin(levelid)
{
    new str[50];
    if(levelid == 1)
    {
        str = "1";
    }
    else if (levelid == 2)
    {
        str = "2";
    }
    else if (levelid == 3)
    {
        str = "3";
    }
    else if (levelid == 4)
    {
        str = "4";
    }
    else if (levelid == 5)
    {
        str = "5";
    }
    return str;
}
??

pawn Код:
CMD:comandosadmin(playerid)
{
 new dialogrande[1024];
 format(dialogrande, sizeof(dialogrande),"%s%s",dialogrande,"/asay, /jetpack, /tr, /ir, /vidat, /dararma, /kick, /pinfo, /setadmin, /ban, /vida, /congelar, /descongelar, /olhar, /olharoff\n");
 return 1;
}
aconselho vivamente a comecar a otimizar seus scripts.
Reply
#3

Quote:
Originally Posted by PT
Посмотреть сообщение
A usar sscanf e depois aparassem comados assim:

pawn Код:
CMD:pinfo(playerid, params[])
{
 if(pAdmin[playerid][Level] >= 1) return SendClientMessage(playerid, -1, "Vocк nгo й um Administrador");
 new tmp[256], idx, string[128];
 tmp = strtok(params, idx);
 
        new id;
        if(!IsNumeric(tmp))
                id = ReturnPlayerID(tmp);
        else
                id = strval(tmp);
 
        if(!strlen(tmp))
            return SendClientMessage(playerid, -1, "Uso: /pinfo [id]");
 
        if(!IsPlayerConnected(id))
                return SendClientMessage(playerid, -1, "ID invбlido!");
 
        format(string, sizeof(string), "|__________ Informaзхes de %s __________|", GetName(id));
        SendClientMessage(playerid, -1,string);
 
        new ip[24];
        new Float:health;
        new Float:armour;
        new ammo = GetPlayerAmmo(id);
        new ping = GetPlayerPing(id);
        new money = GetPlayerMoney(id);
        new level = GetPlayerScore(id);
 
    GetPlayerHealth(id,health);
        GetPlayerArmour(id,armour);
        GetPlayerIp(id, ip, sizeof ip);
 
        format(string, sizeof(string), "IP: %s", ip);
        SendClientMessage(playerid, -1,string);
        format(string, sizeof(string), "Level: %d", level);
        SendClientMessage(playerid, -1,string);
        format(string, sizeof(string), "Vida: %.1f", health);
        SendClientMessage(playerid, -1,string);
        format(string, sizeof(string), "Colete: %.1f", armour);
        SendClientMessage(playerid, -1,string);
        format(string, sizeof(string), "Muniзгo da arma na mгo: %d", ammo);
        SendClientMessage(playerid, -1,string);
        format(string, sizeof(string), "Ping: %d", ping);
        SendClientMessage(playerid, -1,string);
        format(string, sizeof(string), "Dinheiro: %d", money);
        SendClientMessage(playerid, -1,string);
        return 1;
}
prox atualizacao, nao precisa:

pawn Код:
strtok(const string[], &index)
{
        new length = strlen(string);
        while ((index < length) && (string[index] <= ' '))
        {
                index++;
        }
 
        new offset = index;
        new result[20];
        while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
        {
                result[index - offset] = string[index];
                index++;
        }
        result[index - offset] = EOS;
        return result;
}
 
stock strtok2(const string[], &index)
{
 new lenGT = strlen(string);
 while ((index < lenGT) && (string[index] <= ' '))
{
 index++;
}
 new offset = index;
 new result[70];
 while ((index < lenGT) && ((index - offset) < (sizeof(result) - 1)))
{
 result[index - offset] = string[index];
 index++;
}
 result[index - offset] = EOS;
 return result;
}
 
stock ReturnPlayerID(PlayerName[])
{
                new found=0, id;
                for(new i=0; i <= MAX_PLAYERS; i++)
                {
                        if(IsPlayerConnected(i))
                        {
                                new foundname[MAX_PLAYER_NAME+1];
                                GetPlayerName(i, foundname, MAX_PLAYER_NAME+1);
                                new namelen = strlen(foundname);
                                new bool:searched=false;
                        for(new pos=0; pos <= namelen; pos++)
                                {
                                        if(searched != true)
                                        {
                                                if(strfind(foundname,PlayerName,true) == pos)
                                                {
                                        found++;
                                                        id = i;
                                                }
                                        }
                                }
                        }
                }
 
                if(found == 1)
                        return id;
                else
                        return INVALID_PLAYER_ID;
}
estude os especificadores da sscanf e entendera o que quero dizer.

pra que isto:

pawn Код:
stock GetLevelAdmin(levelid)
{
    new str[50];
    if(levelid == 1)
    {
        str = "1";
    }
    else if (levelid == 2)
    {
        str = "2";
    }
    else if (levelid == 3)
    {
        str = "3";
    }
    else if (levelid == 4)
    {
        str = "4";
    }
    else if (levelid == 5)
    {
        str = "5";
    }
    return str;
}
??

pawn Код:
CMD:comandosadmin(playerid)
{
 new dialogrande[1024];
 format(dialogrande, sizeof(dialogrande),"%s%s",dialogrande,"/asay, /jetpack, /tr, /ir, /vidat, /dararma, /kick, /pinfo, /setadmin, /ban, /vida, /congelar, /descongelar, /olhar, /olharoff\n");
 return 1;
}
aconselho vivamente a comecar a otimizar seus scripts.
Sim sim, isso foi no comeзo como disse acima usei strtok tambйm, obrigado pelos conselhos prуxima atualizaзгo nгo terб mais uso de strtok apenas zcmd + sscanf, abraзos.
Reply
#4

pawn Код:
CMD:setadmin(playerid, params[])
{
 new id, level, string[256], string2[256], ganhou[MAX_PLAYER_NAME], deu[MAX_PLAYER_NAME];
 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Vocк nгo й um Administrador Logado Na RCON.");
 if(sscanf(params, "ud", id, level)) return SendClientMessage(playerid, -1, "Use /setadmin [id] [LEVEL]");
 if (level < 0 || level > 5) return SendClientMessage(playerid, -1, "Level invбlido. Use de 1 б 5 .");
 if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "Este jogador nгo estб online.");
 GetPlayerName(id, ganhou, sizeof(ganhou));
 GetPlayerName(playerid, deu, sizeof(deu));
 format(string, sizeof(string), "Vocк deu admin level %s para o %s", GetLevelAdmin(level), ganhou);
 SendClientMessage(playerid, -1, string);
 format(string2, sizeof(string2), "O admin %s deu admin level %s para vocк.", deu , GetLevelAdmin(level));
 SendClientMessage(id, -1, string2);
 pAdmin[id][Level] =  level;
 return 1;
}
1) Nгo tem necessidade de ficar criando string e string2, basta enviб-la ao jogador antes de formatб-la novamente. Veja:

pawn Код:
CMD:setadmin(playerid, params[])
{
 new id, level, string[256], ganhou[MAX_PLAYER_NAME], deu[MAX_PLAYER_NAME];
 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Vocк nгo й um Administrador Logado Na RCON.");
 if(sscanf(params, "ud", id, level)) return SendClientMessage(playerid, -1, "Use /setadmin [id] [LEVEL]");
 if (level < 0 || level > 5) return SendClientMessage(playerid, -1, "Level invбlido. Use de 1 б 5 .");
 if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "Este jogador nгo estб online.");
 GetPlayerName(id, ganhou, sizeof(ganhou));
 GetPlayerName(playerid, deu, sizeof(deu));
 format(string, sizeof(string), "Vocк deu admin level %s para o %s", GetLevelAdmin(level), ganhou);
 SendClientMessage(playerid, -1, string);
 format(string, sizeof(string), "O admin %s deu admin level %s para vocк.", deu , GetLevelAdmin(level));
 SendClientMessage(id, -1, string);
 pAdmin[id][Level] =  level;
 return 1;
}
2) Tambйm aconselho vocк a nгo ficar usando o valor 256 em todas as strings, pois na maioria das vezes nгo vai usar isso. Eu utilizo este contador de caracteres e somo os outros valores como parвmetros do comando, nick do jogador, e por aн vai, e aumento mais uns 5-10 no resultado final, sу para garantir. A maior parte das minhas strings nгo ultrapassam o valor de 120 e essas sгo as que possui variedade de cores, pois as que sгo de uma cor sу, costumam ser de 70 a 90.

3) E por ъltimo, para facilitar sua vida, use uma funзгo para retornar o nome do jogador:

pawn Код:
PlayerName(playerid)
{
    new nomej[MAX_PLAYER_NAME];
    GetPlayerName(playerid, nomej, sizeof(nomej));
    return nomej;
}
Sendo assim, ao invйs de usar, por exemplo:

pawn Код:
new arquivi[34], nomeplayer[MAX_PLAYER_NAME];
GetPlayerName(playerid, nomeplayer, sizeof(nomeplayer));
format(arquivi, sizeof(arquivi), "Admins/%s.ini", nomeplayer);
Vai usar apenas:

pawn Код:
new arquivi[34];
format(arquivi, sizeof(arquivi), "Admins/%s.ini", PlayerName(playerid));
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)