Last active
April 2, 2024 06:28
-
-
Save ArKaNeMaN/14d46548bbdbc7dacec5425e20315abd to your computer and use it in GitHub Desktop.
Интеграция [ACS] INJECTION с Vip Modular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <amxmodx> | |
#include <VipModular> | |
/* | |
* Расширение добавляет тип предмета `ACS-Injection` для контроллера предметов Vip Modular. | |
* Выдаёт шприц из плагина [ACS] INJECTION (https://dev-cs.ru/resources/1582/). | |
* | |
* Параметры: | |
* Count - Сколько шприцов выдать. По умолчанию 1. | |
* MaxCount - Максимальное количество шприцов, выше которого они не будут выдаваться. По умолчанию 0 (без ограничений). | |
* | |
* Пример предмета: | |
* { | |
* "Type": "ACS-Injection" | |
* "Count": 1, | |
* "MaxCount": 1 | |
* } | |
*/ | |
// Сколько шприцов у игрока | |
native bool:acs_inj_get_user_injections(const id); | |
// Выдать (+) или забрать (-) <count> шприцов | |
native bool:acs_inj_add_user_injections(const id, const count); | |
new const ITEMS_NAME[] = "ACS-Injection"; | |
public VipM_IC_OnInitTypes() { | |
register_plugin("[VipM-I] ACS-Injection", "1.1.0", "ArKaNeMaN"); | |
VipM_IC_RegisterType(ITEMS_NAME); | |
VipM_IC_RegisterTypeEvent(ITEMS_NAME, ItemType_OnRead, "@OnRead"); | |
VipM_IC_RegisterTypeEvent(ITEMS_NAME, ItemType_OnGive, "@OnGive"); | |
} | |
@OnRead(const JSON:jCfg, Trie:tParams) { | |
TrieDeleteKey(tParams, "Name"); | |
if (json_object_has_value(jCfg, "Count", JSONNumber)) { | |
TrieSetCell(tParams, "Count", json_object_get_number(jCfg, "Count")); | |
} | |
if (json_object_has_value(jCfg, "MaxCount", JSONNumber)) { | |
TrieSetCell(tParams, "MaxCount", json_object_get_number(jCfg, "MaxCount")); | |
} | |
} | |
@OnGive(const UserId, const Trie:tParams) { | |
new iCount = VipM_Params_GetInt(tParams, "Count", 1); | |
new iMaxCount = VipM_Params_GetInt(tParams, "MaxCount", 0); | |
if (iMaxCount <= 0) { | |
return acs_inj_add_user_injections(UserId, iCount) ? VIPM_CONTINUE : VIPM_STOP; | |
} | |
new iCurrentCount = acs_inj_get_user_injections(UserId); | |
if (iCurrentCount >= iMaxCount) { | |
return VIPM_STOP; | |
} | |
acs_inj_add_user_injections(UserId, min(iMaxCount - iCurrentCount, iCount)); | |
return VIPM_CONTINUE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment