PlayWorld Community

Doriți să reacționați la acest mesaj? Creați un cont în câteva clickuri sau conectați-vă pentru a continua.

    [TUTORIAL/SA:MP] TUTORIAL EXPIRARE AUTO###### A BANULUI

    BogdanYoYo
    BogdanYoYo
    Admin


    Zodiac : Taur Mesaje : 553
    Data de inscriere : 08/04/2013
    Varsta : 26
    Localizare : Brasov

    [TUTORIAL/SA:MP] TUTORIAL EXPIRARE AUTO###### A BANULUI   Empty [TUTORIAL/SA:MP] TUTORIAL EXPIRARE AUTO###### A BANULUI

    Mesaj Scris de BogdanYoYo Mier Aug 14, 2013 12:48 pm

    Salut. In cele ce urmeaza am sa va arat cum sa faceti ca la comanda /ban, banul sa expire automat jucatorului respectiv. Sistemul este creat de mine, bineinteles inspirat din alt sistem de autounban. Consta in salvarea numelui jucatorului si datei care va expira banul. Deci:
    La

    Cod:
    public OnGameModeInit()


    adaugati aceasta verificare:

    Cod:
    if (!fexist("TempBans.ban")){
    new File:open = fopen("TempBans.ban",io_write);
    if (open) fclose(open);
    }



    La

    Cod:
    public OnPlayerLogin(playerid)


    adaugato verificarea

    Cod:
    TempBanCheck(playerid);



    Inlocuiti comenzile de ban si warn cu acestea:

    Cod:
    if(strcmp(cmd, "/ban", true) == 0)
    {
    new name[MAX_PLAYER_NAME];

    if(PlayerInfo[playerid][pAdmin] >= 1)
    {
    tmp = strtok(cmdtext,idx);
    if(!strlen(tmp))
    {
    SendClientMessage(playerid, LIGHTBLUE2, "Usage: /ban [PlayerID] [Day(s)] [Reason]");
    SendClientMessage(playerid, orange, "Function: Temporarily bans a player for specified Days");
    return 1;
    }
    if(PlayerBanned[playerid] == -1)//report timer
    {
    SendClientMessage(playerid,COLOR_RED,"Poti da /ban doar o data la 3 minute!");
    return 1;
    }
    giveplayerid = ReturnUser(tmp);
    if(IsPlayerConnected(giveplayerid))
    {
    tmp = strtok(cmdtext, idx);
    if (!strlen(tmp))
    {
    SendClientMessage(playerid, LIGHTBLUE2, "Usage: /ban [PlayerID] [Day(s)] [Reason]");
    SendClientMessage(playerid, orange, "Function: Temporarily bans a player for specified Days");
    return 1;
    }
    new days = strval(tmp);
    if(!IsNumeric(tmp))
    return SendClientMessage(playerid, lightred, "ERROR: Invalid Day! Only Numbers!");

    if(strval(tmp) <= 0 || strval(tmp) > 1000)
    return SendClientMessage(playerid, lightred, "ERROR: Invalid Day! (1-1000)");

    new reason[128];
    reason = strtok2(cmdtext,idx);
    if (!strlen(reason))
    return SendClientMessage(playerid, lightred, "ERROR: Reason not Specified!");

    if (strlen(reason) <= 0 || strlen(reason) > 100)
    return SendClientMessage(playerid, lightred, "ERROR: Invalid Reason length!");

    GetPlayerName(playerid, name, sizeof name);
    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
    new File:tempban = fopen("TempBans.ban", io_append);
    if (tempban)
    {
    new year,month,day;
    getdate(year, month, day);
    day += days;
    if (IsMonth31(month))
    {
    if (day > 31)
    {
    month += 1;
    if (month > 12)
    {
    year += 1;
    while(day > 31) day -= 31;
    }
    else while(day > 31) day -= 31;
    }
    }
    else if (!IsMonth31(month))
    {
    if (day > 30)
    {
    month += 1;
    if (month > 12)
    {
    year += 1;
    while(day > 30) day -= 30;
    }
    else while(day > 30) day -= 30;
    }
    }
    else if (!IsMonth31(month) && IsMonth29(year) && month == 2)
    {
    if (day > 29)
    {
    month += 1;
    if (month > 12)
    {
    year += 1;
    while(day > 29) day -= 29;
    }
    else while(day > 29) day -= 29;
    }
    }
    else if (!IsMonth31(month) && !IsMonth29(year) && month == 2)
    {
    if (day > 28)
    {
    month += 1;
    if (month > 12)
    {
    year += 1;
    while(day > 28) day -= 28;
    }
    else while(day > 28) day -= 28;
    }
    }
    format(string, sizeof string, "%d|%d|%d|%s\n", day, month, year, giveplayer);
    fwrite(tempban, string);
    fclose(tempban);
    }
    new y,m,d;
    getdate(y,m,d);
    format(string,128,"|- AdmCmd: %s Banned %s for %d Day(s) | Reason: %s -|",name,giveplayer,days,reason);
    SendClientMessageToAll(COLOR_LIGHTRED,string);
    Kick(giveplayerid);

    format(string, sizeof string, "(%d-%d-%d)AdmCmd: Admin %s Banned %s for %d Day(s) | Reason: %s",d,m,y,name,giveplayer,days,reason);
    BanLog(string);
    PlayerBanned[playerid] = -1;
    SetTimerEx("ResetBan", 180000, 0, "d", playerid);
    }
    else
    {
    format(string, sizeof(string), " %d is not an active player.", giveplayerid);
    SendClientMessage(playerid, COLOR_GRAD1, string);
    }
    }
    else return SendClientMessage(playerid,COLOR_GRAD1,"You are not authorized to use that command");
    return true;
    }

    si

    if(strcmp(cmd, "/warn", true) == 0)
    {
    if(IsPlayerConnected(playerid))
    {
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))
    {
    SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /warn [playerid/PartOfName] [reason]");
    return 1;
    }
    if(PlayerWarned[playerid] == -1)//report timer
    {
    SendClientMessage(playerid,COLOR_RED,"Poti da /warn doar o data la 1 minut!");
    return 1;
    }
    giveplayerid = ReturnUser(tmp);
    if (PlayerInfo[playerid][pAdmin] >= 1)
    {
    if(IsPlayerConnected(giveplayerid))
    {
    if(giveplayerid != INVALID_PLAYER_ID)
    {
    if(IsAFounder(giveplayerid))
    {
    SendClientMessage(playerid, COLOR_GRAD1, "You can't warn a founder");
    return 1;
    }
    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
    GetPlayerName(playerid, sendername, sizeof(sendername));
    new length = strlen(cmdtext);
    while ((idx < length) && (cmdtext[idx] <= ' '))
    {
    idx++;
    }
    new offset = idx;
    new result[64];
    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
    {
    result[idx - offset] = cmdtext[idx];
    idx++;
    }
    result[idx - offset] = EOS;
    if(!strlen(result))
    {
    SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /warn [playerid/PartOfName] [reason]");
    return 1;
    }
    format(string, sizeof(string), "You warned %s, reason: %s", giveplayer, (result));
    SendClientMessage(playerid, COLOR_LIGHTRED, string);
    format(string, sizeof(string), "You were warned by %s, reason: %s", sendername, (result));
    SendClientMessage(giveplayerid, COLOR_LIGHTRED, string);
    PlayerInfo[giveplayerid][pWarns] += 1;
    Kick(giveplayerid);
    if(PlayerInfo[giveplayerid][pWarns] >= 3)
    {
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof name);
    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
    new File:tempban = fopen("TempBans.ban", io_append);
    if (tempban)
    {
    new year,month,day;
    getdate(year, month, day);
    day += 2;
    if (IsMonth31(month))
    {
    if (day > 31)
    {
    month += 1;
    if (month > 12)
    {
    year += 1;
    while(day > 31) day -= 31;
    }
    else while(day > 31) day -= 31;
    }
    }
    else if (!IsMonth31(month))
    {
    if (day > 30)
    {
    month += 1;
    if (month > 12)
    {
    year += 1;
    while(day > 30) day -= 30;
    }
    else while(day > 30) day -= 30;
    }
    }
    else if (!IsMonth31(month) && IsMonth29(year) && month == 2)
    {
    if (day > 29)
    {
    month += 1;
    if (month > 12)
    {
    year += 1;
    while(day > 29) day -= 29;
    }
    else while(day > 29) day -= 29;
    }
    }
    else if (!IsMonth31(month) && !IsMonth29(year) && month == 2)
    {
    if (day > 28)
    {
    month += 1;
    if (month > 12)
    {
    year += 1;
    while(day > 28) day -= 28;
    }
    else while(day > 28) day -= 28;
    }
    }
    format(string, sizeof string, "%d|%d|%d|%s\n", day, month, year, giveplayer);
    fwrite(tempban, string);
    fclose(tempban);
    new y,m,d;
    getdate(y, m, d);
    format(string, sizeof(string), "(%d-%d-%d)AdmCmd: Admin %s Banned %s (had 3 Warnings), reason: %s",m,d,y,sendername, giveplayer, (result));
    BanLog(string);
    format(string, sizeof(string), "AdmCmd: Admin %s Banned %s (had 3 Warnings), reason: %s", sendername, giveplayer, (result));
    SendClientMessageToAll(COLOR_LIGHTRED, string);
    }
    PlayerWarned[playerid] = -1;
    SetTimerEx("ResetWarn", 60000, 0, "d", playerid);
    return 1;
    }
    }
    }//not connected
    }
    else
    {
    format(string, sizeof(string), " %d is not an active player.", giveplayerid);
    SendClientMessage(playerid, COLOR_GRAD1, string);
    }
    }
    return 1;
    }


    Iar acum pe undeva pe la sfarsitul GM-ului adaugate acestea:

    stock TempBanCheck(playerid)
    {
    new banname[24];
    new str[128];
    new load[4][32];
    new ban_day, ban_month, ban_year, ban_name[15];
    GetPlayerName(playerid, banname, sizeof banname);
    new year, month, day;
    getdate(year, month, day);
    new File:file = fopen("TempBans.ban",io_read);
    if (file)
    {
    while (fread(file, str, sizeof str))
    {
    split(str, load, '|');

    ban_day = strval(load[0]);
    ban_month = strval(load[1]);
    ban_year = strval(load[2]);
    strmid(ban_name, load[3], 0, strlen(load[3])-1, 24);
    if (!(year >= ban_year && month >= ban_month && day >= ban_day) && !strcmp(ban_name, banname, true))
    {
    format(str, sizeof str, "|- Login de pe cont banat. Banul expira automat la data de: %d/%d/%d -|", ban_day, ban_month, ban_year);
    SendClientMessage(playerid, RED, str);
    return Kick(playerid);
    }
    }
    }
    return true;
    }

    stock IsMonth31(month)
    {
    switch (month)
    {
    case 1: return 1;
    case 3: return 1;
    case 5: return 1;
    case 7: return 1;
    case 8: return 1;
    case 10: return 1;
    case 12: return 1;
    default: return 0;
    }
    return 0;
    }

    stock IsMonth29(year)
    {
    new y = 2000;
    for(new i = 4; i < 3000; i += 4) if ((y+i) == year) return 1;
    return 0;
    }

    stock strtok2(const string[], &idx)
    {
    new length = strlen(string);
    while ((idx < length) && (string[idx] <= ' '))
    {
    idx++;
    }
    new offset = idx;
    new result[128];
    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
    {
    result[idx - offset] = string[idx];
    idx++;
    }
    result[idx - offset] = EOS;
    return result;
    }

    Modificati comenzile /ban si /warn dupa GM-ul vostru ca sa nu apara erori sau warninguri. Multumesc si sper ca v-a fost de folos.

      Data/ora curentă este: Mier Noi 27, 2024 8:29 pm