PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#define PLUGIN "Simple VIP"
#define VERSION "1.0"
#define AUTHOR "author"
#define MAX_PLAYERS 32
#define ACCESS_LEVEL ADMIN_KICK
new bool:isVip[MAX_PLAYERS+1]
new g_sHudMsg[8]
new pCvarMinRounds
new g_iRounds, g_iVipId
enum Teams
{
CTs,
Ts
}
new g_iScores[Teams]
const XO_WEAPON = 4
const m_pPlayer = 41
const m_flNextPrimaryAttack = 46
const TASK_HUDMESSAGE = 5031
const TASK_SHOW_RADAR = 5032
new msg_HostagePos, msg_HostageK
new bool:g_bVIPMode
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
msg_HostagePos = get_user_msgid("HostagePos")
msg_HostageK = get_user_msgid("HostageK")
for(new i;i < sizeof g_sHudMsg;i++)
{
g_sHudMsg[i] = CreateHudSyncObj()
}
pCvarMinRounds = register_cvar("vipmod_rounds", "10")
RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_c4", "CC4_PrimaryAttack")
RegisterHam(Ham_Spawn, "player", "HamPlayerSpawnPost", 1)
register_event("SendAudio", "roundEnd","a","2=%!MRAD_terwin","2=%!MRAD_ctwin","2=%!MRAD_rounddraw")
register_event("DeathMsg", "deathMsg", "a")
register_event("SendAudio", "event_CTsWin", "a", "1=0", "2=%!MRAD_ctwin")
register_clcmd("jointeam", "cmdJoinTeam")
register_clcmd("say", "checkSay")
}
public event_CTsWin()
{
if(g_bVIPMode)
{
set_hudmessage(random_num(0, 255), random_num(0, 255), random_num(0, 255), -1.0, 0.20, 1, 1.0, 4.0)
ShowSyncHudMsg(0, g_sHudMsg[6], "The VIP has survived!^nCounter-Terrorists, good job!")
set_task(3.0, "cmdRR")
g_iScores[CTs]++
}
}
public roundEnd()
{
if(g_bVIPMode)
{
if(g_iRounds < get_pcvar_num(pCvarMinRounds))
{
g_iRounds++
}
else
{
DisableVIPMode()
set_hudmessage(random_num(0, 255), random_num(0, 255), random_num(0, 255), -1.0, 0.20, 1, 1.0, 4.0)
ShowSyncHudMsg(0, g_sHudMsg[3], "%d rounds has passed!^nfinishing the VIP Mode...", get_pcvar_num(pCvarMinRounds))
console_print(0, "[AMXX]: %d rounds has passed. Finishing the VIP Mode...", get_pcvar_num(pCvarMinRounds))
}
}
}
public deathMsg()
{
if(g_bVIPMode)
{
new iKiller = read_data(1)
new iVictim = read_data(2)
remove_task(iVictim+TASK_SHOW_RADAR)
if(isVip[iVictim])
{
g_iScores[Ts]++
if(!IsLastCT())
{
g_iRounds++
}
new szKillerName[MAX_PLAYERS], szVipName[MAX_PLAYERS]
get_user_name(iKiller, szKillerName, charsmax(szKillerName))
get_user_name(iVictim, szVipName, charsmax(szVipName))
set_hudmessage(random_num(0, 255), random_num(0, 255), random_num(0, 255), -1.0, 0.20, 1, 1.0, 4.0)
ShowSyncHudMsg(0, g_sHudMsg[0], "%s has killed the VIP %s^nCounter-Terrorists, you guys sucks!", szKillerName, szVipName)
client_print(0, print_chat, "[AMXX]: %s has killed the VIP %s, Counter-Terrorists, you guys sucks!", szKillerName, szVipName)
set_task(3.0, "cmdRR")
}
}
}
public CC4_PrimaryAttack(iC4)
{
if(g_bVIPMode)
{
client_print(get_pdata_cbase(iC4, m_pPlayer, XO_WEAPON), print_chat, "VIP Mode ON. C4 disabled!")
set_pdata_float(iC4, m_flNextPrimaryAttack, 1.0, XO_WEAPON)
return HAM_SUPERCEDE
}
return HAM_IGNORED
}
public cmdRR()
{
server_cmd("sv_restart 1")
}
public client_disconnect(id)
{
if(g_bVIPMode)
{
if(isVip[id])
{
isVip[id] = false
remove_task(TASK_HUDMESSAGE)
new szVipName[MAX_PLAYERS]
get_user_name(id, szVipName, charsmax(szVipName))
set_hudmessage(random_num(0, 255), random_num(0, 255), random_num(0, 255), -1.0, 0.20, 1, 1.0, 4.0)
ShowSyncHudMsg(0, g_sHudMsg[2], "The VIP %s has disconnected^nselecting another VIP...", szVipName)
client_print(0, print_chat, "The VIP %s has disconnected. Selecting another VIP...", szVipName)
set_task(3.0, "selectRandomPlayerFromCT")
}
}
}
public HamPlayerSpawnPost(id)
{
if(!g_bVIPMode)
return HAM_IGNORED
if(!is_user_alive(id))
return HAM_IGNORED
if(cs_get_user_team(id) == CS_TEAM_T)
{
set_hudmessage(random_num(0, 255), random_num(0, 255), random_num(0, 255), -1.0, 0.20, 1, 1.0, 4.0)
ShowSyncHudMsg(id, g_sHudMsg[5], "KILL THE VIP!")
}
else
{
if(g_iVipId != id)
{
new szVipName[MAX_PLAYERS]
get_user_name(g_iVipId, szVipName, charsmax(szVipName))
set_hudmessage(random_num(0, 255), random_num(0, 255), random_num(0, 255), -1.0, 0.20, 1, 1.0, 4.0)
ShowSyncHudMsg(id, g_sHudMsg[1], "%s is the VIP, protect him!", szVipName)
if(!task_exists(id+TASK_SHOW_RADAR))
{
set_task(1.0, "VIP_RadarScan", id+TASK_SHOW_RADAR, .flags = "b")
}
}
else
{
set_hudmessage(random_num(0, 255), random_num(0, 255), random_num(0, 255), -1.0, 0.20, 1, 1.0, 4.0)
ShowSyncHudMsg(id, g_sHudMsg[7], "You are the VIP!^nDon't die! Good luck!")
}
}
return HAM_IGNORED
}
public checkSay(id)
{
new szArgs[9]
read_argv(1, szArgs, charsmax(szArgs))
remove_quotes(szArgs)
if(equal(szArgs, "/vipmode"))
{
if(access(id, ACCESS_LEVEL))
{
switch(g_bVIPMode)
{
case true:
{
DisableVIPMode()
}
case false:
{
g_bVIPMode = true
set_task(3.0, "selectRandomPlayerFromCT")
}
}
new szAdminName[MAX_PLAYERS]
get_user_name(id, szAdminName, charsmax(szAdminName))
client_print(0, print_chat, "[AMXX]: ADMIN %s has %sabled the VIP mod!", szAdminName ,g_bVIPMode ? "en" : "dis")
return PLUGIN_HANDLED
}
else
{
client_print(id, print_chat, "[AMXX]: You haven't access to this command!")
return PLUGIN_HANDLED
}
}
return PLUGIN_CONTINUE
}
public VIP_RadarScan(playerid)
{
playerid -= TASK_SHOW_RADAR
new VIPCoords[3]
new iPlayers[MAX_PLAYERS], iPlayersNum, id
get_players(iPlayers, iPlayersNum, "aeh", "CT")
for(new i;i < iPlayersNum;i++)
{
id = iPlayers[i]
if(isVip[id])
{
get_user_origin(id, VIPCoords)
message_begin(MSG_ONE_UNRELIABLE, msg_HostagePos, {0,0,0}, playerid)
write_byte(id)
write_byte(i)
write_coord(VIPCoords[0])
write_coord(VIPCoords[1])
write_coord(VIPCoords[2])
message_end()
message_begin(MSG_ONE_UNRELIABLE, msg_HostageK, {0,0,0}, playerid)
write_byte(i)
message_end()
}
}
}
public cmdJoinTeam(id)
{
if(g_bVIPMode)
{
if(!is_user_admin(id) || isVip[id])
{
console_print(id, "[AMXX]: You cannot until the VIP Mode finishs.")
return PLUGIN_HANDLED
}
}
return PLUGIN_CONTINUE
}
public selectRandomPlayerFromCT()
{
new iPlayers[MAX_PLAYERS], iPlayersNum
get_players(iPlayers, iPlayersNum, "eh", "CT")
if(!iPlayersNum)
return
new iRandomPlayer = iPlayers[random(iPlayersNum)]
if(get_user_flags(iRandomPlayer) & ACCESS_LEVEL)
{
isVip[iRandomPlayer] = true
g_iVipId = iRandomPlayer
new szRandomPlayerName[32]
get_user_name(iRandomPlayer, szRandomPlayerName, charsmax(szRandomPlayerName))
set_task(1.0, "pHudMessage", TASK_HUDMESSAGE, .flags = "b")
client_print(0, print_chat, "[AMXX]: Random player selected: %s. Starting the VIP Mod...", szRandomPlayerName)
set_task(1.5, "cmdRR")
}
}
public pHudMessage()
{
set_hudmessage(0, 255, 0, -1.0, 0.0, 0, 1.0, 1.0)
ShowSyncHudMsg(0, g_sHudMsg[4], "[ VIP Mode enabled ]^n[ Round: %d | Remaining: %d ]^n[ CTs: %d | Ts: %d ]", g_iRounds, get_pcvar_num(pCvarMinRounds) - g_iRounds, g_iScores[CTs], g_iScores[Ts])
}
IsLastCT()
{
new iPlayers[MAX_PLAYERS], iPlayersNum
get_players(iPlayers, iPlayersNum, "eh", "CT")
return (iPlayersNum == 1) ? true : false
}
DisableVIPMode()
{
g_iRounds = 0
g_bVIPMode = false
g_iVipId = 0
for(new i;i < sizeof g_iScores;i++)
{
g_iScores[Teams:i] = 0
}
set_task(2.0, "cmdRR")
remove_task(TASK_HUDMESSAGE)
new iPlayers[MAX_PLAYERS], iPlayersNum, iPlayer
get_players(iPlayers, iPlayersNum, "eh", "CT")
for(new i;i < iPlayersNum;i++)
{
iPlayer = iPlayers[i]
remove_task(iPlayer+TASK_SHOW_RADAR)
if(isVip[iPlayer])
{
isVip[iPlayer] = false
}
}
}