PDA

Просмотр полной версии : [Мануал] Автомат с оружием для фракций



Xeno
01.04.2019, 16:23
Всем привет.
Может быть кому нибудь понадобится автомат оружия для фракций. Но переменные в проверке на лидера и участника фракции нужно поставить будет свои!

Для начала добавляем enum и массив данных.


enum wCaseInfo
{
bool:wStatus,
wFraction,
Float:wPosX,
Float:wPosY,
Float:wPosZ,
Float:wRPosX,
Float:wRPosY,
Float:wRPosZ,
wVW,
wInt,
wSlotGun[5],
wSlotAmmo[5],
wCountActiveSlot,
Text3D: wLabel
}
new WeaponCase[2][wCaseInfo] = {
{false, 1, -1979.0333,107.0666,27.6875, 0.000000, 0.000000, 0.000000, 0, 0},
{false, 3, -1972.9081,107.1658,27.6875, 0.000000, 0.000000, 0.000000, 0, 0}
};
new GunsCase[8][2] =
{
{24,1}, //24 - ид оружия, 1 - слот
{25,2},
{28,3},
{29,3},
{32,3},
{30,4},
{31,4},
{33,5}
};


В public OnGameModeInit() добавим создание объекта(автомата).


for(new i = 0; i < sizeof(WeaponCase); i++)
{
CreateDynamicObject(18885, WeaponCase[i][wPosX], WeaponCase[i][wPosY], WeaponCase[i][wPosZ], WeaponCase[i][wRPosX], WeaponCase[i][wRPosY], WeaponCase[i][wRPosZ], WeaponCase[i][wVW], WeaponCase[i][wInt]);
WeaponCase[i][wLabel] = Create3DTextLabel("Автомат закрыт",0xFFFFFFAA,WeaponCase[i][wPosX], WeaponCase[i][wPosY], WeaponCase[i][wPosZ]+0.5,13.0,WeaponCase[i][wVW],0);
}


В public OnPlayerCommandText(playerid, cmdtext[]) добавим основную команду.


if(strcmp(cmd, "/guns", true) == 0)
{
if(pLeader[playerid] != 0) // pLeader[playerid] - заменяем на свою переменную лидеров
{
new gunname[32],
WeaponCaseNum = getWeaponCaseNum(playerid);
static string[220];
string[0] = EOS;
strcat(string, "Оружие\tПатроны\tСтатус\n");
for(new i = 0; i < sizeof(GunsCase); i++)
{
new gunid = GunsCase[i][0];
new gunslot = GunsCase[i][1];
GetWeaponName(gunid, gunname, sizeof(gunname));
format(string, sizeof(string),"%s%s\t%d\t%s\n",string,gunname,(WeaponCase[WeaponCaseNum][wSlotGun][gunslot-1] == gunid) ? WeaponCase[WeaponCaseNum][wSlotAmmo][gunslot-1]:0,(WeaponCase[WeaponCaseNum][wSlotGun][gunslot-1] == gunid) ? ("{228B22}Открыт"):("{DC143C}Закрыт"));
}
ShowPlayerDialog(playerid,1000,DIALOG_STYLE_TABLIS T_HEADERS,"Оружейный автомат",string,"Выбрать","Закрыть");
}
else return SendClientMessage(playerid, -1, "Вы не лидер.");
return true;
}


После этого добавим в public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])



if(dialogid == 1000)
{
if(!response) return 1;
for(new i = 0; i < sizeof(GunsCase); i++)
{
if(GunsCase[i][0] == getWeaponID(inputtext))
{
SetPVarInt(playerid,"SloteCase", (GunsCase[i][1])-1);
}
}
new slot = GetPVarInt(playerid,"SloteCase"),
WeaponCaseNum = getWeaponCaseNum(playerid);

SetPVarInt(playerid,"GunCase", getWeaponID(inputtext));
if(GetPVarInt(playerid,"GunCase") == WeaponCase[WeaponCaseNum][wSlotGun][slot])
{
WeaponCase[WeaponCaseNum][wSlotGun][slot] = 0;
WeaponCase[WeaponCaseNum][wSlotAmmo][slot] = 0;
WeaponCase[WeaponCaseNum][wCountActiveSlot]--;
Update3DTextCase(WeaponCaseNum);
DeletePVar(playerid,"GunCase");
DeletePVar(playerid,"SloteCase");
OnPlayerCommandText(playerid, "/guns");
return true;
}
else ShowPlayerDialog(playerid, 1001, DIALOG_STYLE_INPUT, "Автомат оружия", "{808080}Примечание:{808080}\n>{FFFFFF} Кол-во патронов не может быть больше 500 и меньше 20.\n\nВведите количество патронов:", "Положить", "Назад");

}
if(dialogid == 1001)
{
if(!response) return OnPlayerCommandText(playerid, "/guns");
if(strval(inputtext) < 20 || strval(inputtext) > 500) return ShowPlayerDialog(playerid, 1001, DIALOG_STYLE_INPUT, "Автомат оружия", "{808080}Примечание:{808080}\n>{FFFFFF} Кол-во патронов не может быть больше 500 и меньше 20.\n\nВведите количество патронов:", "Положить", "Назад");

new slot = GetPVarInt(playerid,"SloteCase"),
WeaponCaseNum = getWeaponCaseNum(playerid);
if(WeaponCase[WeaponCaseNum][wSlotGun][slot] == 0) WeaponCase[WeaponCaseNum][wCountActiveSlot]++;
WeaponCase[WeaponCaseNum][wSlotGun][slot] = GetPVarInt(playerid,"GunCase");
WeaponCase[WeaponCaseNum][wSlotAmmo][slot] = strval(inputtext);
Update3DTextCase(WeaponCaseNum);
DeletePVar(playerid,"GunCase");
DeletePVar(playerid,"SloteCase");
OnPlayerCommandText(playerid, "/guns");
}


В public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)


if(newkeys == KEY_WALK)
{
new WeaponCaseNum = getWeaponCaseNum(playerid);
if(IsPlayerInRangeOfPoint(playerid,1.0,WeaponCase[WeaponCaseNum][wPosX], WeaponCase[WeaponCaseNum][wPosY], WeaponCase[WeaponCaseNum][wPosZ]))
{
if(WeaponCase[WeaponCaseNum][wStatus])
{
for(new i = 0; i < 5; i++)
{
if(WeaponCase[WeaponCaseNum][wSlotGun][i] != 0 && WeaponCase[WeaponCaseNum][wSlotAmmo][i] != 0)
{
GivePlayerWeapon(playerid, WeaponCase[WeaponCaseNum][wSlotGun][i], WeaponCase[WeaponCaseNum][wSlotAmmo][i]);
}
}
}
else SendClientMessage(playerid, -1, "Автомат закрыт!");
}
}


Теперь добавим ко всем stock


stock getWeaponCaseNum(playerid)
{
for(new i = 0; i < sizeof(WeaponCase); i++)
{
if(WeaponCase[i][wFraction] == pMember[playerid]) return i; //pMember[playerid] - меняем на свою переменную, которая отвечает за нахождение игрока во фракции.
}
return true;
}
stock getWeaponID(name[])
{
if(strfind(name, "Desert Eagle", true) != -1) return 24;
else if(strfind(name, "Shotgun", true) != -1) return 25;
else if(strfind(name, "UZI", true) != -1) return 28;
else if(strfind(name, "MP5", true) != -1) return 29;
else if(strfind(name, "TEC9", true) != -1) return 32;
else if(strfind(name, "AK47", true) != -1) return 30;
else if(strfind(name, "M4", true) != -1) return 31;
else if(strfind(name, "Rifle", true) != -1) return 33;
return true;
}
stock Update3DTextCase(id)
{
if(WeaponCase[id][wCountActiveSlot] == 0) return Update3DTextLabelText(WeaponCase[id][wLabel],0xFFFFFFAA,"Автомат закрыт"), WeaponCase[id][wStatus] = false;
else
{
new str[100];
strcat(str, "Взять: 'Alt'\n\n");
for(new i = 0; i < 5; i++)
{
if(WeaponCase[id][wSlotGun][i] != 0 && WeaponCase[id][wSlotAmmo][i] != 0 )
{
new gunname[32];
GetWeaponName(WeaponCase[id][wSlotGun][i], gunname, sizeof(gunname));
format(str, sizeof(str),"%s%s x%d\n",str,gunname, WeaponCase[id][wSlotAmmo][i]);
}
}
Update3DTextLabelText(WeaponCase[id][wLabel],0xEEEE88FF,str);
if(!WeaponCase[id][wStatus]) WeaponCase[id][wStatus] = true;
}
return true;
}

Так же готов выслушать недочеты по коду.

И вот собственно видео.

https://www.youtube.com/watch?v=RE2I9JsSntU&feature=youtu.be