Quote:
Originally Posted by KliPPy
You should post what you are really trying to do, this looks like an XY problem.
|
There will surely be a much better plugin released soon enough as Natsheh and others are working on it, but until then I am trying to make my own version of
this plugin because I want it on my server.
I am a beginner and I'm trying to learn by doing, so to keep it simple my plugin only aims to display what grenades players have at the moment.
Code:
/*
BUGS:
Sprite still spawns after freezetime is over.
*/
#include <amxmodx>
#include <amxmisc>
#include <amxmodx>
#include <hamsandwich>
#include <cstrike>
#include <engine>
#include <fun>
#define PLUGIN "gn_shownades"
#define VERSION "0.1"
#define AUTHOR "GoldNux"
#define TEST_SPRITE "sprites/ic5.spr"
//#define HE_SPRITE "sprites/HE.spr"
//#define FLASH_SPRITE "sprites/FLASH.spr"
//#define SMOKE_SPRITE "sprites/SMOKE.spr"
new freezeTime = 0
new g_test_sprite;
//new g_he_sprite;
//new g_flash_sprite;
//new g_smoke_sprite;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_event("HLTV", "eventNewRound", "a", "1=0", "2=0");
RegisterHam(Ham_AddPlayerItem, "player", "eventPurchase");
register_cvar("gn_shownades", "0")
}
public plugin_precache()
{
g_test_sprite = precache_model(TEST_SPRITE);
//g_he_sprite = precache_model(HE_SPRITE);
//g_flash_sprite = precache_model(FLASH_SPRITE);
//g_smoke_sprite = precache_model(SMOKE_SPRITE);
}
public eventNewRound()
{
if (!get_cvar_num("gn_shownades"))
freezeTime = 1
new players[32]
new playercount, i
get_players(players, playercount)
for (i = 0; i < playercount; i++)
set_task(9.0, "removeSprites", players[i]) //Remove sprites when freezetime is over
return PLUGIN_CONTINUE
}
public eventPurchase()
{
if (!get_cvar_num("gn_shownades") && freezeTime == 1)
return PLUGIN_CONTINUE
new players[32]
new playercount, i
get_players(players, playercount)
for (i = 0; i < playercount; i++)
set_task(0.0, "nadeCheck", players[i])
return PLUGIN_CONTINUE
}
public nadeCheck(id)
{
if (is_user_alive(id) && cs_get_user_team(id) != CS_TEAM_SPECTATOR && !is_user_hltv(id))
{
if (user_has_weapon(id, CSW_HEGRENADE))
{
new vec1[3]
get_user_origin(id, vec1)
message_begin(MSG_ALL, SVC_TEMPENTITY);
write_byte(TE_PLAYERATTACHMENT);
write_byte(id);
write_coord(45); //Find out how to place sprites next to each other
write_short(g_test_sprite); //Change to g_he_sprite
write_short(200);
message_end();
}
else if (user_has_weapon(id, CSW_FLASHBANG))
{
new vec1[3]
get_user_origin(id, vec1)
message_begin(MSG_ALL, SVC_TEMPENTITY);
write_byte(TE_PLAYERATTACHMENT);
write_byte(id);
write_coord(45); //Find out how to place sprites next to each other
write_short(g_test_sprite); //Change to g_flash_sprite
write_short(200);
message_end();
}
else if(user_has_weapon(id, CSW_SMOKEGRENADE))
{
new vec1[3]
get_user_origin(id, vec1)
message_begin(MSG_ALL, SVC_TEMPENTITY);
write_byte(TE_PLAYERATTACHMENT);
write_byte(id);
write_coord(45); //Find out how to place sprites next to each other
write_short(g_test_sprite); //Change to g_smoke_sprite
write_short(200);
message_end();
}
}
return PLUGIN_CONTINUE
}
public removeSprites(id)
{
message_begin(MSG_ALL, SVC_TEMPENTITY);
write_byte(TE_KILLPLAYERATTACHMENTS)
write_byte(id)
message_end();
freezeTime = 0
}
__________________