Knife Models [XP System & Skills Support]

Одобрените от нас плъгини. Моля, докладвайте ако забележите бъг с някой от плъгините в този раздел.
Аватар
OciXCrom
Извън линия
Администратор
Администратор
Мнения: 7206
Регистриран на: 06 Окт 2016, 19:20
Местоположение: /resetscore
Се отблагодари: 117 пъти
Получена благодарност: 1295 пъти
Обратна връзка:

Knife Models [XP System Support]

Мнение от OciXCrom » 25 Авг 2018, 00:50

By the way, make sure you update the rank system to the latest version I uploaded a few hours ago, otherwise it won't work.

Аватар
onixsone
Извън линия
Foreigner
Foreigner
Мнения: 19
Регистриран на: 10 Юли 2018, 09:13
Се отблагодари: 2 пъти

Knife Models [XP System Support]

Мнение от onixsone » 25 Авг 2018, 01:12

OciXCrom™ написа: 24 Авг 2018, 20:18
onixsone написа: 24 Авг 2018, 17:47Another idea that maybe would be cool is to modify the plugin custom shop to use xp in place of points ie use the option of points xp or points in money as it replacing the plugin point to use xp and integrate it into the rank system it would look great.
You can do this as well. It's even explained in the plugin's thread how to do it. Simply replace the cshop_settings.inc file with this one and recompile custom_shop.sma:

Код за потвърждение: Избери целия код

#if defined _cshop_settings_included
    #endinput
#endif

#include <crxranks>

#define _cshop_settings_included
#define DEFAULT_SOUND "items/gunpickup2.wav"
#define FLAG_ADMIN ADMIN_BAN
#define LANG_TYPE LANG_SERVER
#define MAX_ITEMS 100

/*
	* Change the lines below if you want to use a native for your money currency, e.g. Ammo Packs, BaseBuilder Credits, JBPacks, etc.
	* Example (%1 = id | %2 = amount):
		native zp_get_user_ammo_packs(id)
		native zp_set_user_ammo_packs(id, amount)
		#define get_user_money(%1) zp_get_user_ammo_packs(%1)
		#define set_user_money(%1,%2) zp_set_user_ammo_packs(%1, %2)
*/
#define get_user_money(%1) crxranks_get_user_xp(%1)
#define set_user_money(%1,%2) crxranks_set_user_xp(%1, %2)

/* Don't touch this line unless you know what you're doing */
#define take_user_money(%1,%2) set_user_money(%1, get_user_money(%1) - %2)
This will replace the usage of the default CS money with the XP from the rank system.
I tried with this code that you informed but I did not succeed, this error appeared:
Screenshot_9.png
Screenshot_9.png (36.07 KiB) Преглеждано 4753 пъти
Screenshot_9.png
Screenshot_9.png (36.07 KiB) Преглеждано 4753 пъти
Then I made the other topic option by adding the natives:
cshop_settings.inc

Код за потвърждение: Избери целия код

#if defined _cshop_settings_included
    #endinput
#endif

#include <cstrike>

#define _cshop_settings_included
#define DEFAULT_SOUND "items/gunpickup2.wav"
#define FLAG_ADMIN ADMIN_BAN
#define LANG_TYPE LANG_SERVER
#define MAX_ITEMS 100

/*
	* Change the lines below if you want to use a native for your money currency, e.g. Ammo Packs, BaseBuilder Credits, JBPacks, etc.
	* Example (%1 = id | %2 = amount):
		native zp_get_user_ammo_packs(id)
		native zp_set_user_ammo_packs(id, amount)
		#define get_user_money(%1) zp_get_user_ammo_packs(%1)
		#define set_user_money(%1,%2) zp_set_user_ammo_packs(%1, %2)
*/

native crxranks_get_user_xp(id)
native crxranks_set_user_xp(id, amount)
#define get_user_money(%1) crxranks_get_user_xp(%1)
#define set_user_money(%1,%2) crxranks_set_user_xp(%1, %2)

/* Don't touch this line unless you know what you're doing */
#define take_user_money(%1,%2) set_user_money(%1, get_user_money(%1) - %2)
Compiled without errors
Is that correct?

Аватар
OciXCrom
Извън линия
Администратор
Администратор
Мнения: 7206
Регистриран на: 06 Окт 2016, 19:20
Местоположение: /resetscore
Се отблагодари: 117 пъти
Получена благодарност: 1295 пъти
Обратна връзка:

Knife Models [XP System Support]

Мнение от OciXCrom » 25 Авг 2018, 03:18

Like I said, you need to update the rank system first.

Аватар
onixsone
Извън линия
Foreigner
Foreigner
Мнения: 19
Регистриран на: 10 Юли 2018, 09:13
Се отблагодари: 2 пъти

Knife Models [XP System Support]

Мнение от onixsone » 25 Авг 2018, 18:40

OciXCrom™ написа: 25 Авг 2018, 03:18 Like I said, you need to update the rank system first.
Yes I updated the rank system .. The error occurred to compile the custom_shop.sma with the code that you passed.

I compiled with this change which was the other option in the topic and compiled without errors and now works perfectly with the rating system.
Just wanted to know if this change I made is correct.
--

I understood what you meant .. I needed to upgrade the includes of the rank system there works with the code you passed.

But the way I did it also compiled with the old include of the rank system and worked fine on the server.

Thanks man!

Аватар
gil5587
Извън линия
Foreigner
Foreigner
Мнения: 72
Регистриран на: 01 Сеп 2018, 01:26
Се отблагодари: 77 пъти
Получена благодарност: 3 пъти

Knife Models [XP System Support]

Мнение от gil5587 » 08 Окт 2018, 01:24

How to add a way of opening the knife menu?
Like if pressing "g" it'll open it

Аватар
1fRaNkkK
Извън линия
Потребител
Потребител
Мнения: 776
Регистриран на: 09 Окт 2016, 15:21
Се отблагодари: 8 пъти
Получена благодарност: 55 пъти

Knife Models [XP System Support]

Мнение от 1fRaNkkK » 08 Окт 2018, 14:51

gil5587 написа: 08 Окт 2018, 01:24 How to add a way of opening the knife menu?
Like if pressing "g" it'll open it
The knife menu is opening with the /knife command, so the easiest way would be to bind 'g' to write /knife:
bind g "say /knife"
bind g "say_team /knife" for team chat

Аватар
illusion
Извън линия
Developer
Developer
Мнения: 1796
Регистриран на: 27 Ное 2016, 17:47
Местоположение: CraftVision
Се отблагодари: 151 пъти
Получена благодарност: 358 пъти
Обратна връзка:

Knife Models [XP System Support]

Мнение от illusion » 08 Окт 2018, 15:36

gil5587 написа: 08 Окт 2018, 01:24 How to add a way of opening the knife menu?
Like if pressing "g" it'll open it

Код за потвърждение: Избери целия код

#include <amxmodx>
#include <amxmisc>
#include <cromchat>
#include <fakemeta>
#include <hamsandwich>
#include <nvault>

native crxranks_get_max_levels()
native crxranks_get_rank_by_level(level, buffer[], len)
native crxranks_get_user_level(id)
native crxranks_get_user_xp(id)

new const g_szNatives[][] =
{
	"crxranks_get_max_levels",
	"crxranks_get_rank_by_level",
	"crxranks_get_user_level",
	"crxranks_get_user_xp"
}

#if !defined m_pPlayer
	#define m_pPlayer 41
#endif

#if defined client_disconnected
	#define client_disconnect client_disconnected
#endif

#define PLUGIN_VERSION "2.5.8"
#define DEFAULT_V "models/v_knife.mdl"
#define DEFAULT_P "models/p_knife.mdl"
#define MAX_SOUND_LENGTH 128
#define MAX_AUTHID_LENGTH 35

#if !defined MAX_NAME_LENGTH
	#define MAX_NAME_LENGTH 32
#endif

#if !defined MAX_PLAYERS
	#define MAX_PLAYERS 32
#endif

enum
{
	SOUND_NONE = 0,
	SOUND_DEPLOY,
	SOUND_HIT,
	SOUND_HITWALL,
	SOUND_SLASH,
	SOUND_STAB
}

enum _:Knives
{
	NAME[MAX_NAME_LENGTH],
	V_MODEL[MAX_SOUND_LENGTH],
	P_MODEL[MAX_SOUND_LENGTH],
	DEPLOY_SOUND[MAX_SOUND_LENGTH],
	HIT_SOUND[MAX_SOUND_LENGTH],
	HITWALL_SOUND[MAX_SOUND_LENGTH],
	SLASH_SOUND[MAX_SOUND_LENGTH],
	STAB_SOUND[MAX_SOUND_LENGTH],
	SELECT_SOUND[MAX_SOUND_LENGTH],
	FLAG,
	LEVEL,
	bool:SHOW_RANK,
	bool:HAS_CUSTOM_SOUND,
	XP
}

new Array:g_aKnives,
	bool:g_bFirstTime[MAX_PLAYERS + 1],
	bool:g_bRankSystem,
	bool:g_bGetLevel,
	bool:g_bGetXP,
	g_eKnife[MAX_PLAYERS + 1][Knives],
	g_szAuth[MAX_PLAYERS + 1][MAX_AUTHID_LENGTH],
	g_iKnife[MAX_PLAYERS + 1],
	g_iCallback,
	g_pAtSpawn,
	g_pSaveChoice,
	g_iSaveChoice,
	g_iKnivesNum,
	g_iVault

public plugin_init()
{
	register_plugin("Knife Models", PLUGIN_VERSION, "OciXCrom")
	register_cvar("CRXKnifeModels", PLUGIN_VERSION, FCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
	
	if(!g_iKnivesNum)
		set_fail_state("No knives found in the configuration file.")
	
	register_dictionary("KnifeModels.txt")
	
	RegisterHam(Ham_Spawn, "player", "OnPlayerSpawn", 1)
	register_forward(FM_EmitSound,	"OnEmitSound")
	RegisterHam(Ham_Item_Deploy, "weapon_knife", "OnSelectKnife", 1)
	
	register_clcmd("say /knife", "ShowMenu")
	register_clcmd("say_team /knife", "ShowMenu")
	register_clcmd("drop", "ShowMenu")
	
	g_iCallback = menu_makecallback("CheckKnifeAccess")
	g_pAtSpawn = register_cvar("km_open_at_spawn", "0")
	g_pSaveChoice = register_cvar("km_save_choice", "0")
}

public plugin_precache()
{
	if(LibraryExists("crxranks", LibType_Library))
		g_bRankSystem = true
		
	g_aKnives = ArrayCreate(Knives)
	ReadFile()
}

public plugin_cfg()
{
	g_iSaveChoice = get_pcvar_num(g_pSaveChoice)
	
	if(g_iSaveChoice)
		g_iVault = nvault_open("KnifeModels")
}

public plugin_natives()
	set_native_filter("native_filter")
	
public native_filter(const szNative[], id, iTrap)
{
	if(!iTrap)
	{
		static i
		
		for(i = 0; i < sizeof(g_szNatives); i++)
		{
			if(equal(szNative, g_szNatives[i]))
				return PLUGIN_HANDLED
		}
	}
	
	return PLUGIN_CONTINUE
}
	
public plugin_end()
{
	ArrayDestroy(g_aKnives)
	
	if(g_iSaveChoice)
		nvault_close(g_iVault)
}

ReadFile()
{
	new szConfigsName[256], szFilename[256]
	get_configsdir(szConfigsName, charsmax(szConfigsName))
	formatex(szFilename, charsmax(szFilename), "%s/KnifeModels.ini", szConfigsName)
	new iFilePointer = fopen(szFilename, "rt")
	
	if(iFilePointer)
	{
		new szData[160], szKey[32], szValue[128], szSound[128], iMaxLevels
		new eKnife[Knives], bool:bCustom
		
		if(g_bRankSystem)
			iMaxLevels = crxranks_get_max_levels()
		
		while(!feof(iFilePointer))
		{
			fgets(iFilePointer, szData, charsmax(szData))
			trim(szData)
			
			switch(szData[0])
			{
				case EOS, '#', ';': continue
				case '[':
				{
					if(szData[strlen(szData) - 1] == ']')
					{
						if(g_iKnivesNum)
							PushKnife(eKnife)
							
						g_iKnivesNum++
						replace(szData, charsmax(szData), "[", "")
						replace(szData, charsmax(szData), "]", "")
						copy(eKnife[NAME], charsmax(eKnife[NAME]), szData)
						
						eKnife[V_MODEL][0] = EOS
						eKnife[P_MODEL][0] = EOS
						eKnife[DEPLOY_SOUND][0] = EOS
						eKnife[HIT_SOUND][0] = EOS
						eKnife[HITWALL_SOUND][0] = EOS
						eKnife[SLASH_SOUND][0] = EOS
						eKnife[STAB_SOUND][0] = EOS
						eKnife[SELECT_SOUND][0] = EOS
						eKnife[FLAG] = ADMIN_ALL
						eKnife[HAS_CUSTOM_SOUND] = false
						
						if(g_bRankSystem)
						{
							eKnife[LEVEL] = 0
							eKnife[SHOW_RANK] = false
							eKnife[XP] = 0
						}
					}
					else continue
				}
				default:
				{
					strtok(szData, szKey, charsmax(szKey), szValue, charsmax(szValue), '=')
					trim(szKey); trim(szValue)
					bCustom = true
					
					if(equal(szKey, "FLAG"))
						eKnife[FLAG] = read_flags(szValue)
					else if(equal(szKey, "LEVEL") && g_bRankSystem)
					{
						eKnife[LEVEL] = clamp(str_to_num(szValue), 0, iMaxLevels)
						
						if(!g_bGetLevel)
							g_bGetLevel = true
					}
					else if(equal(szKey, "SHOW_RANK") && g_bRankSystem)
						eKnife[SHOW_RANK] = _:clamp(str_to_num(szValue), false, true)
					else if(equal(szKey, "XP") && g_bRankSystem)
					{
						eKnife[XP] = _:clamp(str_to_num(szValue), 0)
						
						if(!g_bGetXP)
							g_bGetXP = true
					}
					else if(equal(szKey, "V_MODEL"))
						copy(eKnife[V_MODEL], charsmax(eKnife[V_MODEL]), szValue)
					else if(equal(szKey, "P_MODEL"))
						copy(eKnife[P_MODEL], charsmax(eKnife[P_MODEL]), szValue)
					else if(equal(szKey, "DEPLOY_SOUND"))
						copy(eKnife[DEPLOY_SOUND], charsmax(eKnife[DEPLOY_SOUND]), szValue)
					else if(equal(szKey, "HIT_SOUND"))
						copy(eKnife[HIT_SOUND], charsmax(eKnife[HIT_SOUND]), szValue)
					else if(equal(szKey, "HITWALL_SOUND"))
						copy(eKnife[HITWALL_SOUND], charsmax(eKnife[HITWALL_SOUND]), szValue)
					else if(equal(szKey, "SLASH_SOUND"))
						copy(eKnife[SLASH_SOUND], charsmax(eKnife[SLASH_SOUND]), szValue)
					else if(equal(szKey, "STAB_SOUND"))
						copy(eKnife[STAB_SOUND], charsmax(eKnife[STAB_SOUND]), szValue)
					else if(equal(szKey, "SELECT_SOUND"))
					{
						bCustom = false
						copy(eKnife[SELECT_SOUND], charsmax(eKnife[SELECT_SOUND]), szValue)
					}
					else continue
					
					static const szModelArg[] = "_MODEL"
					static const szSoundArg[] = "_SOUND"
					
					if(contain(szKey, szModelArg) != -1)
					{
						if(!file_exists(szValue))
							log_amx("ERROR: model ^"%s^" not found!", szValue)
						else
							precache_model(szValue)
					}
					else if(contain(szKey, szSoundArg) != -1)
					{
						formatex(szSound, charsmax(szSound), "sound/%s", szValue)

						if(!file_exists(szSound))
							log_amx("ERROR: sound ^"%s^" not found!", szSound)
						else
							precache_sound(szValue)
						
						if(bCustom)
							eKnife[HAS_CUSTOM_SOUND] = true
					}
				}
			}
		}
		
		if(g_iKnivesNum)
			PushKnife(eKnife)
		
		fclose(iFilePointer)
	}
}

public client_connect(id)
{
	g_bFirstTime[id] = true
	ArrayGetArray(g_aKnives, 0, g_eKnife[id])
	g_iKnife[id] = 0
	
	if(g_iSaveChoice)
	{
		get_user_authid(id, g_szAuth[id], charsmax(g_szAuth[]))
		UseVault(id, false)
	}
}

public client_disconnect(id)
{
	if(g_iSaveChoice)
		UseVault(id, true)
}

public OnEmitSound(id, iChannel, const szSample[])
{
	if(!is_user_connected(id) || !g_eKnife[id][HAS_CUSTOM_SOUND] || !IsKnifeSound(szSample))
		return FMRES_IGNORED
	
	switch(DetectKnifeSound(szSample))
	{
		case SOUND_DEPLOY: 		if(g_eKnife[id][DEPLOY_SOUND][0]) 		{ PlayKnifeSound(id, g_eKnife[id][DEPLOY_SOUND][0]); 	return FMRES_SUPERCEDE; }
		case SOUND_HIT: 		if(g_eKnife[id][HIT_SOUND][0]) 			{ PlayKnifeSound(id, g_eKnife[id][HIT_SOUND][0]); 		return FMRES_SUPERCEDE; }
		case SOUND_HITWALL:		if(g_eKnife[id][HITWALL_SOUND][0]) 		{ PlayKnifeSound(id, g_eKnife[id][HITWALL_SOUND][0]); 	return FMRES_SUPERCEDE; }
		case SOUND_SLASH: 		if(g_eKnife[id][SLASH_SOUND][0]) 		{ PlayKnifeSound(id, g_eKnife[id][SLASH_SOUND][0]);		return FMRES_SUPERCEDE; }
		case SOUND_STAB: 		if(g_eKnife[id][STAB_SOUND][0]) 		{ PlayKnifeSound(id, g_eKnife[id][STAB_SOUND][0]); 		return FMRES_SUPERCEDE; }
	}
	
	return FMRES_IGNORED
}

public ShowMenu(id)
{
	static eKnife[Knives]
	new szTitle[128], szItem[128], iLevel, iXP
	formatex(szTitle, charsmax(szTitle), "%L", id, "KM_MENU_TITLE")

	if(g_bGetLevel)
		iLevel = crxranks_get_user_level(id)
	
	if(g_bGetXP)
		iXP = crxranks_get_user_xp(id)
		
	new iMenu = menu_create(szTitle, "MenuHandler")
	
	for(new iFlags = get_user_flags(id), i; i < g_iKnivesNum; i++)
	{
		ArrayGetArray(g_aKnives, i, eKnife)
		copy(szItem, charsmax(szItem), eKnife[NAME])
		
		if(g_bRankSystem)
		{
			if(eKnife[LEVEL] && iLevel < eKnife[LEVEL])
			{
				if(eKnife[SHOW_RANK])
				{
					static szRank[32]
					crxranks_get_rank_by_level(eKnife[LEVEL], szRank, charsmax(szRank))
					format(szItem, charsmax(szItem), "%s %L", szItem, id, "KM_MENU_RANK", szRank)
				}
				else
					format(szItem, charsmax(szItem), "%s %L", szItem, id, "KM_MENU_LEVEL", eKnife[LEVEL])
			}
			
			if(eKnife[XP] && iXP < eKnife[XP])
				format(szItem, charsmax(szItem), "%s %L", szItem, id, "KM_MENU_XP", eKnife[XP])
		}
		
		if(eKnife[FLAG] != ADMIN_ALL && !(iFlags & eKnife[FLAG]))
			format(szItem, charsmax(szItem), "%s %L", szItem, id, "KM_MENU_VIP_ONLY")
			
		if(g_iKnife[id] == i)
			format(szItem, charsmax(szItem), "%s %L", szItem, id, "KM_MENU_SELECTED")
		
		menu_additem(iMenu, szItem, eKnife[NAME], eKnife[FLAG], g_iCallback)
	}
	
	if(menu_pages(iMenu) > 1)
	{
		formatex(szItem, charsmax(szItem), "%s%L", szTitle, id, "KM_MENU_TITLE_PAGE")
		menu_setprop(iMenu, MPROP_TITLE, szItem)
	}
		
	menu_display(id, iMenu)
	return PLUGIN_HANDLED
}

public MenuHandler(id, iMenu, iItem)
{
	if(iItem != MENU_EXIT)
	{
		g_iKnife[id] = iItem
		ArrayGetArray(g_aKnives, iItem, g_eKnife[id])
		
		if(is_user_alive(id) && get_user_weapon(id) == CSW_KNIFE)
			RefreshKnifeModel(id)
		
		new szName[MAX_NAME_LENGTH], iUnused
		menu_item_getinfo(iMenu, iItem, iUnused, szName, charsmax(szName), .callback = iUnused)
		CC_SendMessage(id, "%L %L", id, "KM_CHAT_PREFIX", id, "KM_CHAT_SELECTED", szName)
		
		if(g_eKnife[id][SELECT_SOUND][0])
			PlayKnifeSound(id, g_eKnife[id][SELECT_SOUND])
	}
	
	menu_destroy(iMenu)
	return PLUGIN_HANDLED
}

public CheckKnifeAccess(id, iMenu, iItem)
	return ((g_iKnife[id] == iItem) || !HasKnifeAccess(id, iItem)) ? ITEM_DISABLED : ITEM_ENABLED

public OnPlayerSpawn(id)
{
	if(is_user_alive(id) && get_pcvar_num(g_pAtSpawn) && !g_iKnife[id] && g_bFirstTime[id])
	{
		g_bFirstTime[id] = false
		ShowMenu(id)
	}
}

public OnSelectKnife(iEnt)
{
	new id = get_pdata_cbase(iEnt, m_pPlayer, 4)
	
	if(is_user_connected(id))
		RefreshKnifeModel(id)
}

RefreshKnifeModel(const id)
{
	set_pev(id, pev_viewmodel2, g_eKnife[id][V_MODEL])
	set_pev(id, pev_weaponmodel2, g_eKnife[id][P_MODEL])
}

PushKnife(eKnife[Knives])
{
	if(!eKnife[V_MODEL][0])
		copy(eKnife[V_MODEL], charsmax(eKnife[V_MODEL]), DEFAULT_V)
		
	if(!eKnife[P_MODEL][0])
		copy(eKnife[P_MODEL], charsmax(eKnife[P_MODEL]), DEFAULT_P)
		
	ArrayPushArray(g_aKnives, eKnife)
}

bool:HasKnifeAccess(const id, const iKnife)
{		
	static eKnife[Knives]
	ArrayGetArray(g_aKnives, iKnife, eKnife)
	
	if(g_bRankSystem)
	{
		if(eKnife[LEVEL] && crxranks_get_user_level(id) < eKnife[LEVEL])
			return false
			
		if(eKnife[XP] && crxranks_get_user_xp(id) < eKnife[XP])
			return false
	}
		
	if(eKnife[FLAG] != ADMIN_ALL && !(get_user_flags(id) & eKnife[FLAG]))
		return false
		
	return true
}

bool:IsKnifeSound(const szSample[])
	return bool:equal(szSample[8], "kni", 3)

DetectKnifeSound(const szSample[])
{
	static iSound
	iSound = SOUND_NONE
	
	if(equal(szSample, "weapons/knife_deploy1.wav"))
		iSound = SOUND_DEPLOY
	else if(equal(szSample[14], "hit", 3))
		iSound = szSample[17] == 'w' ? SOUND_HITWALL : SOUND_HIT
	else if(equal(szSample[14], "sla", 3))
		iSound = SOUND_SLASH
	else if(equal(szSample[14], "sta", 3))
		iSound = SOUND_STAB
		
	return iSound
}

UseVault(const id, const bool:bSave)
{
	if(bSave)
	{
		static szData[4]
		num_to_str(g_iKnife[id], szData, charsmax(szData))
		nvault_set(g_iVault, g_szAuth[id], szData)
	}
	else
	{
		static iKnife
		iKnife = nvault_get(g_iVault, g_szAuth[id])
		
		if(iKnife > g_iKnivesNum)
			iKnife = 0

		g_iKnife[id] = iKnife
		CheckKnifeOnConnect(id)
	}
}

public CheckKnifeOnConnect(id)
{
	if(g_iKnife[id])
	{
		if(_:HasKnifeAccess(id, g_iKnife[id]) == ITEM_ENABLED)
		{
			ArrayGetArray(g_aKnives, g_iKnife[id], g_eKnife[id])
			
			if(is_user_alive(id) && get_user_weapon(id) == CSW_KNIFE)
				RefreshKnifeModel(id)
		}
		else g_iKnife[id] = 0
	}
}

PlayKnifeSound(const id, const szSound[])
	engfunc(EngFunc_EmitSound, id, CHAN_AUTO, szSound, 1.0, ATTN_NORM, 0, PITCH_NORM)

Аватар
gil5587
Извън линия
Foreigner
Foreigner
Мнения: 72
Регистриран на: 01 Сеп 2018, 01:26
Се отблагодари: 77 пъти
Получена благодарност: 3 пъти

Knife Models [XP System Support]

Мнение от gil5587 » 09 Окт 2018, 00:38

F33L Th3 P0W3R. написа: 08 Окт 2018, 15:36
gil5587 написа: 08 Окт 2018, 01:24 How to add a way of opening the knife menu?
Like if pressing "g" it'll open it

Код за потвърждение: Избери целия код

#include <amxmodx>
#include <amxmisc>
#include <cromchat>
#include <fakemeta>
#include <hamsandwich>
#include <nvault>

native crxranks_get_max_levels()
native crxranks_get_rank_by_level(level, buffer[], len)
native crxranks_get_user_level(id)
native crxranks_get_user_xp(id)

new const g_szNatives[][] =
{
	"crxranks_get_max_levels",
	"crxranks_get_rank_by_level",
	"crxranks_get_user_level",
	"crxranks_get_user_xp"
}

#if !defined m_pPlayer
	#define m_pPlayer 41
#endif

#if defined client_disconnected
	#define client_disconnect client_disconnected
#endif

#define PLUGIN_VERSION "2.5.8"
#define DEFAULT_V "models/v_knife.mdl"
#define DEFAULT_P "models/p_knife.mdl"
#define MAX_SOUND_LENGTH 128
#define MAX_AUTHID_LENGTH 35

#if !defined MAX_NAME_LENGTH
	#define MAX_NAME_LENGTH 32
#endif

#if !defined MAX_PLAYERS
	#define MAX_PLAYERS 32
#endif

enum
{
	SOUND_NONE = 0,
	SOUND_DEPLOY,
	SOUND_HIT,
	SOUND_HITWALL,
	SOUND_SLASH,
	SOUND_STAB
}

enum _:Knives
{
	NAME[MAX_NAME_LENGTH],
	V_MODEL[MAX_SOUND_LENGTH],
	P_MODEL[MAX_SOUND_LENGTH],
	DEPLOY_SOUND[MAX_SOUND_LENGTH],
	HIT_SOUND[MAX_SOUND_LENGTH],
	HITWALL_SOUND[MAX_SOUND_LENGTH],
	SLASH_SOUND[MAX_SOUND_LENGTH],
	STAB_SOUND[MAX_SOUND_LENGTH],
	SELECT_SOUND[MAX_SOUND_LENGTH],
	FLAG,
	LEVEL,
	bool:SHOW_RANK,
	bool:HAS_CUSTOM_SOUND,
	XP
}

new Array:g_aKnives,
	bool:g_bFirstTime[MAX_PLAYERS + 1],
	bool:g_bRankSystem,
	bool:g_bGetLevel,
	bool:g_bGetXP,
	g_eKnife[MAX_PLAYERS + 1][Knives],
	g_szAuth[MAX_PLAYERS + 1][MAX_AUTHID_LENGTH],
	g_iKnife[MAX_PLAYERS + 1],
	g_iCallback,
	g_pAtSpawn,
	g_pSaveChoice,
	g_iSaveChoice,
	g_iKnivesNum,
	g_iVault

public plugin_init()
{
	register_plugin("Knife Models", PLUGIN_VERSION, "OciXCrom")
	register_cvar("CRXKnifeModels", PLUGIN_VERSION, FCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
	
	if(!g_iKnivesNum)
		set_fail_state("No knives found in the configuration file.")
	
	register_dictionary("KnifeModels.txt")
	
	RegisterHam(Ham_Spawn, "player", "OnPlayerSpawn", 1)
	register_forward(FM_EmitSound,	"OnEmitSound")
	RegisterHam(Ham_Item_Deploy, "weapon_knife", "OnSelectKnife", 1)
	
	register_clcmd("say /knife", "ShowMenu")
	register_clcmd("say_team /knife", "ShowMenu")
	register_clcmd("drop", "ShowMenu")
	
	g_iCallback = menu_makecallback("CheckKnifeAccess")
	g_pAtSpawn = register_cvar("km_open_at_spawn", "0")
	g_pSaveChoice = register_cvar("km_save_choice", "0")
}

public plugin_precache()
{
	if(LibraryExists("crxranks", LibType_Library))
		g_bRankSystem = true
		
	g_aKnives = ArrayCreate(Knives)
	ReadFile()
}

public plugin_cfg()
{
	g_iSaveChoice = get_pcvar_num(g_pSaveChoice)
	
	if(g_iSaveChoice)
		g_iVault = nvault_open("KnifeModels")
}

public plugin_natives()
	set_native_filter("native_filter")
	
public native_filter(const szNative[], id, iTrap)
{
	if(!iTrap)
	{
		static i
		
		for(i = 0; i < sizeof(g_szNatives); i++)
		{
			if(equal(szNative, g_szNatives[i]))
				return PLUGIN_HANDLED
		}
	}
	
	return PLUGIN_CONTINUE
}
	
public plugin_end()
{
	ArrayDestroy(g_aKnives)
	
	if(g_iSaveChoice)
		nvault_close(g_iVault)
}

ReadFile()
{
	new szConfigsName[256], szFilename[256]
	get_configsdir(szConfigsName, charsmax(szConfigsName))
	formatex(szFilename, charsmax(szFilename), "%s/KnifeModels.ini", szConfigsName)
	new iFilePointer = fopen(szFilename, "rt")
	
	if(iFilePointer)
	{
		new szData[160], szKey[32], szValue[128], szSound[128], iMaxLevels
		new eKnife[Knives], bool:bCustom
		
		if(g_bRankSystem)
			iMaxLevels = crxranks_get_max_levels()
		
		while(!feof(iFilePointer))
		{
			fgets(iFilePointer, szData, charsmax(szData))
			trim(szData)
			
			switch(szData[0])
			{
				case EOS, '#', ';': continue
				case '[':
				{
					if(szData[strlen(szData) - 1] == ']')
					{
						if(g_iKnivesNum)
							PushKnife(eKnife)
							
						g_iKnivesNum++
						replace(szData, charsmax(szData), "[", "")
						replace(szData, charsmax(szData), "]", "")
						copy(eKnife[NAME], charsmax(eKnife[NAME]), szData)
						
						eKnife[V_MODEL][0] = EOS
						eKnife[P_MODEL][0] = EOS
						eKnife[DEPLOY_SOUND][0] = EOS
						eKnife[HIT_SOUND][0] = EOS
						eKnife[HITWALL_SOUND][0] = EOS
						eKnife[SLASH_SOUND][0] = EOS
						eKnife[STAB_SOUND][0] = EOS
						eKnife[SELECT_SOUND][0] = EOS
						eKnife[FLAG] = ADMIN_ALL
						eKnife[HAS_CUSTOM_SOUND] = false
						
						if(g_bRankSystem)
						{
							eKnife[LEVEL] = 0
							eKnife[SHOW_RANK] = false
							eKnife[XP] = 0
						}
					}
					else continue
				}
				default:
				{
					strtok(szData, szKey, charsmax(szKey), szValue, charsmax(szValue), '=')
					trim(szKey); trim(szValue)
					bCustom = true
					
					if(equal(szKey, "FLAG"))
						eKnife[FLAG] = read_flags(szValue)
					else if(equal(szKey, "LEVEL") && g_bRankSystem)
					{
						eKnife[LEVEL] = clamp(str_to_num(szValue), 0, iMaxLevels)
						
						if(!g_bGetLevel)
							g_bGetLevel = true
					}
					else if(equal(szKey, "SHOW_RANK") && g_bRankSystem)
						eKnife[SHOW_RANK] = _:clamp(str_to_num(szValue), false, true)
					else if(equal(szKey, "XP") && g_bRankSystem)
					{
						eKnife[XP] = _:clamp(str_to_num(szValue), 0)
						
						if(!g_bGetXP)
							g_bGetXP = true
					}
					else if(equal(szKey, "V_MODEL"))
						copy(eKnife[V_MODEL], charsmax(eKnife[V_MODEL]), szValue)
					else if(equal(szKey, "P_MODEL"))
						copy(eKnife[P_MODEL], charsmax(eKnife[P_MODEL]), szValue)
					else if(equal(szKey, "DEPLOY_SOUND"))
						copy(eKnife[DEPLOY_SOUND], charsmax(eKnife[DEPLOY_SOUND]), szValue)
					else if(equal(szKey, "HIT_SOUND"))
						copy(eKnife[HIT_SOUND], charsmax(eKnife[HIT_SOUND]), szValue)
					else if(equal(szKey, "HITWALL_SOUND"))
						copy(eKnife[HITWALL_SOUND], charsmax(eKnife[HITWALL_SOUND]), szValue)
					else if(equal(szKey, "SLASH_SOUND"))
						copy(eKnife[SLASH_SOUND], charsmax(eKnife[SLASH_SOUND]), szValue)
					else if(equal(szKey, "STAB_SOUND"))
						copy(eKnife[STAB_SOUND], charsmax(eKnife[STAB_SOUND]), szValue)
					else if(equal(szKey, "SELECT_SOUND"))
					{
						bCustom = false
						copy(eKnife[SELECT_SOUND], charsmax(eKnife[SELECT_SOUND]), szValue)
					}
					else continue
					
					static const szModelArg[] = "_MODEL"
					static const szSoundArg[] = "_SOUND"
					
					if(contain(szKey, szModelArg) != -1)
					{
						if(!file_exists(szValue))
							log_amx("ERROR: model ^"%s^" not found!", szValue)
						else
							precache_model(szValue)
					}
					else if(contain(szKey, szSoundArg) != -1)
					{
						formatex(szSound, charsmax(szSound), "sound/%s", szValue)

						if(!file_exists(szSound))
							log_amx("ERROR: sound ^"%s^" not found!", szSound)
						else
							precache_sound(szValue)
						
						if(bCustom)
							eKnife[HAS_CUSTOM_SOUND] = true
					}
				}
			}
		}
		
		if(g_iKnivesNum)
			PushKnife(eKnife)
		
		fclose(iFilePointer)
	}
}

public client_connect(id)
{
	g_bFirstTime[id] = true
	ArrayGetArray(g_aKnives, 0, g_eKnife[id])
	g_iKnife[id] = 0
	
	if(g_iSaveChoice)
	{
		get_user_authid(id, g_szAuth[id], charsmax(g_szAuth[]))
		UseVault(id, false)
	}
}

public client_disconnect(id)
{
	if(g_iSaveChoice)
		UseVault(id, true)
}

public OnEmitSound(id, iChannel, const szSample[])
{
	if(!is_user_connected(id) || !g_eKnife[id][HAS_CUSTOM_SOUND] || !IsKnifeSound(szSample))
		return FMRES_IGNORED
	
	switch(DetectKnifeSound(szSample))
	{
		case SOUND_DEPLOY: 		if(g_eKnife[id][DEPLOY_SOUND][0]) 		{ PlayKnifeSound(id, g_eKnife[id][DEPLOY_SOUND][0]); 	return FMRES_SUPERCEDE; }
		case SOUND_HIT: 		if(g_eKnife[id][HIT_SOUND][0]) 			{ PlayKnifeSound(id, g_eKnife[id][HIT_SOUND][0]); 		return FMRES_SUPERCEDE; }
		case SOUND_HITWALL:		if(g_eKnife[id][HITWALL_SOUND][0]) 		{ PlayKnifeSound(id, g_eKnife[id][HITWALL_SOUND][0]); 	return FMRES_SUPERCEDE; }
		case SOUND_SLASH: 		if(g_eKnife[id][SLASH_SOUND][0]) 		{ PlayKnifeSound(id, g_eKnife[id][SLASH_SOUND][0]);		return FMRES_SUPERCEDE; }
		case SOUND_STAB: 		if(g_eKnife[id][STAB_SOUND][0]) 		{ PlayKnifeSound(id, g_eKnife[id][STAB_SOUND][0]); 		return FMRES_SUPERCEDE; }
	}
	
	return FMRES_IGNORED
}

public ShowMenu(id)
{
	static eKnife[Knives]
	new szTitle[128], szItem[128], iLevel, iXP
	formatex(szTitle, charsmax(szTitle), "%L", id, "KM_MENU_TITLE")

	if(g_bGetLevel)
		iLevel = crxranks_get_user_level(id)
	
	if(g_bGetXP)
		iXP = crxranks_get_user_xp(id)
		
	new iMenu = menu_create(szTitle, "MenuHandler")
	
	for(new iFlags = get_user_flags(id), i; i < g_iKnivesNum; i++)
	{
		ArrayGetArray(g_aKnives, i, eKnife)
		copy(szItem, charsmax(szItem), eKnife[NAME])
		
		if(g_bRankSystem)
		{
			if(eKnife[LEVEL] && iLevel < eKnife[LEVEL])
			{
				if(eKnife[SHOW_RANK])
				{
					static szRank[32]
					crxranks_get_rank_by_level(eKnife[LEVEL], szRank, charsmax(szRank))
					format(szItem, charsmax(szItem), "%s %L", szItem, id, "KM_MENU_RANK", szRank)
				}
				else
					format(szItem, charsmax(szItem), "%s %L", szItem, id, "KM_MENU_LEVEL", eKnife[LEVEL])
			}
			
			if(eKnife[XP] && iXP < eKnife[XP])
				format(szItem, charsmax(szItem), "%s %L", szItem, id, "KM_MENU_XP", eKnife[XP])
		}
		
		if(eKnife[FLAG] != ADMIN_ALL && !(iFlags & eKnife[FLAG]))
			format(szItem, charsmax(szItem), "%s %L", szItem, id, "KM_MENU_VIP_ONLY")
			
		if(g_iKnife[id] == i)
			format(szItem, charsmax(szItem), "%s %L", szItem, id, "KM_MENU_SELECTED")
		
		menu_additem(iMenu, szItem, eKnife[NAME], eKnife[FLAG], g_iCallback)
	}
	
	if(menu_pages(iMenu) > 1)
	{
		formatex(szItem, charsmax(szItem), "%s%L", szTitle, id, "KM_MENU_TITLE_PAGE")
		menu_setprop(iMenu, MPROP_TITLE, szItem)
	}
		
	menu_display(id, iMenu)
	return PLUGIN_HANDLED
}

public MenuHandler(id, iMenu, iItem)
{
	if(iItem != MENU_EXIT)
	{
		g_iKnife[id] = iItem
		ArrayGetArray(g_aKnives, iItem, g_eKnife[id])
		
		if(is_user_alive(id) && get_user_weapon(id) == CSW_KNIFE)
			RefreshKnifeModel(id)
		
		new szName[MAX_NAME_LENGTH], iUnused
		menu_item_getinfo(iMenu, iItem, iUnused, szName, charsmax(szName), .callback = iUnused)
		CC_SendMessage(id, "%L %L", id, "KM_CHAT_PREFIX", id, "KM_CHAT_SELECTED", szName)
		
		if(g_eKnife[id][SELECT_SOUND][0])
			PlayKnifeSound(id, g_eKnife[id][SELECT_SOUND])
	}
	
	menu_destroy(iMenu)
	return PLUGIN_HANDLED
}

public CheckKnifeAccess(id, iMenu, iItem)
	return ((g_iKnife[id] == iItem) || !HasKnifeAccess(id, iItem)) ? ITEM_DISABLED : ITEM_ENABLED

public OnPlayerSpawn(id)
{
	if(is_user_alive(id) && get_pcvar_num(g_pAtSpawn) && !g_iKnife[id] && g_bFirstTime[id])
	{
		g_bFirstTime[id] = false
		ShowMenu(id)
	}
}

public OnSelectKnife(iEnt)
{
	new id = get_pdata_cbase(iEnt, m_pPlayer, 4)
	
	if(is_user_connected(id))
		RefreshKnifeModel(id)
}

RefreshKnifeModel(const id)
{
	set_pev(id, pev_viewmodel2, g_eKnife[id][V_MODEL])
	set_pev(id, pev_weaponmodel2, g_eKnife[id][P_MODEL])
}

PushKnife(eKnife[Knives])
{
	if(!eKnife[V_MODEL][0])
		copy(eKnife[V_MODEL], charsmax(eKnife[V_MODEL]), DEFAULT_V)
		
	if(!eKnife[P_MODEL][0])
		copy(eKnife[P_MODEL], charsmax(eKnife[P_MODEL]), DEFAULT_P)
		
	ArrayPushArray(g_aKnives, eKnife)
}

bool:HasKnifeAccess(const id, const iKnife)
{		
	static eKnife[Knives]
	ArrayGetArray(g_aKnives, iKnife, eKnife)
	
	if(g_bRankSystem)
	{
		if(eKnife[LEVEL] && crxranks_get_user_level(id) < eKnife[LEVEL])
			return false
			
		if(eKnife[XP] && crxranks_get_user_xp(id) < eKnife[XP])
			return false
	}
		
	if(eKnife[FLAG] != ADMIN_ALL && !(get_user_flags(id) & eKnife[FLAG]))
		return false
		
	return true
}

bool:IsKnifeSound(const szSample[])
	return bool:equal(szSample[8], "kni", 3)

DetectKnifeSound(const szSample[])
{
	static iSound
	iSound = SOUND_NONE
	
	if(equal(szSample, "weapons/knife_deploy1.wav"))
		iSound = SOUND_DEPLOY
	else if(equal(szSample[14], "hit", 3))
		iSound = szSample[17] == 'w' ? SOUND_HITWALL : SOUND_HIT
	else if(equal(szSample[14], "sla", 3))
		iSound = SOUND_SLASH
	else if(equal(szSample[14], "sta", 3))
		iSound = SOUND_STAB
		
	return iSound
}

UseVault(const id, const bool:bSave)
{
	if(bSave)
	{
		static szData[4]
		num_to_str(g_iKnife[id], szData, charsmax(szData))
		nvault_set(g_iVault, g_szAuth[id], szData)
	}
	else
	{
		static iKnife
		iKnife = nvault_get(g_iVault, g_szAuth[id])
		
		if(iKnife > g_iKnivesNum)
			iKnife = 0

		g_iKnife[id] = iKnife
		CheckKnifeOnConnect(id)
	}
}

public CheckKnifeOnConnect(id)
{
	if(g_iKnife[id])
	{
		if(_:HasKnifeAccess(id, g_iKnife[id]) == ITEM_ENABLED)
		{
			ArrayGetArray(g_aKnives, g_iKnife[id], g_eKnife[id])
			
			if(is_user_alive(id) && get_user_weapon(id) == CSW_KNIFE)
				RefreshKnifeModel(id)
		}
		else g_iKnife[id] = 0
	}
}

PlayKnifeSound(const id, const szSound[])
	engfunc(EngFunc_EmitSound, id, CHAN_AUTO, szSound, 1.0, ATTN_NORM, 0, PITCH_NORM)
Works! ty very much.
Can you tell what you added/changed in the code? thx!

Аватар
1fRaNkkK
Извън линия
Потребител
Потребител
Мнения: 776
Регистриран на: 09 Окт 2016, 15:21
Се отблагодари: 8 пъти
Получена благодарност: 55 пъти

Knife Models [XP System Support]

Мнение от 1fRaNkkK » 09 Окт 2018, 00:57

@gil5587 you can use: https://www.diffchecker.com/
He added this line:

Код за потвърждение: Избери целия код

register_clcmd("drop", "ShowMenu")

Аватар
Maverick
Извън линия
Рекламатор
Рекламатор
Мнения: 254
Регистриран на: 22 Окт 2016, 17:05
Местоположение: 93.123.18.81:27017
Се отблагодари: 34 пъти
Получена благодарност: 14 пъти
Обратна връзка:

Knife Models [XP System Support]

Мнение от Maverick » 09 Яну 2019, 15:09

Здравейте има ли начин да се оправи това, че запаметяването по steam id да не работи дори и когато настройката е включена?
Преди бях писал и гледам че от тогава си направил промяна, но все още не работи като влезна отново в сървъра и пак съм си с стандартният нож.

Публикувай отговор
  • Подобни теми
    Отговори
    Преглеждания
     Последно мнение

Обратно към “Одобрени плъгини”

Кой е на линия

Потребители разглеждащи този форум: 0 регистрирани и 13 госта