I create nemesis plugin but not work [Help]

Coding Help/Re-API Supported
User avatar
Mohamed Alaa
Mod Developer
Mod Developer
Egypt
Posts: 624
Joined: 2 Years Ago
Location: Egypt
Has thanked: 34 times
Been thanked: 48 times
Age: 19
Contact:

Re: I create nemesis plugin but not work [Help]

#31

Post by Mohamed Alaa » 2 Days Ago

Wait for the next version..

[ Post made via Android ]
Want your own mod edition? PM me.
Accepting web projects.
CS 1.6 hosting: powergamingtech.com

User avatar
Mohamed Alaa
Mod Developer
Mod Developer
Egypt
Posts: 624
Joined: 2 Years Ago
Location: Egypt
Has thanked: 34 times
Been thanked: 48 times
Age: 19
Contact:

#32

Post by Mohamed Alaa » 14 Hours Ago

Updated:
1- Added ambience.
2- Bug fixes.
3- Added countdown.
4- Added "ze_nemesis" command to set a specific player a nemesis.

Code:

Code: Select all

#include <zombie_escape>

// Uncomment to use custom model for nemesis
// Note: This includes player model & claws
//#define USE_NEMESIS_MODEL

// Uncomment to use leap for nemesis
// Leap Code: https://escapers-zone.net/viewtopic.php?p=10582#p10582
//#define USE_NEMESIS_LEAP

#define TASK_MAKE_NEMESIS 4949849
#define TASK_AMBIENCESOUND 2020
#define TASK_REAMBIENCESOUND 5050

// Access to start nemesis round
#define STARTNEMESIS_ACCESS ADMIN_LEVEL_H

// Settings file
new const ZE_SETTING_FILE[] = "zombie_escape.ini"

#if defined USE_NEMESIS_MODEL
// Default models
new const g_szModels_Nemesis_Player[][] = { "ze_nemesis_host" }
new const g_szModels_Nemesis_Claws[][] = { "models/zombie_escape/v_knife_nemesis.mdl" }

new Array:g_aModels_Nemesis_Player,
	Array:g_aModels_Nemesis_Claws
#endif

#if defined USE_NEMESIS_LEAP
native ze_get_longjump(id)
native ze_remove_longjump(id)
#endif

enum _:Colors
{
	Red = 0,
	Green,
	Blue
}

new g_iAmbianceSoundDuration = 160	// Set ambience duration = highest sound duration
new const szAmbianceSound[][] = 
{
	"zombie_escape/ze_ambiance1.mp3"
}

new bool:g_bIsNemesis[33],
	bool:g_bIsNextRoundNemesis = false,
	g_iCountDown,
	Array:g_szAmbianceSound

new g_pCvarNemesisHP,
	g_pCvarNemesisGravity,
	g_pCvarNemesisSpeed,
	g_pCvarNemesisGlow,
	g_pCvarNemesisGlowColor[Colors],
	g_pCvarNemesisKB,
	g_pCvarNemesisDmg,
	g_pCvarNemesisFreeze,
	g_pCvarNemesisFire

public plugin_natives()
{
	register_native("ze_is_user_nemesis", "native_ze_is_user_nemesis", 1)
	register_native("ze_set_user_nemesis", "native_ze_set_user_nemesis", 1)
}

public plugin_precache()
{
	g_szAmbianceSound = ArrayCreate(64, 1)
	amx_load_setting_string_arr(ZE_SETTING_FILE, "Sounds", "Nemesis Round Ambiance", g_szAmbianceSound)

	new iIndex, szSound[64]
	if (ArraySize(g_szAmbianceSound) == 0)
	{
		for (iIndex = 0; iIndex < sizeof szAmbianceSound; iIndex++)
			ArrayPushString(g_szAmbianceSound, szAmbianceSound[iIndex])
		
		// Save to external file
		amx_save_setting_string_arr(ZE_SETTING_FILE, "Sounds", "Nemesis Round Ambiance", g_szAmbianceSound)
	}

	for (iIndex = 0; iIndex < ArraySize(g_szAmbianceSound); iIndex++)
	{
		ArrayGetString(g_szAmbianceSound, iIndex, szSound, charsmax(szSound))
		
		if (equal(szSound[strlen(szSound)-4], ".mp3"))
		{
			format(szSound, charsmax(szSound), "sound/%s", szSound)
			precache_generic(szSound)
		}
		else
		{
			precache_sound(szSound)
		}
	}

	#if defined USE_NEMESIS_MODEL
		// Initialize arrays
		g_aModels_Nemesis_Player = ArrayCreate(32, 1)
		g_aModels_Nemesis_Claws = ArrayCreate(64, 1)
		
		// Load from external file
		amx_load_setting_string_arr(ZE_SETTING_FILE, "Player Models", "NEMESIS MODEL", g_aModels_Nemesis_Player)
		amx_load_setting_string_arr(ZE_SETTING_FILE, "Weapon Models", "V_KNIFE NEMESIS", g_aModels_Nemesis_Claws)
		
		// If we couldn't load from file, use and save default ones
		if (ArraySize(g_aModels_Nemesis_Player) == 0)
		{
			for (iIndex = 0; iIndex < sizeof g_szModels_Nemesis_Player; iIndex++)
				ArrayPushString(g_aModels_Nemesis_Player, g_szModels_Nemesis_Player[iIndex])
			
			// Save to external file
			amx_save_setting_string_arr(ZE_SETTING_FILE, "Player Models", "NEMESIS", g_aModels_Nemesis_Player)
		}

		if (ArraySize(g_aModels_Nemesis_Claws) == 0)
		{
			for (iIndex = 0; iIndex < sizeof g_szModels_Nemesis_Claws; iIndex++)
				ArrayPushString(g_aModels_Nemesis_Claws, g_szModels_Nemesis_Claws[iIndex])
			
			// Save to external file
			amx_save_setting_string_arr(ZE_SETTING_FILE, "Weapon Models", "V_KNIFE NEMESIS", g_aModels_Nemesis_Claws)
		}
		
		// Precache models
		new player_model[32], model[64], model_path[128]

		for (iIndex = 0; iIndex < ArraySize(g_aModels_Nemesis_Player); iIndex++)
		{
			ArrayGetString(g_aModels_Nemesis_Player, iIndex, player_model, charsmax(player_model))
			formatex(model_path, charsmax(model_path), "models/player/%s/%s.mdl", player_model, player_model)
			precache_model(model_path)
			// Support modelT.mdl files
			formatex(model_path, charsmax(model_path), "models/player/%s/%sT.mdl", player_model, player_model)
			if (file_exists(model_path)) precache_model(model_path)
		}

		for (iIndex = 0; iIndex < ArraySize(g_aModels_Nemesis_Claws); iIndex++)
		{
			ArrayGetString(g_aModels_Nemesis_Claws, iIndex, model, charsmax(model))
			precache_model(model)
		}
	#endif
}

public plugin_init()
{
	register_plugin("[ZE] Addons: Nemesis", "2.0", "Jack")

	RegisterHam(Ham_TakeDamage, "player", "Fw_TakeDamage")

	register_clcmd("ze_start_nemesis_next", "cmd_start_nemesis", STARTNEMESIS_ACCESS)
	register_concmd("ze_nemesis", "cmd_nemsis", STARTNEMESIS_ACCESS)

	g_pCvarNemesisHP = register_cvar("ze_nemesis_hp", "20000")	// Nemesis health - Set 0 to use zombie HP
	g_pCvarNemesisGravity = register_cvar("ze_nemesis_gravity", "600")	// Nemesis gravity - Set 0 to use zombie gravity
	g_pCvarNemesisSpeed = register_cvar("ze_nemesis_speed", "300")	// Nemesis speed - Set 0 to use zombie speed
	g_pCvarNemesisGlow = register_cvar("ze_nemesis_glow", "1")	// Nemesis glow - 1 = enable | 0 = disable
	g_pCvarNemesisGlowColor[Red] = register_cvar("ze_nemesis_glow_r", "255")	// Nemesis glow color RED
	g_pCvarNemesisGlowColor[Green] = register_cvar("ze_nemesis_glow_g", "255")	// Nemesis glow color GREEN
	g_pCvarNemesisGlowColor[Blue] = register_cvar("ze_nemesis_glow_b", "255")	// Nemesis glow color BLUE
	g_pCvarNemesisKB = register_cvar("ze_nemesis_kb", "200.0")	// Nemesis knockback - Set 0 to use zombie knockback
	g_pCvarNemesisDmg = register_cvar("ze_nemesis_dmg", "200.0")	// Nemesis damage
	g_pCvarNemesisFreeze = register_cvar("ze_nemesis_freeze", "0")	// Nemesis get frozen? - 1 = doesn't get frozen | 0 = gets frozen
	g_pCvarNemesisFire = register_cvar("ze_nemesis_fire", "1")	// Nemesis set on fire? - 1 = doesn't set on fire | 0 = set on fire
}

public client_disconnected(id)
{
	if (g_bIsNemesis[id])
	{
		new szPlayerName[2][32], iNewNemId
		get_user_name(id, szPlayerName[0], charsmax(szPlayerName))
		iNewNemId = GetRandomNemesis()
		get_user_name(iNewNemId, szPlayerName[1], charsmax(szPlayerName))
		g_bIsNemesis[id] = false
		Set_Nemesis(iNewNemId)
		ze_colored_print(0, "!g%s !thas left !n& !g%s !thas become nemesis!n.", szPlayerName[0], szPlayerName[1])
	}
}

public client_putinserver(id)
{
	if (g_bIsNemesis[id])
		g_bIsNemesis[id] = false
}

public ze_user_infected_pre(iVictim, iAttacker)
{
	if (g_bIsNemesis[iAttacker] && !ze_is_user_zombie(iVictim))
	{
		SendDeathMsg(iAttacker, iVictim)
		return 1
	}

	return 0
}

public Fw_TakeDamage(iVictim, iInfector, iAttacker, Float:iDamage)
{
	if (iVictim == iAttacker || !is_user_alive(iAttacker))
		return HAM_IGNORED

	if (g_bIsNemesis[iAttacker] && !ze_is_user_zombie(iVictim) && iInfector == iAttacker)
	{
		SetHamParamFloat(4, iDamage * get_pcvar_float(g_pCvarNemesisDmg))
		return HAM_HANDLED
	}

	return HAM_IGNORED
}

public ze_fire_pre(id)
{
	if (g_bIsNemesis[id] && get_pcvar_num(g_pCvarNemesisFire))
		return PLUGIN_HANDLED
	return PLUGIN_CONTINUE
}

public ze_frost_pre(id)
{
	if (g_bIsNemesis[id] && get_pcvar_num(g_pCvarNemesisFreeze))
		return PLUGIN_HANDLED
	return PLUGIN_CONTINUE
}

public ze_user_humanized(id)
{
	UnSet_Nemesis(id)
}

public ze_roundend()
{
	for (new id = 0; id <= get_member_game(m_nMaxPlayers); id++)
	{
		if (is_user_alive(id) && g_bIsNemesis[id])
			UnSet_Nemesis(id)
	}
}

public ze_game_started_pre()
{
	if (get_playersnum())
	{
		if (g_bIsNextRoundNemesis)
		{
			g_bIsNextRoundNemesis = false
			g_iCountDown = 5
			set_task(1.0, "StartNemesis", TASK_MAKE_NEMESIS, _, _, "b")
			// Remove Tasks (Again as somehow may it not removed at the roundend)
			remove_task(TASK_AMBIENCESOUND)
			remove_task(TASK_REAMBIENCESOUND)
			set_task(3.0, "AmbianceSound", TASK_AMBIENCESOUND)
			return PLUGIN_HANDLED
		}
	}
	else
		ze_colored_print(0, "!gThe server doesn't have enough players to start nemesis round !n(!tat least 1!n)!n.")

	return PLUGIN_CONTINUE
}

public AmbianceSound()
{
	// Stop All Sounds
	StopSound()
	
	// Play The Ambiance Sound For All Players
	new szSound[64]
	ArrayGetString(g_szAmbianceSound, random_num(0, ArraySize(g_szAmbianceSound) - 1), szSound, charsmax(szSound))
	
	for (new id = 1; id <= get_member_game(m_nMaxPlayers); id++)
	{
		if (!is_user_connected(id))
			continue

		PlaySound(id, szSound)
	}

	// We should Set Task back again to replay (Repeated 5 times MAX)
	set_task(float(g_iAmbianceSoundDuration), "AmbianceSound", TASK_REAMBIENCESOUND, _, _, "a", 5)
}

public StartNemesis(taskid)
{
	if (!g_iCountDown)
	{
		Set_Nemesis(GetRandomNemesis())
		remove_task(taskid)
		return
	}

	set_hudmessage(random(256), random(256), random(256), -1.0, 0.21, 0, 0.8, 0.8)
	show_hudmessage(0, "Nemesis starts in %d second(s).", g_iCountDown--)
}

public cmd_start_nemesis(id, level, cid)
{
	if (!cmd_access(id, STARTNEMESIS_ACCESS, cid, 0))
	{
		client_print(id, print_console, "You have not access.")
		return PLUGIN_HANDLED
	}
	
	g_bIsNextRoundNemesis = true
	client_print(id, print_console, "Nemesis round will start next round.")
	return PLUGIN_HANDLED
}

public cmd_zombie(id, level, cid)
{
	if (!cmd_access(id, STARTNEMESIS_ACCESS, cid, 0))
	{
		client_print(id, print_console, "You have not access.")
		return PLUGIN_HANDLED
	}
	
	// Retrieve arguments
	new arg[32], player
	read_argv(1, arg, charsmax(arg))
	player = cmd_target(id, arg, (CMDTARGET_ONLY_ALIVE | CMDTARGET_ALLOW_SELF))
	
	// Invalid target
	if (!player || !is_user_alive(player))
	{
		ze_colored_print(id, "Invalid player.")
		return PLUGIN_HANDLED
	}
	
	// Target not allowed to be nemesis
	if (g_bIsNemesis[player])
	{
		new player_name[32]
		get_user_name(player, player_name, charsmax(player_name))
		client_print(id, print_console, "[ZE] %s is already nemesis.", player_name)
		return PLUGIN_HANDLED
	}
	
	Set_Nemesis(player)
	return PLUGIN_HANDLED
}

public Set_Nemesis(id)
{
	g_bIsNemesis[id] = true

	if (!ze_is_user_zombie(id))
		ze_set_user_zombie(id)

	#if defined USE_NEMESIS_LEAP
		ze_get_longjump(id)
	#endif

	#if defined USE_NEMESIS_MODEL
		new szPlayerModel[32], szModel[64]
		ArrayGetString(g_aModels_Nemesis_Player, random_num(0, ArraySize(g_aModels_Nemesis_Player) - 1), szPlayerModel, charsmax(szPlayerModel))
		cs_set_user_model(id, szPlayerModel)

		ArrayGetString(g_aModels_Nemesis_Claws, random_num(0, ArraySize(g_aModels_Nemesis_Claws) - 1), szModel, charsmax(szModel))
		cs_set_player_view_model(id, CSW_KNIFE, szModel)
	#endif
	
	if (get_pcvar_float(g_pCvarNemesisHP))
	{
		set_entvar(id, var_health, get_pcvar_float(g_pCvarNemesisHP))
	}

	if (get_pcvar_num(g_pCvarNemesisSpeed))
	{
		ze_set_zombie_speed(id, get_pcvar_num(g_pCvarNemesisSpeed))
	}

	if (get_pcvar_num(g_pCvarNemesisGravity))
	{
		ze_set_user_gravity(id, get_pcvar_num(g_pCvarNemesisGravity))
	}

	if (get_pcvar_num(g_pCvarNemesisKB))
	{
		ze_set_user_knockback(id, get_pcvar_float(g_pCvarNemesisKB))
	}

	if (get_pcvar_num(g_pCvarNemesisGlow))
	{
		Set_Rendering(id, kRenderFxNone, 255, 0, 0, kRenderNormal, 15)
	}

	new szName[32]
	get_user_name(id, szName, charsmax(szName))
	set_hudmessage(255, 0, 0, -1.0, 0.21, 0, 0.0, 5.0, 0.1, 1.5)
	show_hudmessage(id, "%s became Nemesis", szName)
	ze_colored_print(0, "!g%s !tbecame !gNemesis!n.", szName)
	ze_colored_print(id, "!gYou !tbecame !gNemesis!n.")
}

public UnSet_Nemesis(id)
{
	if (!g_bIsNemesis[id] || !is_user_alive(id))
		return

	g_bIsNemesis[id] = false

	#if defined USE_NEMESIS_LEAP
		ze_remove_longjump(id)
	#endif

	if (get_pcvar_num(g_pCvarNemesisSpeed))
	{
		ze_reset_zombie_speed(id)
	}

	if (get_pcvar_num(g_pCvarNemesisGravity))
	{
		ze_reset_user_gravity(id)
	}

	if (get_pcvar_num(g_pCvarNemesisKB))
	{
		ze_reset_user_knockback(id)
	}

	if (get_pcvar_num(g_pCvarNemesisGlow))
	{
		Set_Rendering(id)
	}
}

public GetRandomNemesis()
{
	if (get_playersnum())
	{
		new iPlayers[32], iSelected[33], iCount = 0, iTotalPlayers, id
		get_players(iPlayers, iTotalPlayers)

		for (new i = 0; i < iTotalPlayers; i++)
		{
			id = iPlayers[i]

			if (is_user_alive(id) && !g_bIsNemesis[id])
			{
				iSelected[iCount++] = id
			}
		}

		return iSelected[random(--iCount)]
	}

	return 0
}

public native_ze_is_user_nemesis(id)
{
	if (!is_user_connected(id))
	{
		log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
		return -1
	}

	return g_bIsNemesis[id]
}

public native_ze_set_user_nemesis(id, bool:set)
{
	if (!is_user_connected(id))
	{
		log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player id (%d)", id)
		return false
	}

	if (set)
	{
		if (!g_bIsNemesis[id])
			Set_Nemesis(id)
	}
	else
	{
		if (g_bIsNemesis[id])
			UnSet_Nemesis(id)
	}

	return true
}
Want your own mod edition? PM me.
Accepting web projects.
CS 1.6 hosting: powergamingtech.com

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest