Resolved new hero

Unpaid Requests, Public Plugins
Post Reply
czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 525
Joined: 2 Years Ago
Has thanked: 19 times
Been thanked: 1 time
Contact:

new hero

#1

Post by czirimbolo » 4 Months Ago

Raheem or Jack, can you convert this to our mod and add MULTIJUMP and speed value 380?

Code: Select all

#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>
#include <xs>
#include <zombieplague>

#if (AMXX_VERSION_NUM < 183)
#include <dhudmessage>
#endif

#define PLUGIN_NAME				"[ZP] Addon: Hero"
#define PLUGIN_VERSION			"1.0"
#define PLUGIN_AUTHOR			"Batcon"

#define BIT_VALID(%0,%1)	(%0 & (1<<(%1 & 31)))
#define BIT_ADD(%0,%1)		(%0 |= (1<<(%1 & 31)))
#define BIT_SUB(%0,%1)		(%0 &= ~(1<<(%1 & 31)))
#define BIT_INVERT(%0,%1)	(%0 ^= (1<<(%1 & 31)))
#define IsNullEnt(%0)		(%0 == -1 || %0 == 0)
#define IsValidEnt(%0)		(!IsNullEnt(%0) && pev_valid(%0))

#define FILE_HERO_SETTING	"zp_hero.ini"
#define FILE_HERO_LANG		"zp_hero.txt"

#define HUD_NOTICE_X 	0.6
#define HUD_NOTICE_Y 	0.5
#define HUD_NOTICE_C 	0, 155, 200
#define HUD_NOTICE_T	2.0

new const MAXBPAMMO[] = { -1, 52, -1, 90, 1, 32, 1, 100, 90, 1, 120, 100, 100, 90, 90, 90, 100, 120,
			30, 120, 200, 32, 90, 120, 90, 2, 35, 90, 90, -1, 100 }				
		
#define SLOT_PRIMARY	1
#define SLOT_SECONDARY	2
#define SLOT_KNIFE 		3
#define SLOT_GRENADE 	4
#define SLOT_C4			5

#define MAX_CLIENTS		32
#define TASK_ICON_ID	64
#define TASK_ICON_DELAY	0.3	
#define TASK_AURA_ID	96
#define TASK_AURA_DELAY	0.1	

#define AURA_RADIUS	20	

// Linux extra offset
#define OFFSET_LINUX_WEAPON		4
#define OFFSET_LINUX_PLAYER		5

// CBasePlayerItem
#define m_pPlayer 			41
#define m_pNext				42
#define m_iId				43

// CBasePlayer
#define m_rpgPlayerItems		367

new g_BitUserHero;
new g_sHeroModel[32];
new g_iHeroBody;
new g_iHeroArmor;
new g_iHeroHealth;
new Array:g_aHeroWeapons;
new g_iHeroMinPlayers;
new Array:g_aHeroes;
new g_sHeroModelIcon;

public plugin_init()
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
	RegisterHam(Ham_Spawn, "player", "CBasePlayer_Spawn_Post", true);
	RegisterHam(Ham_Killed, "player", "CBasePlayer_Killed_Post", true);
	RegisterHam(Ham_Touch, "weaponbox", "CWeaponBox_Touch", false);
	register_dictionary(FILE_HERO_LANG);
	register_clcmd("drop", "ClientCmd_Drop");
}
public plugin_cfg()
{
	g_aHeroWeapons = ArrayCreate(32,1);
	g_aHeroes = ArrayCreate(1,1);
	SettingsFile_Load();
}
public plugin_natives()
{
	register_native("zp_is_user_hero", "native_is_user_hero", 1);
	register_native("zp_make_user_hero", "native_make_user_hero", 1);
}
public native_is_user_hero(pPlayer)
{
	return BIT_VALID(g_BitUserHero, pPlayer);
}
public native_make_user_hero(pPlayer)
{
	if(!is_user_alive(pPlayer))
		return 0;
	if(zp_get_user_zombie(pPlayer))
		return 0;
	if(zp_get_user_survivor(pPlayer))
		return 0;
	MakeUserHero(pPlayer);
	return 1;
}

#if (AMXX_VERSION_NUM < 183)
public client_disconnect(pPlayer)
#else
public client_disconnected(pPlayer)
#endif
{
	RemoveUserHero(pPlayer);
	remove_task(pPlayer + TASK_ICON_ID);
}
public CBasePlayer_Spawn_Post(pPlayer)
{
	if(!BIT_VALID(g_BitUserHero, pPlayer))
		return;

	RemoveUserHero(pPlayer);
		
	CS_RemoveItemsBySlot(pPlayer, SLOT_PRIMARY);
	CS_RemoveItemsBySlot(pPlayer, SLOT_SECONDARY);
	CS_RemoveItemsBySlot(pPlayer, SLOT_GRENADE);
	CS_RemoveItemsBySlot(pPlayer, SLOT_C4);
}
public CBasePlayer_Killed_Post(pVictim, pAttacker, Gibs)
{
	RemoveUserHero(pVictim);
	remove_task(pVictim + TASK_ICON_ID);
}
public CWeaponBox_Touch(pWeaponBox, pPlayer)
{
	if(!is_user_alive(pPlayer))
		return HAM_IGNORED;
	if(!BIT_VALID(g_BitUserHero, pPlayer))
		return HAM_IGNORED;
	return HAM_SUPERCEDE;
}
public ClientCmd_Drop(pPlayer)
{
	if(BIT_VALID(g_BitUserHero, pPlayer))
		return PLUGIN_HANDLED;
	return PLUGIN_CONTINUE;
}
public zp_user_humanized_pre(pPlayer)
{
	if(!BIT_VALID(g_BitUserHero, pPlayer))
		return;

	RemoveUserHero(pPlayer);
		
	CS_RemoveItemsBySlot(pPlayer, SLOT_PRIMARY);
	CS_RemoveItemsBySlot(pPlayer, SLOT_SECONDARY);
	CS_RemoveItemsBySlot(pPlayer, SLOT_GRENADE);
	CS_RemoveItemsBySlot(pPlayer, SLOT_C4);
}
public zp_user_humanized_post(pPlayer, bSurvivor)
{
	RemoveUserHero(pPlayer);
	remove_task(pPlayer + TASK_ICON_ID);

	if(bSurvivor)
		return;
	
	if(zp_has_round_started() && ArraySize(g_aHeroes))
		set_task(TASK_ICON_DELAY, "Task_Client_DrawIcons", pPlayer + TASK_ICON_ID, _, _, "b");
}
public zp_user_infected_post(pPlayer)
{
	RemoveUserHero(pPlayer);
	remove_task(pPlayer + TASK_ICON_ID);
}
public zp_round_started(GameModeID)
{
	if(GameModeID != MODE_INFECTION)
		return;

	new Players[MAX_CLIENTS], iPlayersNum; 
	get_players(Players, iPlayersNum, "a");
	
	if(iPlayersNum < g_iHeroMinPlayers)
		return;

	new Humans[MAX_CLIENTS], iHumansNum;
	new pPlayer;

	for(new i; i < iPlayersNum; i++)
	{
		pPlayer = Players[i];
		if(zp_get_user_zombie(pPlayer) || BIT_VALID(g_BitUserHero, pPlayer))
			continue;

		Humans[iHumansNum] = pPlayer;
		iHumansNum++;
	}

	if(!iHumansNum)
		return;

	new pHero = Humans[random(iHumansNum)];
	MakeUserHero(pHero);
	
	new szUserName[32]; get_user_name(pHero, szUserName, charsmax(szUserName));
	set_dhudmessage(HUD_NOTICE_C, HUD_NOTICE_X, HUD_NOTICE_Y, 0, 0.0, HUD_NOTICE_T, 1.0, 0.1);
	show_dhudmessage(0, "%L", LANG_PLAYER, "NOTICE_HERO", szUserName);
	
	if(ArraySize(g_aHeroes))
	{
		for(new i; i < iHumansNum; i++)
		{
			pPlayer = Humans[i];

			if(BIT_VALID(g_BitUserHero, pPlayer))
				continue;

			set_task(TASK_ICON_DELAY, "Task_Client_DrawIcons", pPlayer + TASK_ICON_ID, _, _, "b");
		}
	}
}
public Task_Client_DrawIcons(pPlayer)
{
	pPlayer -= TASK_ICON_ID;

	static pHero;
	static Float:vIcon[3];
	static Float:vSrc[3];
	static Float:vViewOfs[3];
	static Float:vEnd[3];
	static Float:vDir[3];
	static Float:vEndPos[3];
	static Float:fDistToWall;
	static Float:fDistToHero;
	static Float:fScal;
	static Float:fFraction;
	static iTrace;

	iTrace = create_tr2();
	pev(pPlayer, pev_origin, vSrc);
	pev(pPlayer, pev_view_ofs, vViewOfs);
	xs_vec_add(vSrc, vViewOfs, vSrc);

	for(new i = 0; i < ArraySize(g_aHeroes); i++)
	{
		pHero = ArrayGetCell(g_aHeroes, i);
		pev(pHero, pev_origin, vEnd);
		xs_vec_sub(vEnd, vSrc, vDir);

		engfunc(EngFunc_TraceLine, vSrc, vEnd, IGNORE_MONSTERS, 0, iTrace);
		get_tr2(iTrace, TR_flFraction, fFraction);
		fDistToHero = get_distance_f(vSrc, vEnd);

		get_tr2(iTrace, TR_vecEndPos, vEndPos);

		fDistToWall = get_distance_f(vSrc, vEndPos) - 10.0;

		if(fFraction == 1.0)
		{
			if(fDistToHero < 256.0)
				continue;

			fDistToWall -= 30.0;
		}

		xs_vec_normalize(vDir, vDir);
		xs_vec_mul_scalar(vDir, fDistToWall, vIcon);
		xs_vec_add(vIcon, vSrc, vIcon);
			
		fScal = 1.0 + fDistToWall / fDistToHero

		if(fFraction == 1.0)
			vIcon[2] += 36.0;
			
		message_begin(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, _, pPlayer); 
		write_byte(TE_SPRITE);
		engfunc(EngFunc_WriteCoord, vIcon[0]); 
		engfunc(EngFunc_WriteCoord, vIcon[1]); 
		engfunc(EngFunc_WriteCoord, vIcon[2]); 
		write_short(g_sHeroModelIcon);
		write_byte(floatround(fScal));
		write_byte(125);
		message_end() ;
	}
	free_tr2(iTrace);
}
public Task_Hero_Aura(pPlayer)
{
	pPlayer -= TASK_AURA_ID;

	static origin[3]; get_user_origin(pPlayer, origin);
	message_begin(MSG_PVS, SVC_TEMPENTITY, origin);
	write_byte(TE_DLIGHT); 
	write_coord(origin[0]); 
	write_coord(origin[1]);
	write_coord(origin[2]);
	write_byte(AURA_RADIUS);
	write_byte(128);
	write_byte(128);
	write_byte(128);
	write_byte(2);
	write_byte(0);
	message_end();
}

public MakeUserHero(pPlayer)
{
	RemoveUserHero(pPlayer);

	CS_RemoveItemsBySlot(pPlayer, SLOT_PRIMARY);
	CS_RemoveItemsBySlot(pPlayer, SLOT_SECONDARY);
	CS_RemoveItemsBySlot(pPlayer, SLOT_GRENADE);
	CS_RemoveItemsBySlot(pPlayer, SLOT_C4);
	
	BIT_ADD(g_BitUserHero, pPlayer);
	ArrayPushCell(g_aHeroes, pPlayer);

	set_pev(pPlayer, pev_health, float(g_iHeroHealth));
	set_pev(pPlayer, pev_max_health, float(g_iHeroHealth));
	cs_set_user_armor(pPlayer, g_iHeroArmor, CS_ARMOR_KEVLAR);
	zp_override_user_model(pPlayer, g_sHeroModel, true);
	set_pev(pPlayer, pev_body, g_iHeroBody);

	for(new i, szWeaponName[32], iId; i < ArraySize(g_aHeroWeapons); i++)
	{
		ArrayGetString(g_aHeroWeapons, i, szWeaponName, charsmax(szWeaponName));
		if((iId = zp_get_extra_item_id(szWeaponName)) != -1)
			zp_force_buy_extra_item(pPlayer, iId, true);
		else if((iId = get_weaponid(szWeaponName)) > 0)
			CS_GiveWeapon(pPlayer, szWeaponName, true);
	}

	set_task(TASK_AURA_DELAY, "Task_Hero_Aura", pPlayer + TASK_AURA_ID, _, _, "b");
}
public RemoveUserHero(pPlayer)
{
	if(!BIT_VALID(g_BitUserHero, pPlayer))
		return;

	BIT_SUB(g_BitUserHero, pPlayer);

	for(new i = 0; i < ArraySize(g_aHeroes); i++)
	{
		if(ArrayGetCell(g_aHeroes, i) == pPlayer)
		{
			ArrayDeleteItem(g_aHeroes, i);
			break;
		}
	}

	remove_task(pPlayer + TASK_AURA_ID);
}

public SettingsFile_Load()
{
	new szDirPath[64];
	get_localinfo("amxx_configsdir", szDirPath, charsmax(szDirPath));
	format(szDirPath, charsmax(szDirPath), "%s/%s", szDirPath, FILE_HERO_SETTING);
	
	if(!file_exists(szDirPath))
	{
		new szError[100];
		formatex(szError, charsmax(szError), "| File '%s' not found.", szDirPath);
		set_fail_state(szError);
		return;
	}
	
	new szBuffer[1024], szKey[64], szValue[960];
	new iFile = fopen(szDirPath, "rt");
	
	while(iFile && !feof(iFile))
	{
		fgets(iFile, szBuffer, charsmax(szBuffer));
	   
		if(!szBuffer[0] || szBuffer[0] == '/' || szBuffer[0] == ';') 
			continue;

		strtok(szBuffer, szKey, charsmax(szKey), szValue, charsmax(szValue), '=');
		trim(szKey);
		trim(szValue);
		
		if(equal(szKey, "HERO MODEL"))
		{
			copy(g_sHeroModel, charsmax(g_sHeroModel), szValue);
			new szModel[96]; format(szModel, charsmax(szModel), "models/player/%s/%s.mdl", szValue, szValue);
			engfunc(EngFunc_PrecacheModel, szModel);
		}
		else if(equal(szKey, "HERO BODY"))
		{
			g_iHeroBody = str_to_num(szValue);
		}
		else if(equal(szKey, "HERO ARMOR"))
		{
			g_iHeroArmor = str_to_num(szValue);
		}
		else if(equal(szKey, "HERO HEALTH"))
		{
			g_iHeroHealth = str_to_num(szValue);
		}
		else if(equal(szKey, "HERO WEAPONS"))
		{
			while (szValue[0] != 0 && strtok(szValue, szKey, charsmax(szKey), szValue, charsmax(szValue), ','))
			{
				trim(szKey)
				trim(szValue)
				ArrayPushString(g_aHeroWeapons, szKey);
			}
		}
		else if(equal(szKey, "HERO ICON"))
		{
			g_sHeroModelIcon = engfunc(EngFunc_PrecacheModel, szValue);
		}
		else if(equal(szKey, "HERO MIN PLAYERS"))
		{
			g_iHeroMinPlayers = str_to_num(szValue);
		}
	}
	if(iFile) 
		fclose(iFile);
}
stock CS_GiveWeapon(pPlayer, szWeaponName[], bool:bGiveAmmo = false)
{
	new pItem = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, szWeaponName));
	if(!pev_valid(pItem))
		return 0;

	ExecuteHamB(Ham_Spawn, pItem);

	if(!ExecuteHamB(Ham_AddPlayerItem, pPlayer, pItem))
	{
		set_pev(pItem, pev_flags, FL_KILLME);
		return 0;
	}

	ExecuteHamB(Ham_Item_AttachToPlayer, pItem, pPlayer);
	emit_sound(pPlayer, CHAN_ITEM, "items/gunpickup2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);

	if(bGiveAmmo)
	{
		new iId = cs_get_weapon_id(pItem);
		if(MAXBPAMMO[iId] != -1)
			cs_set_user_bpammo(pPlayer, iId, MAXBPAMMO[iId]);
	}

	return pItem;
}
stock CS_DropItemsBySlot(pPlayer, iSlot)
{
	new pItem = get_pdata_cbase(pPlayer, m_rpgPlayerItems + iSlot, OFFSET_LINUX_PLAYER);

	if(IsNullEnt(pItem))
		return;

	new pNext;
	new szWeaponName[28];

	do
	{
		pNext = get_pdata_cbase(pItem, m_pNext, OFFSET_LINUX_WEAPON);
		if(get_weaponname(get_pdata_int(pItem, m_iId, OFFSET_LINUX_WEAPON), szWeaponName, charsmax(szWeaponName)))  
			engclient_cmd(pPlayer, "drop", szWeaponName);
	}
	while((pItem = pNext) > 0)
}
stock CS_RemoveItemsBySlot(pPlayer, iSlot)
{
	new pItem = get_pdata_cbase(pPlayer, m_rpgPlayerItems + iSlot, OFFSET_LINUX_PLAYER);

	if(IsNullEnt(pItem))
		return;

	new pNext;
	new iId;

	do
	{
		pNext = get_pdata_cbase(pItem, m_pNext, OFFSET_LINUX_WEAPON);
		iId = get_pdata_int(pItem, m_iId, OFFSET_LINUX_WEAPON);

		if(get_user_weapon(pPlayer) == iId) 
			ExecuteHamB(Ham_Weapon_RetireWeapon, pItem);

		ExecuteHamB(Ham_RemovePlayerItem, pPlayer, pItem);
		ExecuteHamB(Ham_Item_Kill, pItem);
		set_pev(pPlayer, pev_weapons, pev(pPlayer, pev_weapons) & ~(1<<iId));

		cs_set_user_bpammo(pPlayer, iId, 0);
	}
	while((pItem = pNext) > 0)
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1049\\ f0\\ fs16 \n\\ par }
*/
Image

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 525
Joined: 2 Years Ago
Has thanked: 19 times
Been thanked: 1 time
Contact:

#2

Post by czirimbolo » 4 Months Ago

raheem, can you make it?
Image

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1962
Joined: 2 Years Ago
Location: Egypt
Has thanked: 32 times
Been thanked: 108 times
Age: 21
Contact:

#3

Post by Raheem » 3 Months Ago

Try, i don't know what is this i just converted:

  1. #include <zombie_escape>
  2. #include <cstrike>
  3. #include <xs>
  4.  
  5. #define PLUGIN_NAME             "[ZE] Addon: Hero"
  6. #define PLUGIN_VERSION          "1.0"
  7. #define PLUGIN_AUTHOR           "Batcon"
  8.  
  9. #define BIT_VALID(%0,%1)    (%0 & (1<<(%1 & 31)))
  10. #define BIT_ADD(%0,%1)      (%0 |= (1<<(%1 & 31)))
  11. #define BIT_SUB(%0,%1)      (%0 &= ~(1<<(%1 & 31)))
  12. #define BIT_INVERT(%0,%1)   (%0 ^= (1<<(%1 & 31)))
  13. #define IsNullEnt(%0)       (%0 == -1 || %0 == 0)
  14. #define IsValidEnt(%0)      (!IsNullEnt(%0) && pev_valid(%0))
  15.  
  16. #define FILE_HERO_SETTING   "ze_hero.ini"
  17. #define FILE_HERO_LANG      "ze_hero.txt"
  18.  
  19. #define HUD_NOTICE_X    0.6
  20. #define HUD_NOTICE_Y    0.5
  21. #define HUD_NOTICE_C    0, 155, 200
  22. #define HUD_NOTICE_T    2.0
  23.  
  24. new const MAXBPAMMO[] = { -1, 52, -1, 90, 1, 32, 1, 100, 90, 1, 120, 100, 100, 90, 90, 90, 100, 120,
  25.             30, 120, 200, 32, 90, 120, 90, 2, 35, 90, 90, -1, 100 }            
  26.        
  27. #define SLOT_PRIMARY    1
  28. #define SLOT_SECONDARY  2
  29. #define SLOT_KNIFE      3
  30. #define SLOT_GRENADE    4
  31. #define SLOT_C4         5
  32.  
  33. #define MAX_CLIENTS     32
  34. #define TASK_ICON_ID    64
  35. #define TASK_ICON_DELAY 0.3
  36. #define TASK_AURA_ID    96
  37. #define TASK_AURA_DELAY 0.1
  38.  
  39. #define AURA_RADIUS 20 
  40.  
  41. // Linux extra offset
  42. #define OFFSET_LINUX_WEAPON     4
  43. #define OFFSET_LINUX_PLAYER     5
  44.  
  45. // CBasePlayerItem
  46. #define m_pPlayer           41
  47. #define m_pNext             42
  48. #define m_iId               43
  49.  
  50. // CBasePlayer
  51. #define m_rpgPlayerItems        367
  52.  
  53. new g_BitUserHero;
  54. new g_sHeroModel[32];
  55. new g_iHeroBody;
  56. new g_iHeroArmor;
  57. new g_iHeroHealth;
  58. new Array:g_aHeroWeapons;
  59. new g_iHeroMinPlayers;
  60. new Array:g_aHeroes;
  61. new g_sHeroModelIcon;
  62.  
  63. public plugin_init()
  64. {
  65.     register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
  66.     RegisterHam(Ham_Spawn, "player", "CBasePlayer_Spawn_Post", true);
  67.     RegisterHam(Ham_Killed, "player", "CBasePlayer_Killed_Post", true);
  68.     RegisterHam(Ham_Touch, "weaponbox", "CWeaponBox_Touch", false);
  69.     register_dictionary(FILE_HERO_LANG);
  70.     register_clcmd("drop", "ClientCmd_Drop");
  71. }
  72. public plugin_cfg()
  73. {
  74.     g_aHeroWeapons = ArrayCreate(32,1);
  75.     g_aHeroes = ArrayCreate(1,1);
  76.     SettingsFile_Load();
  77. }
  78. public plugin_natives()
  79. {
  80.     register_native("ze_is_user_hero", "native_is_user_hero", 1);
  81.     register_native("ze_make_user_hero", "native_make_user_hero", 1);
  82. }
  83. public native_is_user_hero(pPlayer)
  84. {
  85.     return BIT_VALID(g_BitUserHero, pPlayer);
  86. }
  87. public native_make_user_hero(pPlayer)
  88. {
  89.     if(!is_user_alive(pPlayer))
  90.         return 0;
  91.     if(ze_is_user_zombie(pPlayer))
  92.         return 0;
  93.     MakeUserHero(pPlayer);
  94.     return 1;
  95. }
  96.  
  97. public client_disconnected(pPlayer)
  98. {
  99.     RemoveUserHero(pPlayer);
  100.     remove_task(pPlayer + TASK_ICON_ID);
  101. }
  102.  
  103. public CBasePlayer_Spawn_Post(pPlayer)
  104. {
  105.     if(!BIT_VALID(g_BitUserHero, pPlayer))
  106.         return;
  107.  
  108.     RemoveUserHero(pPlayer);
  109.        
  110.     CS_RemoveItemsBySlot(pPlayer, SLOT_PRIMARY);
  111.     CS_RemoveItemsBySlot(pPlayer, SLOT_SECONDARY);
  112.     CS_RemoveItemsBySlot(pPlayer, SLOT_GRENADE);
  113.     CS_RemoveItemsBySlot(pPlayer, SLOT_C4);
  114. }
  115. public CBasePlayer_Killed_Post(pVictim, pAttacker, Gibs)
  116. {
  117.     RemoveUserHero(pVictim);
  118.     remove_task(pVictim + TASK_ICON_ID);
  119. }
  120. public CWeaponBox_Touch(pWeaponBox, pPlayer)
  121. {
  122.     if(!is_user_alive(pPlayer))
  123.         return HAM_IGNORED;
  124.     if(!BIT_VALID(g_BitUserHero, pPlayer))
  125.         return HAM_IGNORED;
  126.     return HAM_SUPERCEDE;
  127. }
  128. public ClientCmd_Drop(pPlayer)
  129. {
  130.     if(BIT_VALID(g_BitUserHero, pPlayer))
  131.         return PLUGIN_HANDLED;
  132.     return PLUGIN_CONTINUE;
  133. }
  134.  
  135. /*public zp_user_humanized_pre(pPlayer)
  136. {
  137.     if(!BIT_VALID(g_BitUserHero, pPlayer))
  138.         return;
  139.  
  140.     RemoveUserHero(pPlayer);
  141.        
  142.     CS_RemoveItemsBySlot(pPlayer, SLOT_PRIMARY);
  143.     CS_RemoveItemsBySlot(pPlayer, SLOT_SECONDARY);
  144.     CS_RemoveItemsBySlot(pPlayer, SLOT_GRENADE);
  145.     CS_RemoveItemsBySlot(pPlayer, SLOT_C4);
  146. }*/
  147.  
  148. public ze_user_humanized(pPlayer)
  149. {
  150.     RemoveUserHero(pPlayer);
  151.     remove_task(pPlayer + TASK_ICON_ID);
  152.    
  153.     if(ze_is_game_started() && ArraySize(g_aHeroes))
  154.         set_task(TASK_ICON_DELAY, "Task_Client_DrawIcons", pPlayer + TASK_ICON_ID, _, _, "b");
  155. }
  156.  
  157. public ze_user_infected(pPlayer)
  158. {
  159.     RemoveUserHero(pPlayer);
  160.     remove_task(pPlayer + TASK_ICON_ID);
  161. }
  162. public ze_game_started()
  163. {
  164.     new Players[MAX_CLIENTS], iPlayersNum;
  165.     get_players(Players, iPlayersNum, "a");
  166.    
  167.     if(iPlayersNum < g_iHeroMinPlayers)
  168.         return;
  169.  
  170.     new Humans[MAX_CLIENTS], iHumansNum;
  171.     new pPlayer;
  172.  
  173.     for(new i; i < iPlayersNum; i++)
  174.     {
  175.         pPlayer = Players[i];
  176.         if(ze_is_user_zombie(pPlayer) || BIT_VALID(g_BitUserHero, pPlayer))
  177.             continue;
  178.  
  179.         Humans[iHumansNum] = pPlayer;
  180.         iHumansNum++;
  181.     }
  182.  
  183.     if(!iHumansNum)
  184.         return;
  185.  
  186.     new pHero = Humans[random(iHumansNum)];
  187.     MakeUserHero(pHero);
  188.    
  189.     new szUserName[32]; get_user_name(pHero, szUserName, charsmax(szUserName));
  190.     set_dhudmessage(HUD_NOTICE_C, HUD_NOTICE_X, HUD_NOTICE_Y, 0, 0.0, HUD_NOTICE_T, 1.0, 0.1);
  191.     show_dhudmessage(0, "%L", LANG_PLAYER, "NOTICE_HERO", szUserName);
  192.    
  193.     if(ArraySize(g_aHeroes))
  194.     {
  195.         for(new i; i < iHumansNum; i++)
  196.         {
  197.             pPlayer = Humans[i];
  198.  
  199.             if(BIT_VALID(g_BitUserHero, pPlayer))
  200.                 continue;
  201.  
  202.             set_task(TASK_ICON_DELAY, "Task_Client_DrawIcons", pPlayer + TASK_ICON_ID, _, _, "b");
  203.         }
  204.     }
  205. }
  206. public Task_Client_DrawIcons(pPlayer)
  207. {
  208.     pPlayer -= TASK_ICON_ID;
  209.  
  210.     static pHero;
  211.     static Float:vIcon[3];
  212.     static Float:vSrc[3];
  213.     static Float:vViewOfs[3];
  214.     static Float:vEnd[3];
  215.     static Float:vDir[3];
  216.     static Float:vEndPos[3];
  217.     static Float:fDistToWall;
  218.     static Float:fDistToHero;
  219.     static Float:fScal;
  220.     static Float:fFraction;
  221.     static iTrace;
  222.  
  223.     iTrace = create_tr2();
  224.     pev(pPlayer, pev_origin, vSrc);
  225.     pev(pPlayer, pev_view_ofs, vViewOfs);
  226.     xs_vec_add(vSrc, vViewOfs, vSrc);
  227.  
  228.     for(new i = 0; i < ArraySize(g_aHeroes); i++)
  229.     {
  230.         pHero = ArrayGetCell(g_aHeroes, i);
  231.         pev(pHero, pev_origin, vEnd);
  232.         xs_vec_sub(vEnd, vSrc, vDir);
  233.  
  234.         engfunc(EngFunc_TraceLine, vSrc, vEnd, IGNORE_MONSTERS, 0, iTrace);
  235.         get_tr2(iTrace, TR_flFraction, fFraction);
  236.         fDistToHero = get_distance_f(vSrc, vEnd);
  237.  
  238.         get_tr2(iTrace, TR_vecEndPos, vEndPos);
  239.  
  240.         fDistToWall = get_distance_f(vSrc, vEndPos) - 10.0;
  241.  
  242.         if(fFraction == 1.0)
  243.         {
  244.             if(fDistToHero < 256.0)
  245.                 continue;
  246.  
  247.             fDistToWall -= 30.0;
  248.         }
  249.  
  250.         xs_vec_normalize(vDir, vDir);
  251.         xs_vec_mul_scalar(vDir, fDistToWall, vIcon);
  252.         xs_vec_add(vIcon, vSrc, vIcon);
  253.            
  254.         fScal = 1.0 + fDistToWall / fDistToHero
  255.  
  256.         if(fFraction == 1.0)
  257.             vIcon[2] += 36.0;
  258.            
  259.         message_begin(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, _, pPlayer);
  260.         write_byte(TE_SPRITE);
  261.         engfunc(EngFunc_WriteCoord, vIcon[0]);
  262.         engfunc(EngFunc_WriteCoord, vIcon[1]);
  263.         engfunc(EngFunc_WriteCoord, vIcon[2]);
  264.         write_short(g_sHeroModelIcon);
  265.         write_byte(floatround(fScal));
  266.         write_byte(125);
  267.         message_end() ;
  268.     }
  269.     free_tr2(iTrace);
  270. }
  271. public Task_Hero_Aura(pPlayer)
  272. {
  273.     pPlayer -= TASK_AURA_ID;
  274.  
  275.     static origin[3]; get_user_origin(pPlayer, origin);
  276.     message_begin(MSG_PVS, SVC_TEMPENTITY, origin);
  277.     write_byte(TE_DLIGHT);
  278.     write_coord(origin[0]);
  279.     write_coord(origin[1]);
  280.     write_coord(origin[2]);
  281.     write_byte(AURA_RADIUS);
  282.     write_byte(128);
  283.     write_byte(128);
  284.     write_byte(128);
  285.     write_byte(2);
  286.     write_byte(0);
  287.     message_end();
  288. }
  289.  
  290. public MakeUserHero(pPlayer)
  291. {
  292.     RemoveUserHero(pPlayer);
  293.  
  294.     CS_RemoveItemsBySlot(pPlayer, SLOT_PRIMARY);
  295.     CS_RemoveItemsBySlot(pPlayer, SLOT_SECONDARY);
  296.     CS_RemoveItemsBySlot(pPlayer, SLOT_GRENADE);
  297.     CS_RemoveItemsBySlot(pPlayer, SLOT_C4);
  298.    
  299.     BIT_ADD(g_BitUserHero, pPlayer);
  300.     ArrayPushCell(g_aHeroes, pPlayer);
  301.  
  302.     set_pev(pPlayer, pev_health, float(g_iHeroHealth));
  303.     set_pev(pPlayer, pev_max_health, float(g_iHeroHealth));
  304.     cs_set_user_armor(pPlayer, g_iHeroArmor, CS_ARMOR_KEVLAR);
  305.     rg_set_user_model(pPlayer, g_sHeroModel);
  306.     set_pev(pPlayer, pev_body, g_iHeroBody);
  307.  
  308.     for(new i, szWeaponName[32], iId; i < ArraySize(g_aHeroWeapons); i++)
  309.     {
  310.         ArrayGetString(g_aHeroWeapons, i, szWeaponName, charsmax(szWeaponName));
  311.         if((iId = ze_get_item_id(szWeaponName)) != -1)
  312.             ze_force_buy_item(pPlayer, iId, true);
  313.         else if((iId = get_weaponid(szWeaponName)) > 0)
  314.             CS_GiveWeapon(pPlayer, szWeaponName, true);
  315.     }
  316.  
  317.     set_task(TASK_AURA_DELAY, "Task_Hero_Aura", pPlayer + TASK_AURA_ID, _, _, "b");
  318. }
  319. public RemoveUserHero(pPlayer)
  320. {
  321.     if(!BIT_VALID(g_BitUserHero, pPlayer))
  322.         return;
  323.  
  324.     BIT_SUB(g_BitUserHero, pPlayer);
  325.  
  326.     for(new i = 0; i < ArraySize(g_aHeroes); i++)
  327.     {
  328.         if(ArrayGetCell(g_aHeroes, i) == pPlayer)
  329.         {
  330.             ArrayDeleteItem(g_aHeroes, i);
  331.             break;
  332.         }
  333.     }
  334.  
  335.     remove_task(pPlayer + TASK_AURA_ID);
  336. }
  337.  
  338. public SettingsFile_Load()
  339. {
  340.     new szDirPath[64];
  341.     get_localinfo("amxx_configsdir", szDirPath, charsmax(szDirPath));
  342.     format(szDirPath, charsmax(szDirPath), "%s/%s", szDirPath, FILE_HERO_SETTING);
  343.    
  344.     if(!file_exists(szDirPath))
  345.     {
  346.         new szError[100];
  347.         formatex(szError, charsmax(szError), "| File '%s' not found.", szDirPath);
  348.         set_fail_state(szError);
  349.         return;
  350.     }
  351.    
  352.     new szBuffer[1024], szKey[64], szValue[960];
  353.     new iFile = fopen(szDirPath, "rt");
  354.    
  355.     while(iFile && !feof(iFile))
  356.     {
  357.         fgets(iFile, szBuffer, charsmax(szBuffer));
  358.        
  359.         if(!szBuffer[0] || szBuffer[0] == '/' || szBuffer[0] == ';')
  360.             continue;
  361.  
  362.         strtok(szBuffer, szKey, charsmax(szKey), szValue, charsmax(szValue), '=');
  363.         trim(szKey);
  364.         trim(szValue);
  365.        
  366.         if(equal(szKey, "HERO MODEL"))
  367.         {
  368.             copy(g_sHeroModel, charsmax(g_sHeroModel), szValue);
  369.             new szModel[96]; format(szModel, charsmax(szModel), "models/player/%s/%s.mdl", szValue, szValue);
  370.             engfunc(EngFunc_PrecacheModel, szModel);
  371.         }
  372.         else if(equal(szKey, "HERO BODY"))
  373.         {
  374.             g_iHeroBody = str_to_num(szValue);
  375.         }
  376.         else if(equal(szKey, "HERO ARMOR"))
  377.         {
  378.             g_iHeroArmor = str_to_num(szValue);
  379.         }
  380.         else if(equal(szKey, "HERO HEALTH"))
  381.         {
  382.             g_iHeroHealth = str_to_num(szValue);
  383.         }
  384.         else if(equal(szKey, "HERO WEAPONS"))
  385.         {
  386.             while (szValue[0] != 0 && strtok(szValue, szKey, charsmax(szKey), szValue, charsmax(szValue), ','))
  387.             {
  388.                 trim(szKey)
  389.                 trim(szValue)
  390.                 ArrayPushString(g_aHeroWeapons, szKey);
  391.             }
  392.         }
  393.         else if(equal(szKey, "HERO ICON"))
  394.         {
  395.             g_sHeroModelIcon = engfunc(EngFunc_PrecacheModel, szValue);
  396.         }
  397.         else if(equal(szKey, "HERO MIN PLAYERS"))
  398.         {
  399.             g_iHeroMinPlayers = str_to_num(szValue);
  400.         }
  401.     }
  402.     if(iFile)
  403.         fclose(iFile);
  404. }
  405. stock CS_GiveWeapon(pPlayer, szWeaponName[], bool:bGiveAmmo = false)
  406. {
  407.     new pItem = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, szWeaponName));
  408.     if(!pev_valid(pItem))
  409.         return 0;
  410.  
  411.     ExecuteHamB(Ham_Spawn, pItem);
  412.  
  413.     if(!ExecuteHamB(Ham_AddPlayerItem, pPlayer, pItem))
  414.     {
  415.         set_pev(pItem, pev_flags, FL_KILLME);
  416.         return 0;
  417.     }
  418.  
  419.     ExecuteHamB(Ham_Item_AttachToPlayer, pItem, pPlayer);
  420.     emit_sound(pPlayer, CHAN_ITEM, "items/gunpickup2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
  421.  
  422.     if(bGiveAmmo)
  423.     {
  424.         new iId = cs_get_weapon_id(pItem);
  425.         if(MAXBPAMMO[iId] != -1)
  426.             cs_set_user_bpammo(pPlayer, iId, MAXBPAMMO[iId]);
  427.     }
  428.  
  429.     return pItem;
  430. }
  431. stock CS_DropItemsBySlot(pPlayer, iSlot)
  432. {
  433.     new pItem = get_pdata_cbase(pPlayer, m_rpgPlayerItems + iSlot, OFFSET_LINUX_PLAYER);
  434.  
  435.     if(IsNullEnt(pItem))
  436.         return;
  437.  
  438.     new pNext;
  439.     new szWeaponName[28];
  440.  
  441.     do
  442.     {
  443.         pNext = get_pdata_cbase(pItem, m_pNext, OFFSET_LINUX_WEAPON);
  444.         if(get_weaponname(get_pdata_int(pItem, m_iId, OFFSET_LINUX_WEAPON), szWeaponName, charsmax(szWeaponName)))  
  445.             engclient_cmd(pPlayer, "drop", szWeaponName);
  446.     }
  447.     while((pItem = pNext) > 0)
  448. }
  449. stock CS_RemoveItemsBySlot(pPlayer, iSlot)
  450. {
  451.     new pItem = get_pdata_cbase(pPlayer, m_rpgPlayerItems + iSlot, OFFSET_LINUX_PLAYER);
  452.  
  453.     if(IsNullEnt(pItem))
  454.         return;
  455.  
  456.     new pNext;
  457.     new iId;
  458.  
  459.     do
  460.     {
  461.         pNext = get_pdata_cbase(pItem, m_pNext, OFFSET_LINUX_WEAPON);
  462.         iId = get_pdata_int(pItem, m_iId, OFFSET_LINUX_WEAPON);
  463.  
  464.         if(get_user_weapon(pPlayer) == iId)
  465.             ExecuteHamB(Ham_Weapon_RetireWeapon, pItem);
  466.  
  467.         ExecuteHamB(Ham_RemovePlayerItem, pPlayer, pItem);
  468.         ExecuteHamB(Ham_Item_Kill, pItem);
  469.         set_pev(pPlayer, pev_weapons, pev(pPlayer, pev_weapons) & ~(1<<iId));
  470.  
  471.         cs_set_user_bpammo(pPlayer, iId, 0);
  472.     }
  473.     while((pItem = pNext) > 0)
  474. }
You don't know? Learn and you will know.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests