Доступ к архиву

Переход в группу "Пользователь"

300.00 ₽
Одноразовый платёж
Быстрый переход в группу "Пользователи", без надобности написания постов и ожидания.

Покупка дает возможность:
Быть полноправным участником форума
Нормальное копирование кода
Создавать темы
Скачивать файлы
Доступ к архиву Pawno-Info

Динамическая система фракций

Статус
В этой теме нельзя размещать новые ответы.

Rocky98

Ученик
Ув.пользователи pawno-info.ru

Решил выложить урок динамических фракций.
С помощью этого урока вы можете прямо в игре создавать фракции, это проще чем в моде.

Итак, начнём..


1 Шаг.
Ко всем #define


Код:
#define MAX_FRACTIONS 30 //максимальное кол-во фракций, измените на своё
2-ой шаг.
Далее..ко всем new


Код:
new PFRACTIONS[MAX_FRACTIONS];
new Text3D:FRACTIONS[MAX_FRACTIONS];
3-ий шаг.

ко всем enum, например перед/после enim pInfo.


Код:
enum FracInfo
{
    Float:EnteR[3],
    Float:ExiT[3],
    InterioR,
    LeadeR[MAX_PLAYER_NAME],
    BanK,
    NamE[MAX_PLAYER_NAME],
    VirtW,
    RegistreD,
};
new FractionInfo[MAX_FRACTIONS][FracInfo];
4-ый шаг.
В public OnGameModeInit()


Код:
LoadFractions();
    for(new numb = 0;numb < sizeof(FractionInfo); numb++)
    {
        if(FractionInfo[numb][RegistreD] == 0){}
     PFRACTIONS[numb] = CreatePickup(1318,1,FractionInfo[numb][EnteR][0],FractionInfo[numb][EnteR][1],FractionInfo[numb][EnteR][2]-0.4,0);
     FRACTIONS[numb] = Create3DTextLabel(FractionInfo[numb][NamE],-1,FractionInfo[numb][EnteR][0],FractionInfo[numb][EnteR][1],FractionInfo[numb][EnteR][2]+0.5,20,0,0);
    }
5-ый шаг.
В OnGameModeExit()


Код:
SaveFractions();
6-ой шаг.
В public OnPlayerCommandText(playerid, cmdtext[])


Код:
new cmd[256];
       new tmp[256];
       new idx;
    if(strcmp(cmd, "/organization", true) == 0 || strcmp(cmd, "/org", true) == 0)
    {
        if(IsPlayerConnected(playerid))
     {
         tmp = strtok(cmdtext,idx);
         if(!strlen(tmp))
        {
            SendClientMessage(playerid,-1,"/org [действие (создать|удалить|вход|выход|название) ]");
                return 1;
        }
      if(strcmp(tmp,"создать",true) == 0)
      {
          tmp = strtok(cmdtext,idx);
       if(!strlen(tmp))
         {
             SendClientMessage(playerid,-1,"/org создать [id] [название]");
                 return 1;
         }
         new numb = strval(tmp);
         if(FractionInfo[numb][RegistreD] == 1)
         {
             SendClientMessage(playerid,-1,"Извините, но организация по этим ID уже зарегистрирована.");
                 return 1;
       }
       new length = strlen(cmdtext);
       while ((idx < length) && (cmdtext[idx] <= ' '))
       {
        idx++;
       }
       new offset = idx;
       new result[128];
       while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
       {
        result[idx - offset] = cmdtext[idx];
        idx++;
       }
       result[idx - offset] = EOS;
       if(!strlen(result))
         {
             SendClientMessage(playerid,-1,"/org создать [id] [название]");
                 return 1;
         }
       strmid(FractionInfo[numb][NamE],result,0,strlen(result),255);
       GetPlayerName(playerid,FractionInfo[numb][LeadeR],256);
       FractionInfo[numb][RegistreD] = 1;
       GetPlayerPos(playerid,
       FractionInfo[numb][EnteR][0],
       FractionInfo[numb][EnteR][1],
       FractionInfo[numb][EnteR][2]);
       FractionInfo[numb][ExiT][0] = 1;
       FractionInfo[numb][ExiT][1] = 1;
       FractionInfo[numb][ExiT][2] = 1;
       PFRACTIONS[numb] = CreatePickup(1318,1,FractionInfo[numb][EnteR][0],FractionInfo[numb][EnteR][1],FractionInfo[numb][EnteR][2]-0.4,GetPlayerVirtualWorld(playerid));
       FRACTIONS[numb] = Create3DTextLabel(FractionInfo[numb][NamE],-1,FractionInfo[numb][EnteR][0],FractionInfo[numb][EnteR][1],FractionInfo[numb][EnteR][2]+0.5,20,GetPlayerVirtualWorld(playerid),0);
       SaveFractions();
      }
      else if(strcmp(tmp,"удалить",true) == 0)
      {
          tmp = strtok(cmdtext,idx);
       if(!strlen(tmp))
        {
         SendClientMessage(playerid,-1,"/org удалить [id]");
           return 1;
       }
       new frac = strval(tmp);
          FractionInfo[frac][EnteR][0] = 1;
       FractionInfo[frac][EnteR][1] = 1;
       FractionInfo[frac][EnteR][2] = 1;
       FractionInfo[frac][ExiT][0] = 1;
       FractionInfo[frac][ExiT][1] = 1;
       FractionInfo[frac][ExiT][2] = 1;
                   strmid(FractionInfo[frac][NamE],"NONE",0,strlen("NONE"),255);
       strmid(FractionInfo[frac][LeadeR],"NONE",0,strlen("NONE"),255);
                   DestroyPickup(PFRACTIONS[frac]);
                Delete3DTextLabel(FRACTIONS[frac]);
          FractionInfo[frac][RegistreD] = 0;
          SaveFractions();
          return 1;
      }
      else if(strcmp(tmp,"вход",true) == 0)
      {
                   tmp = strtok(cmdtext,idx);
       if(!strlen(tmp))
       {
           SendClientMessage(playerid,-1,"/org вход [id]");
              return 1;
       }
                   new frac = strval(tmp);
          GetPlayerPos(playerid,FractionInfo[frac][EnteR][0],FractionInfo[frac][EnteR][1],FractionInfo[frac][EnteR][2]);
       DestroyPickup(PFRACTIONS[frac]);
       PFRACTIONS[frac] = CreatePickup(1318,1,FractionInfo[frac][EnteR][0],FractionInfo[frac][EnteR][1],FractionInfo[frac][EnteR][2]-0.4,GetPlayerVirtualWorld(playerid));
       Delete3DTextLabel(FRACTIONS[frac]);
       FRACTIONS[frac] = Create3DTextLabel(FractionInfo[frac][NamE],-1,FractionInfo[frac][EnteR][0],FractionInfo[frac][EnteR][1],FractionInfo[frac][EnteR][2]+0.5,20,GetPlayerVirtualWorld(playerid),0);
       SaveFractions();
          return 1;
         }
      else if(strcmp(tmp,"выход",true) == 0)
         {
          tmp = strtok(cmdtext,idx);
       if(!strlen(tmp))
        {
               SendClientMessage(playerid,-1,"/org выход [id]");
                  return 1;
         }
                   new frac = strval(tmp);
          GetPlayerPos(playerid,FractionInfo[frac][ExiT][0],FractionInfo[frac][ExiT][1],FractionInfo[frac][ExiT][2]);
       FractionInfo[frac][InterioR] = GetPlayerInterior(playerid);
       FractionInfo[frac][VirtW] = frac;
       SaveFractions();
          return 1;
         }
      else if(strcmp(tmp,"название",true) == 0)
      {
             tmp = strtok(cmdtext,idx);
       if(!strlen(tmp))
        {
              SendClientMessage(playerid,-1,"/org название [id] [название орг.]");
                  return 1;
         }
                   new frac = strval(tmp);
          new length = strlen(cmdtext);
       while ((idx < length) && (cmdtext[idx] <= ' '))
       {
        idx++;
       }
       new offset = idx;
       new result[128];
       while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
       {
        result[idx - offset] = cmdtext[idx];
        idx++;
       }
       result[idx - offset] = EOS;
       if(!strlen(result))
         {
             SendClientMessage(playerid,-1,"/org название [id] [название орг.]");
                 return 1;
         }
       strmid(FractionInfo[frac][NamE],result,0,strlen(result),255);
                   Delete3DTextLabel(FRACTIONS[frac]);
       FRACTIONS[frac] = Create3DTextLabel(FractionInfo[frac][NamE],-1,FractionInfo[frac][EnteR][0],FractionInfo[frac][EnteR][1],FractionInfo[frac][EnteR][2]+0.5,20,GetPlayerVirtualWorld(playerid),0);
       SaveFractions();
          return 1;
      }
     }
     return 1;
    }
    if(strcmp(cmd, "/clearfractions", true) == 0)
    {
        if(IsPlayerConnected(playerid))
     {
         for(new frac; frac < sizeof(FractionInfo); frac++)
      {
          FractionInfo[frac][EnteR][0] = 1;
       FractionInfo[frac][EnteR][1] = 1;
       FractionInfo[frac][EnteR][2] = 1;
       FractionInfo[frac][ExiT][0] = 1;
       FractionInfo[frac][ExiT][1] = 1;
       FractionInfo[frac][ExiT][2] = 1;
       FractionInfo[frac][InterioR] = 0;
       FractionInfo[frac][VirtW] = 255;
       FractionInfo[frac][BanK] = 100;
                   strmid(FractionInfo[frac][NamE],"NONE",0,strlen("NONE"),255);
       strmid(FractionInfo[frac][LeadeR],"NONE",0,strlen("NONE"),255);
                   DestroyPickup(PFRACTIONS[frac]);
                   Delete3DTextLabel(FRACTIONS[frac]);
          FractionInfo[frac][RegistreD] = 0;
       SaveFractions();
         }
      SendClientMessage(playerid,-1,"Вы только что очистили все динамические фракции.");
     }
     return 1;
    }
7-ой шаг.
В public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)


Код:
 if(newkeys == KEY_WALK)
    {
     for(new i = 0; i <sizeof(FractionInfo); i++)
     {
      if (PlayerToPoint(3, playerid,FractionInfo[i][EnteR][0], FractionInfo[i][EnteR][1], FractionInfo[i][EnteR][2]))
      {
       SetPlayerPos(playerid,FractionInfo[i][ExiT][0],FractionInfo[i][ExiT][1],FractionInfo[i][ExiT][2]);
          SetPlayerInterior(playerid,FractionInfo[i][InterioR]);
          SetPlayerVirtualWorld(playerid,FractionInfo[i][VirtW]);
      }
     }
    }
8-ой шаг.
В конце мода создаем паблики сохранения и загрузки фракций:


Код:
forward LoadFractions();
public LoadFractions()
{
       new arrCoords[12][64];
    new strFromFile2[256];
    new File: file = fopen("fractions.cfg", io_read);
    if (file)
    {
     new idx;
     while (idx < sizeof(FractionInfo))
     {
      fread(file, strFromFile2);
      split(strFromFile2, arrCoords, '|');
      FractionInfo[idx][EnteR][0] = strval(arrCoords[0]);
      FractionInfo[idx][EnteR][1] = strval(arrCoords[1]);
      FractionInfo[idx][EnteR][2] = strval(arrCoords[2]);
      FractionInfo[idx][ExiT][0] = strval(arrCoords[3]);
      FractionInfo[idx][ExiT][1] = strval(arrCoords[4]);
      FractionInfo[idx][ExiT][2] = strval(arrCoords[5]);
      FractionInfo[idx][InterioR] = strval(arrCoords[6]);
      strmid(FractionInfo[idx][LeadeR],arrCoords[7],0,strlen(arrCoords[7]),255);
      FractionInfo[idx][BanK] = strval(arrCoords[8]);
      strmid(FractionInfo[idx][NamE],arrCoords[9],0,strlen(arrCoords[9]),255);
      FractionInfo[idx][VirtW] = strval(arrCoords[10]);
      FractionInfo[idx][RegistreD] = strval(arrCoords[11]);
      idx++;
     }
     fclose(file);
    }
    return 1;
}

forward SaveFractions();
public SaveFractions()
{
    new idx;
    new File: file2;
    while (idx < sizeof(FractionInfo))
    {
     new coordsstring[256];
     format(coordsstring, sizeof(coordsstring), "%f|%f|%f|%f|%f|%f|%d|%s|%d|%s|%d|%d\n",
     FractionInfo[idx][EnteR][0],
     FractionInfo[idx][EnteR][1],
     FractionInfo[idx][EnteR][2],
     FractionInfo[idx][ExiT][0],
     FractionInfo[idx][ExiT][1],
     FractionInfo[idx][ExiT][2],
     FractionInfo[idx][InterioR],
     FractionInfo[idx][LeadeR],
     FractionInfo[idx][BanK],
     FractionInfo[idx][NamE],
     FractionInfo[idx][VirtW],
           FractionInfo[idx][RegistreD]);
     if(idx == 0)
     {
      file2 = fopen("fractions.cfg", io_write);
     }
     else
     {
      file2 = fopen("fractions.cfg", io_append);
     }
     fwrite(file2, coordsstring);
     idx++;
     fclose(file2);
    }
    return 1;
}
Ну и последний 9-ый шаг.
Вспомогательные функции для работы, если их нет в моде:


Код:
forward split(const strsrc[], strdest[][], delimiter);
public split(const strsrc[], strdest[][], delimiter)
{
    new i, li;
    new aNum;
    new len;
    while(i <= strlen(strsrc)){
        if(strsrc[i]==delimiter || i==strlen(strsrc)){
            len = strmid(strdest[aNum], strsrc, li, i, 128);
            strdest[aNum][len] = 0;
            li = i+1;
            aNum++;
     }
     i++;
    }
    return 1;
}



forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
       if(IsPlayerConnected(playerid))
       {
           new Float:oldposx, Float:oldposy, Float:oldposz;
           new Float:tempposx, Float:tempposy, Float:tempposz;
           GetPlayerPos(playerid, oldposx, oldposy, oldposz);
           tempposx = (oldposx -x);
           tempposy = (oldposy -y);
           tempposz = (oldposz -z);
           if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
           {
               return 1;
           }
       }
       return 0;
}

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;
}
Автор данного урока Rocky98.
 
Последнее редактирование:
Статус
В этой теме нельзя размещать новые ответы.
Сверху Снизу