Пользователь
- Регистрация
- 18 Фев 2025
- Сообщения
- 1
- Автор темы
- #1
2.6. Весь код необходимо брать под тег "Код".
Привет! Это реализация не полная, базовые функции. Можно дополнить кодом,системами.
avtor = larionov. удачи!
#include <Pawn.CMD> // (скачать)
#define MAX_PETS 100
#define PET_FOLLOW_DISTANCE 2.0
enum E_PET_INFO {
bool
etCreated,
petOwnerID,
petID,
petName[24],
Float
etX,
Float
etY,
Float
etZ
};
new PetInfo[MAX_PETS][E_PET_INFO];
public OnFilterScriptInit() {
for(new i = 0; i < MAX_PETS; i++) {
PetInfo[petCreated] = false;
}
return 1;
}
// Команда для создания питомца
cmd:createpet(playerid) {
CreatePet(playerid);
return 1;
}
// Команда для открытия меню питомца
cmd
etmenu(playerid) {
ShowPetMenu(playerid);
return 1;
}
CreatePet(playerid) {
for(new i = 0; i < MAX_PETS; i++) {
if (!PetInfo[petCreated]) {
PetInfo[petCreated] = true;
PetInfo[petOwnerID] = playerid;
PetInfo[petID] = CreateDynamicObject(19315, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // Пример объекта питомца
GetPlayerPos(playerid, PetInfo[petX], PetInfo[petY], PetInfo[petZ]);
SetDynamicObjectPos(PetInfo[petID], PetInfo[petX], PetInfo[petY], PetInfo[petZ]);
SendClientMessage(playerid, -1, "Питомец создан! Используйте /petmenu для управления.");
return 1;
}
}
SendClientMessage(playerid, -1, "Не удалось создать питомца. Достигнут лимит.");
return 0;
}
ShowPetMenu(playerid) {
new petIndex = GetPlayerPetIndex(playerid);
if (petIndex == -1) {
SendClientMessage(playerid, -1, "У вас нет питомца.");
return 0;
}
ShowPlayerDialog(playerid, 100, DIALOG_STYLE_LIST, "Меню питомца", "Следовать за мной\nОстановиться\nПереименовать", "Выбрать", "Отмена");
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
if (dialogid == 100) {
if (!response) return 0;
new petIndex = GetPlayerPetIndex(playerid);
if (petIndex == -1) return 0;
switch(listitem) {
case 0: {
PetFollowPlayer(petIndex, playerid);
SendClientMessage(playerid, -1, "Питомец следует за вами.");
}
case 1: {
StopPet(petIndex);
SendClientMessage(playerid, -1, "Питомец остановлен.");
}
case 2: {
ShowPlayerDialog(playerid, 101, DIALOG_STYLE_INPUT, "Переименовать питомца", "Введите новое имя для питомца:", "ОК", "Отмена");
}
}
return 1;
}
if (dialogid == 101) {
if (!response) return 0;
new petIndex = GetPlayerPetIndex(playerid);
if (petIndex == -1) return 0;
if (strlen(inputtext) > 0) {
format(PetInfo[petIndex][petName], 24, inputtext);
SendClientMessage(playerid, -1, "Имя питомца изменено.");
}
return 1;
}
return 0;
}
PetFollowPlayer(petIndex, playerid) {
PetInfo[petIndex][petOwnerID] = playerid;
// Здесь можно добавить логику для следования питомца за игроком
// Например, использование таймеров для обновления позиции питомца
}
StopPet(petIndex) {
// Остановить питомца
}
GetPlayerPetIndex(playerid) {
for(new i = 0; i < MAX_PETS; i++) {
if (PetInfo[petCreated] && PetInfo[petOwnerID] == playerid) {
return i;
}
}
return -1;
}
public OnPlayerUpdate(playerid) {
new petIndex = GetPlayerPetIndex(playerid);
if (petIndex != -1) {
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
if (GetPlayerDistanceFromPoint(playerid, PetInfo[petIndex][petX], PetInfo[petIndex][petY], PetInfo[petIndex][petZ]) > PET_FOLLOW_DISTANCE) {
SetDynamicObjectPos(PetInfo[petIndex][petID], x, y, z);
PetInfo[petIndex][petX] = x;
PetInfo[petIndex][petY] = y;
PetInfo[petIndex][petZ] = z;
}
}
return 1;
}
#define MAX_PETS 100
#define PET_FOLLOW_DISTANCE 2.0
enum E_PET_INFO {
bool
petOwnerID,
petID,
petName[24],
Float
Float
Float
};
new PetInfo[MAX_PETS][E_PET_INFO];
public OnFilterScriptInit() {
for(new i = 0; i < MAX_PETS; i++) {
PetInfo[petCreated] = false;
}
return 1;
}
// Команда для создания питомца
cmd:createpet(playerid) {
CreatePet(playerid);
return 1;
}
// Команда для открытия меню питомца
cmd
ShowPetMenu(playerid);
return 1;
}
CreatePet(playerid) {
for(new i = 0; i < MAX_PETS; i++) {
if (!PetInfo[petCreated]) {
PetInfo[petCreated] = true;
PetInfo[petOwnerID] = playerid;
PetInfo[petID] = CreateDynamicObject(19315, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // Пример объекта питомца
GetPlayerPos(playerid, PetInfo[petX], PetInfo[petY], PetInfo[petZ]);
SetDynamicObjectPos(PetInfo[petID], PetInfo[petX], PetInfo[petY], PetInfo[petZ]);
SendClientMessage(playerid, -1, "Питомец создан! Используйте /petmenu для управления.");
return 1;
}
}
SendClientMessage(playerid, -1, "Не удалось создать питомца. Достигнут лимит.");
return 0;
}
ShowPetMenu(playerid) {
new petIndex = GetPlayerPetIndex(playerid);
if (petIndex == -1) {
SendClientMessage(playerid, -1, "У вас нет питомца.");
return 0;
}
ShowPlayerDialog(playerid, 100, DIALOG_STYLE_LIST, "Меню питомца", "Следовать за мной\nОстановиться\nПереименовать", "Выбрать", "Отмена");
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
if (dialogid == 100) {
if (!response) return 0;
new petIndex = GetPlayerPetIndex(playerid);
if (petIndex == -1) return 0;
switch(listitem) {
case 0: {
PetFollowPlayer(petIndex, playerid);
SendClientMessage(playerid, -1, "Питомец следует за вами.");
}
case 1: {
StopPet(petIndex);
SendClientMessage(playerid, -1, "Питомец остановлен.");
}
case 2: {
ShowPlayerDialog(playerid, 101, DIALOG_STYLE_INPUT, "Переименовать питомца", "Введите новое имя для питомца:", "ОК", "Отмена");
}
}
return 1;
}
if (dialogid == 101) {
if (!response) return 0;
new petIndex = GetPlayerPetIndex(playerid);
if (petIndex == -1) return 0;
if (strlen(inputtext) > 0) {
format(PetInfo[petIndex][petName], 24, inputtext);
SendClientMessage(playerid, -1, "Имя питомца изменено.");
}
return 1;
}
return 0;
}
PetFollowPlayer(petIndex, playerid) {
PetInfo[petIndex][petOwnerID] = playerid;
// Здесь можно добавить логику для следования питомца за игроком
// Например, использование таймеров для обновления позиции питомца
}
StopPet(petIndex) {
// Остановить питомца
}
GetPlayerPetIndex(playerid) {
for(new i = 0; i < MAX_PETS; i++) {
if (PetInfo[petCreated] && PetInfo[petOwnerID] == playerid) {
return i;
}
}
return -1;
}
public OnPlayerUpdate(playerid) {
new petIndex = GetPlayerPetIndex(playerid);
if (petIndex != -1) {
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
if (GetPlayerDistanceFromPoint(playerid, PetInfo[petIndex][petX], PetInfo[petIndex][petY], PetInfo[petIndex][petZ]) > PET_FOLLOW_DISTANCE) {
SetDynamicObjectPos(PetInfo[petIndex][petID], x, y, z);
PetInfo[petIndex][petX] = x;
PetInfo[petIndex][petY] = y;
PetInfo[petIndex][petZ] = z;
}
}
return 1;
}
avtor = larionov. удачи!
Последнее редактирование модератором: