Solved supply box

Unpaid Requests, Public Plugins
Post Reply
czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 598
Joined: 7 years ago
Contact:

supply box

#1

Post by czirimbolo » 5 years ago

Jack, Raheem, can you add random armor from 1 to 50 to this supply box?

Code: Select all

#include <zombie_escape>
#include <engine>
#include <ze_levels>
#include <xs>

#define PLUGIN "[ZE] SupplyBox"
#define VERSION "1.1"
#define AUTHOR "Dias"

// ======================= SUPPLYBOX CONFIG ======================== // 
#define SUPPLYBOX_CLASSNAME "supplybox"
#define TASK_SUPPLYBOX 128256
#define TASK_SUPPLYBOX2 138266
#define TASK_SUPPLYBOX_HELP 129257
#define TASK_SUPPLYBOX_WAIT 130259

#define COINS 1000 // Random from 0 to 1000

const MAX_SUPPLYBOX_ENT = 100
new const supplybox_spawn_file[] = "%s/zp_supplybox/%s.cfg"
new const supplybox_icon_spr[] = "sprites/zombie_escape/icon_supplybox.spr"
new const supplybox_model[][] = {
	"models/zombie_escape/supplybox.mdl"
}
new const supplybox_drop_sound[][] = {
	"zombie_escape/supplybox_drop.wav"
}
new const supplybox_pickup_sound[][] = {
	"zombie_escape/supplybox_pickup.wav"
}
// ======================= END OF SUPPLYBOX CONFIG ======================== // 

// Below here is hard code. Don't edit anything except cvars
new g_supplybox_num, g_supplybox_wait[33], supplybox_count,
supplybox_ent[MAX_SUPPLYBOX_ENT], g_supplybox_icon_id, Float:g_supplybox_spawn[MAX_SUPPLYBOX_ENT][3],
g_total_supplybox_spawn
new cvar_supplybox_icon, cvar_supplybox_max, cvar_supplybox_num, cvar_supplybox_totalintime, 
cvar_supplybox_time, cvar_supplybox_delaytime, cvar_supplybox_icon_size, cvar_supplybox_icon_light, cvar_xp_max_amount
new bool:made_supplybox, Float:g_icon_delay[33], g_newround, g_endround

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)

	register_event("HLTV", "event_newround", "a", "1=0", "2=0")
	register_logevent("logevent_round_end", 2, "1=Round_End")
	
	register_forward(FM_Touch, "fw_supplybox_touch")
	
	cvar_supplybox_max = register_cvar("ze_supplybox_max", "10")
	cvar_supplybox_num = register_cvar("ze_supplybox_num", "2")
	cvar_supplybox_totalintime = register_cvar("ze_supplybox_totalintime", "4")
	cvar_supplybox_time = register_cvar("ze_supplybox_time", "30")
	cvar_supplybox_icon = register_cvar("ze_supplybox_icon", "1")
	cvar_supplybox_delaytime = register_cvar("ze_supplybox_icon_delay_time", "0.03")	
	cvar_supplybox_icon_size = register_cvar("ze_supplybox_icon_size", "2")
	cvar_supplybox_icon_light = register_cvar("ze_supplybox_icon_light", "100")
	cvar_xp_max_amount = register_cvar("ze_xp_max_amount", "50000")
	
	set_task(2.0, "update_radar", _, _, _, "b")
}

public plugin_precache()
{
	load_supplybox_spawn()
	
	static i
	for(i = 0; i < sizeof(supplybox_model); i++)
		engfunc(EngFunc_PrecacheModel, supplybox_model[i])
	for(i = 0; i < sizeof(supplybox_drop_sound); i++)
		engfunc(EngFunc_PrecacheSound, supplybox_drop_sound[i])		
	for(i = 0; i < sizeof(supplybox_pickup_sound); i++)
		engfunc(EngFunc_PrecacheSound, supplybox_pickup_sound[i])
		
	g_supplybox_icon_id = engfunc(EngFunc_PrecacheModel, supplybox_icon_spr)
}

public plugin_cfg()
{
	set_task(0.5, "event_newround")
}

public load_supplybox_spawn()
{
	// Check for spawns points of the current map
	static cfgdir[64]
	new mapname[32], filepath[100], linedata[64]
	get_localinfo("amxx_configsdir", cfgdir, charsmax(cfgdir))
	get_mapname(mapname, charsmax(mapname))
	formatex(filepath, charsmax(filepath), supplybox_spawn_file, cfgdir, mapname)
	
	// Load spawns points
	if (file_exists(filepath))
	{
		new file = fopen(filepath,"rt"), row[4][6]
		
		while (file && !feof(file))
		{
			fgets(file, linedata, charsmax(linedata))
			
			// invalid spawn
			if(!linedata[0] || str_count(linedata,' ') < 2) continue;
			
			// get spawn point data
			parse(linedata,row[0],5,row[1],5,row[2],5)
			
			// origin
			g_supplybox_spawn[g_total_supplybox_spawn][0] = floatstr(row[0])
			g_supplybox_spawn[g_total_supplybox_spawn][1] = floatstr(row[1])
			g_supplybox_spawn[g_total_supplybox_spawn][2] = floatstr(row[2])

			g_total_supplybox_spawn++
			if (g_total_supplybox_spawn >= MAX_SUPPLYBOX_ENT) 
				break
		}
		if (file) fclose(file)
	}
}

public update_radar()
{	
	for (new id = 1; id <= get_maxplayers(); id++)
	{
		if (!is_user_alive(id) || !supplybox_count || ze_is_user_zombie(id)) 
			continue
		
		static i, next_ent
		i = 1
		while(i <= supplybox_count)
		{
			next_ent = supplybox_ent[i]
			if (next_ent && is_valid_ent(next_ent))
			{
				static Float:origin[3]
				pev(next_ent, pev_origin, origin)
				
				message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("HostagePos"), {0,0,0}, id)
				write_byte(id)
				write_byte(i)		
				write_coord(floatround(origin[0]))
				write_coord(floatround(origin[1]))
				write_coord(floatround(origin[2]))
				message_end()
			
				message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("HostageK"), {0,0,0}, id)
				write_byte(i)
				message_end()
			}

			i++
		}
	}
}

public event_newround()
{
	made_supplybox = false
	g_newround = 1
	g_endround = 0
	
	remove_supplybox()
	supplybox_count = 0
	
	if(task_exists(TASK_SUPPLYBOX)) remove_task(TASK_SUPPLYBOX)
	if(task_exists(TASK_SUPPLYBOX2)) remove_task(TASK_SUPPLYBOX2)
	if(task_exists(TASK_SUPPLYBOX_HELP)) remove_task(TASK_SUPPLYBOX_HELP)
}

public logevent_round_end() g_endround = 1

public ze_user_infected()
{
	if(!made_supplybox)
	{
		g_newround = 0
		made_supplybox = true
		
		if(task_exists(TASK_SUPPLYBOX)) remove_task(TASK_SUPPLYBOX)
		
		if(!g_total_supplybox_spawn)
		{
			client_print(0, print_console, "[ZE - SupplyBox][Error] Spawn Point Not Found. Please Create Spawn Point")
		} else {
			set_task(get_pcvar_float(cvar_supplybox_time), "create_supplybox", TASK_SUPPLYBOX)
		}
	}
}

public client_PostThink(id)
{
	if (!get_pcvar_num(cvar_supplybox_icon) || !is_user_alive(id) || ze_is_user_zombie(id))
		return
	if((g_icon_delay[id] + get_pcvar_float(cvar_supplybox_delaytime)) > get_gametime())
		return
		
	g_icon_delay[id] = get_gametime()

	if (supplybox_count)
	{
		static i, box_ent
		i = 1
		
		while (i <= supplybox_count)
		{
			box_ent = supplybox_ent[i]
			create_icon_origin(id, box_ent, g_supplybox_icon_id)
			i++
		}
	}
}

public create_supplybox()
{
	if (supplybox_count >= get_pcvar_num(cvar_supplybox_max) || g_newround || g_endround) 
		return

	if (task_exists(TASK_SUPPLYBOX)) remove_task(TASK_SUPPLYBOX)
	set_task(get_pcvar_float(cvar_supplybox_time), "create_supplybox", TASK_SUPPLYBOX)
	
	if (get_total_supplybox() >= get_pcvar_num(cvar_supplybox_totalintime)) 
		return
	
	g_supplybox_num = 0
	create_supplybox2()
	
	static random_sound
	random_sound = random_num(0, charsmax(supplybox_drop_sound))
	client_cmd(0, "spk ^"%s^"", supplybox_drop_sound[random_sound])
	
	for(new i = 0; i < get_maxplayers(); i++)
	{
		if(is_user_alive(i) && is_user_connected(i) && !ze_is_user_zombie(i))
		{
			set_dhudmessage(random(256), random(256), random(256), -1.0, -0.80, 2, 4.0, 3.0, 0.1, 0.1)
			show_dhudmessage(i, "Supplybox has appeared. Find it.")
		}
	}
	
	if (task_exists(TASK_SUPPLYBOX_HELP)) remove_task(TASK_SUPPLYBOX_HELP)
	set_task(6.0, "show_supplybox_help", TASK_SUPPLYBOX_HELP)

	if (task_exists(TASK_SUPPLYBOX2)) remove_task(TASK_SUPPLYBOX2)
	set_task(0.5, "create_supplybox2", TASK_SUPPLYBOX2, _, _, "b")	
}

public create_supplybox2()
{
	if (supplybox_count >= get_pcvar_num(cvar_supplybox_max)
	|| get_total_supplybox() >= get_pcvar_num(cvar_supplybox_totalintime) || g_newround || g_endround)
	{
		remove_task(TASK_SUPPLYBOX2)
		return
	}
	
	supplybox_count++
	g_supplybox_num++

	new ent = create_entity("info_target")
	
	entity_set_string(ent, EV_SZ_classname, SUPPLYBOX_CLASSNAME)
	entity_set_model(ent, supplybox_model[random_num(0, charsmax(supplybox_model))])	
	entity_set_size(ent,Float:{-2.0,-2.0,-2.0},Float:{5.0,5.0,5.0})
	entity_set_int(ent,EV_INT_solid,1)
	entity_set_int(ent,EV_INT_movetype,6)
	entity_set_int(ent, EV_INT_iuser2, supplybox_count)
	
	static Float:Origin[3]
	collect_spawn_point(Origin)
	engfunc(EngFunc_SetOrigin, ent, Origin)
	
	supplybox_ent[supplybox_count] = ent

	if ((g_supplybox_num >= get_pcvar_num(cvar_supplybox_num)) && task_exists(TASK_SUPPLYBOX2)) 
		remove_task(TASK_SUPPLYBOX2)
}

public get_total_supplybox()
{
	new total
	for (new i = 1; i <= supplybox_count; i++)
	{
		if (supplybox_ent[i]) total += 1
	}
	return total
}

public show_supplybox_help()
{
	for(new i = 0; i < get_maxplayers(); i++)
	{
		if(is_user_alive(i) && is_user_connected(i) && !ze_is_user_zombie(i))
		{
			set_dhudmessage(random(256), random(256), random(256), -1.0, -0.80, 2, 4.0, 3.0, 0.1, 0.1)
			show_dhudmessage(i, "You can see Supplybox Location in the Radar.")
		}
	}
}

public remove_supplybox()
{
	remove_ent_by_class(SUPPLYBOX_CLASSNAME)
	new supplybox_ent_reset[MAX_SUPPLYBOX_ENT]
	supplybox_ent = supplybox_ent_reset
}

public fw_supplybox_touch(ent, id)
{
	if (!pev_valid(ent) || !is_user_alive(id) || ze_is_user_zombie(id) || g_supplybox_wait[id]) 
		return FMRES_IGNORED
	
	static classname[32]
	entity_get_string(ent,EV_SZ_classname,classname,31)
	
	if (equal(classname, SUPPLYBOX_CLASSNAME))
	{
		static name[32]
		get_user_name(id, name, charsmax(name))
		new iCurrentXP = ze_get_user_xp(id)
		
		switch(random_num(0,3))
		{
			case 0:
			{
				rg_give_item(id, "weapon_hegrenade", GT_APPEND)
				ze_colored_print(0, "!t%s !ghas received !tNapalm Nade!y!!!", name)
			}
			case 1:
			{
				rg_give_item(id, "weapon_smokegrenade", GT_APPEND)
				ze_colored_print(0, "!t%s !ghas received !tForst Nade!y!!!", name)
			}
			case 2:
			{
				new iXPAmount = random_num(1, get_pcvar_num(cvar_xp_max_amount))
				ze_set_user_xp(id, iCurrentXP + iXPAmount)
				ze_colored_print(0, "!t%s !ghas received !t%i XP!y!!!", name, iXPAmount)
			}
			case 3:
			{
			new iCoinsAmount = random_num(1, COINS)
				ze_set_escape_coins(id, ze_get_escape_coins(id) + iCoinsAmount)
				ze_colored_print(0, "!t%s !ghas received !t%i XP!y!!!", name, iCoinsAmount)
			}
		}
		
		static random_sound
		random_sound = random_num(0, charsmax(supplybox_pickup_sound))
		emit_sound(id, CHAN_VOICE, supplybox_pickup_sound[random_sound], 1.0, ATTN_NORM, 0, PITCH_NORM)

		new num_box = entity_get_int(ent, EV_INT_iuser2)
		supplybox_ent[num_box] = 0
		remove_entity(ent)

		g_supplybox_wait[id] = 1
		if (task_exists(id+TASK_SUPPLYBOX_WAIT)) remove_task(id+TASK_SUPPLYBOX_WAIT)
		set_task(2.0, "remove_supplybox_wait", id+TASK_SUPPLYBOX_WAIT)
	}
	
	return FMRES_IGNORED
}

public remove_supplybox_wait(id)
{
	id -= TASK_SUPPLYBOX_WAIT
	
	g_supplybox_wait[id] = 0
	if (task_exists(id+TASK_SUPPLYBOX_WAIT)) remove_task(id+TASK_SUPPLYBOX_WAIT)
}

stock collect_spawn_point(Float:origin[3]) // By Sontung0
{
	for (new i = 1; i <= g_total_supplybox_spawn *3 ; i++)
	{
		origin = g_supplybox_spawn[random(g_total_supplybox_spawn)]
		if (check_spawn_box(origin)) return 1;
	}

	return 0;
}
stock check_spawn_box(Float:origin[3]) // By Sontung0
{
	new Float:originE[3], Float:origin1[3], Float:origin2[3]
	new ent = -1
	while ((ent = engfunc(EngFunc_FindEntityByString, ent, "classname", SUPPLYBOX_CLASSNAME)) != 0)
	{
		pev(ent, pev_origin, originE)
		
		// xoy
		origin1 = origin
		origin2 = originE
		origin1[2] = origin2[2] = 0.0
		if (vector_distance(origin1, origin2) <= 32.0) return 0;
	}
	return 1;
}

stock create_icon_origin(id, ent, sprite) // By sontung0
{
	if (!pev_valid(ent)) return;
	
	new Float:fMyOrigin[3]
	entity_get_vector(id, EV_VEC_origin, fMyOrigin)
	
	new target = ent
	new Float:fTargetOrigin[3]
	entity_get_vector(target, EV_VEC_origin, fTargetOrigin)
	fTargetOrigin[2] += 40.0
	
	if (!is_in_viewcone(id, fTargetOrigin)) return;

	new Float:fMiddle[3], Float:fHitPoint[3]
	xs_vec_sub(fTargetOrigin, fMyOrigin, fMiddle)
	trace_line(-1, fMyOrigin, fTargetOrigin, fHitPoint)
							
	new Float:fWallOffset[3], Float:fDistanceToWall
	fDistanceToWall = vector_distance(fMyOrigin, fHitPoint) - 10.0
	normalize(fMiddle, fWallOffset, fDistanceToWall)
	
	new Float:fSpriteOffset[3]
	xs_vec_add(fWallOffset, fMyOrigin, fSpriteOffset)
	new Float:fScale
	fScale = 0.01 * fDistanceToWall
	
	new scale = floatround(fScale)
	scale = max(scale, 1)
	scale = min(scale, get_pcvar_num(cvar_supplybox_icon_size))
	scale = max(scale, 1)

	te_sprite(id, fSpriteOffset, sprite, scale, get_pcvar_num(cvar_supplybox_icon_light))
}

stock te_sprite(id, Float:origin[3], sprite, scale, brightness) // By sontung0
{	
	message_begin(MSG_ONE, SVC_TEMPENTITY, _, id)
	write_byte(TE_SPRITE)
	write_coord(floatround(origin[0]))
	write_coord(floatround(origin[1]))
	write_coord(floatround(origin[2]))
	write_short(sprite)
	write_byte(scale) 
	write_byte(brightness)
	message_end()
}

stock normalize(Float:fIn[3], Float:fOut[3], Float:fMul) // By sontung0
{
	new Float:fLen = xs_vec_len(fIn)
	xs_vec_copy(fIn, fOut)
	
	fOut[0] /= fLen, fOut[1] /= fLen, fOut[2] /= fLen
	fOut[0] *= fMul, fOut[1] *= fMul, fOut[2] *= fMul
}

stock str_count(const str[], searchchar) // By Twilight Suzuka
{
	new count, i, len = strlen(str)
	
	for (i = 0; i <= len; i++)
	{
		if(str[i] == searchchar)
			count++
	}
	
	return count;
}

stock remove_ent_by_class(classname[])
{
	new nextitem  = find_ent_by_class(-1, classname)
	while(nextitem)
	{
		remove_entity(nextitem)
		nextitem = find_ent_by_class(-1, classname)
	}
}
Image

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#2

Post by Raheem » 5 years ago

  1. #include <zombie_escape>
  2. #include <engine>
  3. #include <ze_levels>
  4. #include <xs>
  5.  
  6. #define PLUGIN "[ZE] SupplyBox"
  7. #define VERSION "1.1"
  8. #define AUTHOR "Dias"
  9.  
  10. // ======================= SUPPLYBOX CONFIG ======================== //
  11. #define SUPPLYBOX_CLASSNAME "supplybox"
  12. #define TASK_SUPPLYBOX 128256
  13. #define TASK_SUPPLYBOX2 138266
  14. #define TASK_SUPPLYBOX_HELP 129257
  15. #define TASK_SUPPLYBOX_WAIT 130259
  16.  
  17. #define COINS 1000 // Random from 0 to 1000
  18. #define ARMOR 50 // Random armor from 0 to 50
  19.  
  20. const MAX_SUPPLYBOX_ENT = 100
  21. new const supplybox_spawn_file[] = "%s/zp_supplybox/%s.cfg"
  22. new const supplybox_icon_spr[] = "sprites/zombie_escape/icon_supplybox.spr"
  23. new const supplybox_model[][] = {
  24.     "models/zombie_escape/supplybox.mdl"
  25. }
  26. new const supplybox_drop_sound[][] = {
  27.     "zombie_escape/supplybox_drop.wav"
  28. }
  29. new const supplybox_pickup_sound[][] = {
  30.     "zombie_escape/supplybox_pickup.wav"
  31. }
  32. // ======================= END OF SUPPLYBOX CONFIG ======================== //
  33.  
  34. // Below here is hard code. Don't edit anything except cvars
  35. new g_supplybox_num, g_supplybox_wait[33], supplybox_count,
  36. supplybox_ent[MAX_SUPPLYBOX_ENT], g_supplybox_icon_id, Float:g_supplybox_spawn[MAX_SUPPLYBOX_ENT][3],
  37. g_total_supplybox_spawn
  38. new cvar_supplybox_icon, cvar_supplybox_max, cvar_supplybox_num, cvar_supplybox_totalintime,
  39. cvar_supplybox_time, cvar_supplybox_delaytime, cvar_supplybox_icon_size, cvar_supplybox_icon_light, cvar_xp_max_amount
  40. new bool:made_supplybox, Float:g_icon_delay[33], g_newround, g_endround
  41.  
  42. public plugin_init()
  43. {
  44.     register_plugin(PLUGIN, VERSION, AUTHOR)
  45.  
  46.     register_event("HLTV", "event_newround", "a", "1=0", "2=0")
  47.     register_logevent("logevent_round_end", 2, "1=Round_End")
  48.    
  49.     register_forward(FM_Touch, "fw_supplybox_touch")
  50.    
  51.     cvar_supplybox_max = register_cvar("ze_supplybox_max", "10")
  52.     cvar_supplybox_num = register_cvar("ze_supplybox_num", "2")
  53.     cvar_supplybox_totalintime = register_cvar("ze_supplybox_totalintime", "4")
  54.     cvar_supplybox_time = register_cvar("ze_supplybox_time", "30")
  55.     cvar_supplybox_icon = register_cvar("ze_supplybox_icon", "1")
  56.     cvar_supplybox_delaytime = register_cvar("ze_supplybox_icon_delay_time", "0.03")  
  57.     cvar_supplybox_icon_size = register_cvar("ze_supplybox_icon_size", "2")
  58.     cvar_supplybox_icon_light = register_cvar("ze_supplybox_icon_light", "100")
  59.     cvar_xp_max_amount = register_cvar("ze_xp_max_amount", "50000")
  60.    
  61.     set_task(2.0, "update_radar", _, _, _, "b")
  62. }
  63.  
  64. public plugin_precache()
  65. {
  66.     load_supplybox_spawn()
  67.    
  68.     static i
  69.     for(i = 0; i < sizeof(supplybox_model); i++)
  70.         engfunc(EngFunc_PrecacheModel, supplybox_model[i])
  71.     for(i = 0; i < sizeof(supplybox_drop_sound); i++)
  72.         engfunc(EngFunc_PrecacheSound, supplybox_drop_sound[i])    
  73.     for(i = 0; i < sizeof(supplybox_pickup_sound); i++)
  74.         engfunc(EngFunc_PrecacheSound, supplybox_pickup_sound[i])
  75.        
  76.     g_supplybox_icon_id = engfunc(EngFunc_PrecacheModel, supplybox_icon_spr)
  77. }
  78.  
  79. public plugin_cfg()
  80. {
  81.     set_task(0.5, "event_newround")
  82. }
  83.  
  84. public load_supplybox_spawn()
  85. {
  86.     // Check for spawns points of the current map
  87.     static cfgdir[64]
  88.     new mapname[32], filepath[100], linedata[64]
  89.     get_localinfo("amxx_configsdir", cfgdir, charsmax(cfgdir))
  90.     get_mapname(mapname, charsmax(mapname))
  91.     formatex(filepath, charsmax(filepath), supplybox_spawn_file, cfgdir, mapname)
  92.    
  93.     // Load spawns points
  94.     if (file_exists(filepath))
  95.     {
  96.         new file = fopen(filepath,"rt"), row[4][6]
  97.        
  98.         while (file && !feof(file))
  99.         {
  100.             fgets(file, linedata, charsmax(linedata))
  101.            
  102.             // invalid spawn
  103.             if(!linedata[0] || str_count(linedata,' ') < 2) continue;
  104.            
  105.             // get spawn point data
  106.             parse(linedata,row[0],5,row[1],5,row[2],5)
  107.            
  108.             // origin
  109.             g_supplybox_spawn[g_total_supplybox_spawn][0] = floatstr(row[0])
  110.             g_supplybox_spawn[g_total_supplybox_spawn][1] = floatstr(row[1])
  111.             g_supplybox_spawn[g_total_supplybox_spawn][2] = floatstr(row[2])
  112.  
  113.             g_total_supplybox_spawn++
  114.             if (g_total_supplybox_spawn >= MAX_SUPPLYBOX_ENT)
  115.                 break
  116.         }
  117.         if (file) fclose(file)
  118.     }
  119. }
  120.  
  121. public update_radar()
  122. {  
  123.     for (new id = 1; id <= get_maxplayers(); id++)
  124.     {
  125.         if (!is_user_alive(id) || !supplybox_count || ze_is_user_zombie(id))
  126.             continue
  127.        
  128.         static i, next_ent
  129.         i = 1
  130.         while(i <= supplybox_count)
  131.         {
  132.             next_ent = supplybox_ent[i]
  133.             if (next_ent && is_valid_ent(next_ent))
  134.             {
  135.                 static Float:origin[3]
  136.                 pev(next_ent, pev_origin, origin)
  137.                
  138.                 message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("HostagePos"), {0,0,0}, id)
  139.                 write_byte(id)
  140.                 write_byte(i)      
  141.                 write_coord(floatround(origin[0]))
  142.                 write_coord(floatround(origin[1]))
  143.                 write_coord(floatround(origin[2]))
  144.                 message_end()
  145.            
  146.                 message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("HostageK"), {0,0,0}, id)
  147.                 write_byte(i)
  148.                 message_end()
  149.             }
  150.  
  151.             i++
  152.         }
  153.     }
  154. }
  155.  
  156. public event_newround()
  157. {
  158.     made_supplybox = false
  159.     g_newround = 1
  160.     g_endround = 0
  161.    
  162.     remove_supplybox()
  163.     supplybox_count = 0
  164.    
  165.     if(task_exists(TASK_SUPPLYBOX)) remove_task(TASK_SUPPLYBOX)
  166.     if(task_exists(TASK_SUPPLYBOX2)) remove_task(TASK_SUPPLYBOX2)
  167.     if(task_exists(TASK_SUPPLYBOX_HELP)) remove_task(TASK_SUPPLYBOX_HELP)
  168. }
  169.  
  170. public logevent_round_end() g_endround = 1
  171.  
  172. public ze_user_infected()
  173. {
  174.     if(!made_supplybox)
  175.     {
  176.         g_newround = 0
  177.         made_supplybox = true
  178.        
  179.         if(task_exists(TASK_SUPPLYBOX)) remove_task(TASK_SUPPLYBOX)
  180.        
  181.         if(!g_total_supplybox_spawn)
  182.         {
  183.             client_print(0, print_console, "[ZE - SupplyBox][Error] Spawn Point Not Found. Please Create Spawn Point")
  184.         } else {
  185.             set_task(get_pcvar_float(cvar_supplybox_time), "create_supplybox", TASK_SUPPLYBOX)
  186.         }
  187.     }
  188. }
  189.  
  190. public client_PostThink(id)
  191. {
  192.     if (!get_pcvar_num(cvar_supplybox_icon) || !is_user_alive(id) || ze_is_user_zombie(id))
  193.         return
  194.     if((g_icon_delay[id] + get_pcvar_float(cvar_supplybox_delaytime)) > get_gametime())
  195.         return
  196.        
  197.     g_icon_delay[id] = get_gametime()
  198.  
  199.     if (supplybox_count)
  200.     {
  201.         static i, box_ent
  202.         i = 1
  203.        
  204.         while (i <= supplybox_count)
  205.         {
  206.             box_ent = supplybox_ent[i]
  207.             create_icon_origin(id, box_ent, g_supplybox_icon_id)
  208.             i++
  209.         }
  210.     }
  211. }
  212.  
  213. public create_supplybox()
  214. {
  215.     if (supplybox_count >= get_pcvar_num(cvar_supplybox_max) || g_newround || g_endround)
  216.         return
  217.  
  218.     if (task_exists(TASK_SUPPLYBOX)) remove_task(TASK_SUPPLYBOX)
  219.     set_task(get_pcvar_float(cvar_supplybox_time), "create_supplybox", TASK_SUPPLYBOX)
  220.    
  221.     if (get_total_supplybox() >= get_pcvar_num(cvar_supplybox_totalintime))
  222.         return
  223.    
  224.     g_supplybox_num = 0
  225.     create_supplybox2()
  226.    
  227.     static random_sound
  228.     random_sound = random_num(0, charsmax(supplybox_drop_sound))
  229.     client_cmd(0, "spk ^"%s^"", supplybox_drop_sound[random_sound])
  230.    
  231.     for(new i = 0; i < get_maxplayers(); i++)
  232.     {
  233.         if(is_user_alive(i) && is_user_connected(i) && !ze_is_user_zombie(i))
  234.         {
  235.             set_dhudmessage(random(256), random(256), random(256), -1.0, -0.80, 2, 4.0, 3.0, 0.1, 0.1)
  236.             show_dhudmessage(i, "Supplybox has appeared. Find it.")
  237.         }
  238.     }
  239.    
  240.     if (task_exists(TASK_SUPPLYBOX_HELP)) remove_task(TASK_SUPPLYBOX_HELP)
  241.     set_task(6.0, "show_supplybox_help", TASK_SUPPLYBOX_HELP)
  242.  
  243.     if (task_exists(TASK_SUPPLYBOX2)) remove_task(TASK_SUPPLYBOX2)
  244.     set_task(0.5, "create_supplybox2", TASK_SUPPLYBOX2, _, _, "b")
  245. }
  246.  
  247. public create_supplybox2()
  248. {
  249.     if (supplybox_count >= get_pcvar_num(cvar_supplybox_max)
  250.     || get_total_supplybox() >= get_pcvar_num(cvar_supplybox_totalintime) || g_newround || g_endround)
  251.     {
  252.         remove_task(TASK_SUPPLYBOX2)
  253.         return
  254.     }
  255.    
  256.     supplybox_count++
  257.     g_supplybox_num++
  258.  
  259.     new ent = create_entity("info_target")
  260.    
  261.     entity_set_string(ent, EV_SZ_classname, SUPPLYBOX_CLASSNAME)
  262.     entity_set_model(ent, supplybox_model[random_num(0, charsmax(supplybox_model))])  
  263.     entity_set_size(ent,Float:{-2.0,-2.0,-2.0},Float:{5.0,5.0,5.0})
  264.     entity_set_int(ent,EV_INT_solid,1)
  265.     entity_set_int(ent,EV_INT_movetype,6)
  266.     entity_set_int(ent, EV_INT_iuser2, supplybox_count)
  267.    
  268.     static Float:Origin[3]
  269.     collect_spawn_point(Origin)
  270.     engfunc(EngFunc_SetOrigin, ent, Origin)
  271.    
  272.     supplybox_ent[supplybox_count] = ent
  273.  
  274.     if ((g_supplybox_num >= get_pcvar_num(cvar_supplybox_num)) && task_exists(TASK_SUPPLYBOX2))
  275.         remove_task(TASK_SUPPLYBOX2)
  276. }
  277.  
  278. public get_total_supplybox()
  279. {
  280.     new total
  281.     for (new i = 1; i <= supplybox_count; i++)
  282.     {
  283.         if (supplybox_ent[i]) total += 1
  284.     }
  285.     return total
  286. }
  287.  
  288. public show_supplybox_help()
  289. {
  290.     for(new i = 0; i < get_maxplayers(); i++)
  291.     {
  292.         if(is_user_alive(i) && is_user_connected(i) && !ze_is_user_zombie(i))
  293.         {
  294.             set_dhudmessage(random(256), random(256), random(256), -1.0, -0.80, 2, 4.0, 3.0, 0.1, 0.1)
  295.             show_dhudmessage(i, "You can see Supplybox Location in the Radar.")
  296.         }
  297.     }
  298. }
  299.  
  300. public remove_supplybox()
  301. {
  302.     remove_ent_by_class(SUPPLYBOX_CLASSNAME)
  303.     new supplybox_ent_reset[MAX_SUPPLYBOX_ENT]
  304.     supplybox_ent = supplybox_ent_reset
  305. }
  306.  
  307. public fw_supplybox_touch(ent, id)
  308. {
  309.     if (!pev_valid(ent) || !is_user_alive(id) || ze_is_user_zombie(id) || g_supplybox_wait[id])
  310.         return FMRES_IGNORED
  311.    
  312.     static classname[32]
  313.     entity_get_string(ent,EV_SZ_classname,classname,31)
  314.    
  315.     if (equal(classname, SUPPLYBOX_CLASSNAME))
  316.     {
  317.         static name[32]
  318.         get_user_name(id, name, charsmax(name))
  319.         new iCurrentXP = ze_get_user_xp(id)
  320.        
  321.         switch(random_num(0,4))
  322.         {
  323.             case 0:
  324.             {
  325.                 rg_give_item(id, "weapon_hegrenade", GT_APPEND)
  326.                 ze_colored_print(0, "!t%s !ghas received !tNapalm Nade!y!!!", name)
  327.             }
  328.             case 1:
  329.             {
  330.                 rg_give_item(id, "weapon_smokegrenade", GT_APPEND)
  331.                 ze_colored_print(0, "!t%s !ghas received !tForst Nade!y!!!", name)
  332.             }
  333.             case 2:
  334.             {
  335.                 new iXPAmount = random_num(1, get_pcvar_num(cvar_xp_max_amount))
  336.                 ze_set_user_xp(id, iCurrentXP + iXPAmount)
  337.                 ze_colored_print(0, "!t%s !ghas received !t%i XP!y!!!", name, iXPAmount)
  338.             }
  339.             case 3:
  340.             {
  341.                 new iCoinsAmount = random_num(1, COINS)
  342.                 ze_set_escape_coins(id, ze_get_escape_coins(id) + iCoinsAmount)
  343.                 ze_colored_print(0, "!t%s !ghas received !t%i Coins!y!!!", name, iCoinsAmount)
  344.             }
  345.             case 4:
  346.             {
  347.                 new iRandomArmor = random_num(1, ARMOR)
  348.                 set_entvar(id, var_armorvalue, float(iRandomArmor + floatround(get_entvar(id, var_armorvalue))))
  349.                 ze_colored_print(0, "!t%s !ghas received !t%i Armor!y!!!", name, iRandomArmor)
  350.             }
  351.         }
  352.        
  353.         static random_sound
  354.         random_sound = random_num(0, charsmax(supplybox_pickup_sound))
  355.         emit_sound(id, CHAN_VOICE, supplybox_pickup_sound[random_sound], 1.0, ATTN_NORM, 0, PITCH_NORM)
  356.  
  357.         new num_box = entity_get_int(ent, EV_INT_iuser2)
  358.         supplybox_ent[num_box] = 0
  359.         remove_entity(ent)
  360.  
  361.         g_supplybox_wait[id] = 1
  362.         if (task_exists(id+TASK_SUPPLYBOX_WAIT)) remove_task(id+TASK_SUPPLYBOX_WAIT)
  363.         set_task(2.0, "remove_supplybox_wait", id+TASK_SUPPLYBOX_WAIT)
  364.     }
  365.    
  366.     return FMRES_IGNORED
  367. }
  368.  
  369. public remove_supplybox_wait(id)
  370. {
  371.     id -= TASK_SUPPLYBOX_WAIT
  372.    
  373.     g_supplybox_wait[id] = 0
  374.     if (task_exists(id+TASK_SUPPLYBOX_WAIT)) remove_task(id+TASK_SUPPLYBOX_WAIT)
  375. }
  376.  
  377. stock collect_spawn_point(Float:origin[3]) // By Sontung0
  378. {
  379.     for (new i = 1; i <= g_total_supplybox_spawn *3 ; i++)
  380.     {
  381.         origin = g_supplybox_spawn[random(g_total_supplybox_spawn)]
  382.         if (check_spawn_box(origin)) return 1;
  383.     }
  384.  
  385.     return 0;
  386. }
  387. stock check_spawn_box(Float:origin[3]) // By Sontung0
  388. {
  389.     new Float:originE[3], Float:origin1[3], Float:origin2[3]
  390.     new ent = -1
  391.     while ((ent = engfunc(EngFunc_FindEntityByString, ent, "classname", SUPPLYBOX_CLASSNAME)) != 0)
  392.     {
  393.         pev(ent, pev_origin, originE)
  394.        
  395.         // xoy
  396.         origin1 = origin
  397.         origin2 = originE
  398.         origin1[2] = origin2[2] = 0.0
  399.         if (vector_distance(origin1, origin2) <= 32.0) return 0;
  400.     }
  401.     return 1;
  402. }
  403.  
  404. stock create_icon_origin(id, ent, sprite) // By sontung0
  405. {
  406.     if (!pev_valid(ent)) return;
  407.    
  408.     new Float:fMyOrigin[3]
  409.     entity_get_vector(id, EV_VEC_origin, fMyOrigin)
  410.    
  411.     new target = ent
  412.     new Float:fTargetOrigin[3]
  413.     entity_get_vector(target, EV_VEC_origin, fTargetOrigin)
  414.     fTargetOrigin[2] += 40.0
  415.    
  416.     if (!is_in_viewcone(id, fTargetOrigin)) return;
  417.  
  418.     new Float:fMiddle[3], Float:fHitPoint[3]
  419.     xs_vec_sub(fTargetOrigin, fMyOrigin, fMiddle)
  420.     trace_line(-1, fMyOrigin, fTargetOrigin, fHitPoint)
  421.                            
  422.     new Float:fWallOffset[3], Float:fDistanceToWall
  423.     fDistanceToWall = vector_distance(fMyOrigin, fHitPoint) - 10.0
  424.     normalize(fMiddle, fWallOffset, fDistanceToWall)
  425.    
  426.     new Float:fSpriteOffset[3]
  427.     xs_vec_add(fWallOffset, fMyOrigin, fSpriteOffset)
  428.     new Float:fScale
  429.     fScale = 0.01 * fDistanceToWall
  430.    
  431.     new scale = floatround(fScale)
  432.     scale = max(scale, 1)
  433.     scale = min(scale, get_pcvar_num(cvar_supplybox_icon_size))
  434.     scale = max(scale, 1)
  435.  
  436.     te_sprite(id, fSpriteOffset, sprite, scale, get_pcvar_num(cvar_supplybox_icon_light))
  437. }
  438.  
  439. stock te_sprite(id, Float:origin[3], sprite, scale, brightness) // By sontung0
  440. {  
  441.     message_begin(MSG_ONE, SVC_TEMPENTITY, _, id)
  442.     write_byte(TE_SPRITE)
  443.     write_coord(floatround(origin[0]))
  444.     write_coord(floatround(origin[1]))
  445.     write_coord(floatround(origin[2]))
  446.     write_short(sprite)
  447.     write_byte(scale)
  448.     write_byte(brightness)
  449.     message_end()
  450. }
  451.  
  452. stock normalize(Float:fIn[3], Float:fOut[3], Float:fMul) // By sontung0
  453. {
  454.     new Float:fLen = xs_vec_len(fIn)
  455.     xs_vec_copy(fIn, fOut)
  456.    
  457.     fOut[0] /= fLen, fOut[1] /= fLen, fOut[2] /= fLen
  458.     fOut[0] *= fMul, fOut[1] *= fMul, fOut[2] *= fMul
  459. }
  460.  
  461. stock str_count(const str[], searchchar) // By Twilight Suzuka
  462. {
  463.     new count, i, len = strlen(str)
  464.    
  465.     for (i = 0; i <= len; i++)
  466.     {
  467.         if(str[i] == searchchar)
  468.             count++
  469.     }
  470.    
  471.     return count;
  472. }
  473.  
  474. stock remove_ent_by_class(classname[])
  475. {
  476.     new nextitem  = find_ent_by_class(-1, classname)
  477.     while(nextitem)
  478.     {
  479.         remove_entity(nextitem)
  480.         nextitem = find_ent_by_class(-1, classname)
  481.     }
  482. }
He who fails to plan is planning to fail

Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Who is online

Users browsing this forum: No registered users and 1 guest