/* Plugin Template generated by Pawn Studio */
#include <sourcemod>
#include <sdktools>
#include <sdktools_functions>
#include <sdkhooks>
#define SOUND_PIPEBOMB "weapons/hegrenade/beep.wav"
#define SOUND_BLIP "UI/Beep07.wav"
new ItemEnt[ MAXPLAYERS+1];
new Handle:Timer[MAXPLAYERS+1];
new Float:Energe[MAXPLAYERS+1];
new g_destory_ent=0;
new g_create_ent=0;
public Plugin:myinfo =
{
name = "Gas tank bomb", //名字
author = "XiaoHai", //作者
description = "<- Description ->",
version = "1.0",
url = "<- URL ->"
}
new Handle:l4d_bomb_enable;
new Handle:l4d_bomb_delay;
new Handle:l4d_bomb_set_time;
new Handle:l4d_bomb_attract_infected;
public OnPluginStart()
{
CreateConVar("l4d_bomb_version", "1.0", "",FCVAR_PLUGIN);
l4d_bomb_enable = CreateConVar("l4d_bomb_enable", "1", "{0,1}", FCVAR_PLUGIN);
l4d_bomb_delay = CreateConVar("l4d_bomb_explode_delay", "3.0", "seconds", FCVAR_PLUGIN);
l4d_bomb_set_time = CreateConVar("l4d_bomb_set_time", "7.0", "seconds", FCVAR_PLUGIN);
l4d_bomb_attract_infected = CreateConVar("l4d_bomb_attract_infected", "1", "{0, 1}", FCVAR_PLUGIN);
HookEvent("player_use", player_use);
HookEvent("round_start", RoundStart);
for (new i=1;i<=MaxClients;i++)
{
Timer[i]=INVALID_HANDLE;
Energe[i]=0.0;
g_destory_ent=0;
g_create_ent=0;
}
AutoExecConfig(true, "l4d_bomb_v10");
}
public OnMapStart()
{
InitPrecache();
}
InitPrecache()
{
PrecacheSound(SOUND_PIPEBOMB, true) ;
PrecacheSound(SOUND_BLIP, true);
}
public Action:RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
for (new i=1;i<=MaxClients;i++)
{
g_destory_ent=0;
g_create_ent=0;
StopTimer(i);
}
}
public Action:player_use(Handle:hEvent, const String:strName[], bool:DontBroadcast)
{
if(GetConVarInt(l4d_bomb_enable)>0)
{
new client = GetClientOfUserId(GetEventInt(hEvent, "userid"));
new ent=GetEventInt(hEvent, "targetid");
if(client > 0 && ent>0 && IsValidEdict(ent) && IsValidEntity(ent))
{
decl String:name[100];
GetClientWeapon(client, name, 100);
//PrintToChatAll("%N use %s", client ,name);
if(ItemOk(name))
{
StopTimer(client);
ItemEnt[client]=g_create_ent;
Timer[client]=CreateTimer(0.5, checkitem, client, TIMER_REPEAT);
}
}
}
return Plugin_Continue;
}
public Action:checkitem(Handle:timer, any:client)
{
if (IsClientInGame(client) && IsPlayerAlive(client))
{
decl String:name[100];
GetClientWeapon(client, name, 100);
if(ItemOk(name))
{
new b=GetClientButtons(client);
if(b & IN_ATTACK2)
{
Energe[client]=0.0;
}
if(b & IN_DUCK)
{
Energe[client]+=0.5;
if(Energe[client]<=GetConVarFloat(l4d_bomb_set_time))
{
decl Float:pos[3];
GetClientEyePosition(client, pos);
//EmitAmbientSound(SOUND_BLIP, pos, client, SNDLEVEL_RAIDSIREN);
EmitSoundToAll(SOUND_BLIP, 0, SNDCHAN_WEAPON, SNDLEVEL_TRAFFIC, SND_NOFLAGS, SNDVOL_NORMAL, 100, _, pos, NULL_VECTOR, false, 0.0);
}
}
if(Energe[client]>GetConVarFloat(l4d_bomb_set_time))
{
PrintHintText(client, "bomb set sucessfully, now drop it");
}
else
{
if(Energe[client]==0.0)PrintHintText(client, "duck to set bomb");
else PrintHintText(client, "set bomb progress %d%%", RoundFloat(Energe[client]/GetConVarFloat(l4d_bomb_set_time)*100.0));
//ShowBar(client, "bomb progress", Energe[client], GetConVarFloat(l4d_bomb_set_time));
}
}
else if(Energe[client]>GetConVarFloat(l4d_bomb_set_time))
{
PrepareBomb(client);
return StopTimer(client);
}
else
{
return StopTimer(client);
}
}
else
{
return StopTimer(client);
}
return Plugin_Continue;
}
PrepareBomb(client)
{
new ent=ItemEnt[client];
if(EntOk(ent))
{
new chase=0;
new particle=0;
if(GetConVarInt(l4d_bomb_attract_infected)>0)
{
decl Float:pos[3];
GetEntPropVector(ent, Prop_Send, "m_vecOrigin", pos);
decl String:tName[128];
Format(tName, sizeof(tName), "bomb%i", ent);
DispatchKeyValue(ent, "targetname", tName);
chase = CreateEntityByName("info_goal_infected_chase");
decl String:chase_name[128];
Format(chase_name, sizeof(chase_name), "chase%i", chase);
DispatchKeyValue(chase,"targetname", chase_name);
DispatchKeyValue(chase, "parentname", tName);
DispatchSpawn(chase);
TeleportEntity(chase, pos, NULL_VECTOR, NULL_VECTOR);
SetVariantString(tName);
AcceptEntityInput(chase, "SetParent", chase, chase, 0);
SetVariantString("forward");
AcceptEntityInput(chase, "Enable");
particle=AttachParticle(chase, "weapon_pipebomb_blinking_light", pos);
}
new Handle:data = CreateDataPack();
WritePackCell(data, client);
WritePackCell(data, ItemEnt[client]);
WritePackFloat(data,GetEngineTime());
WritePackFloat(data,GetEngineTime()+GetConVarFloat(l4d_bomb_delay));
WritePackCell(data, chase);
WritePackCell(data, particle);
ItemEnt[client]=0;
CreateTimer(0.5, ShowEffect, data, TIMER_REPEAT);
}
}
public Action:ShowEffect(Handle:timer, Handle:data)
{
ResetPack(data);
new client=ReadPackCell(data);
new ent=ReadPackCell(data);
new Float:starttime=ReadPackFloat(data);
new Float:endtime=ReadPackFloat(data);
new chase=ReadPackCell(data);
new particle=ReadPackCell(data);
new Float:time=GetEngineTime();
if(EntOk(ent))
{
if(time<endtime)
{
if(IsClientInGame(client))PrintHintText(client, "time left %d", RoundFloat(endtime-time));
decl Float:pos[3];
GetEntPropVector(ent, Prop_Send, "m_vecOrigin", pos);
EmitSoundToAll(SOUND_PIPEBOMB, 0, SNDCHAN_WEAPON, SNDLEVEL_TRAFFIC, SND_NOFLAGS, SNDVOL_NORMAL, 100, _, pos, NULL_VECTOR, false, 0.0);
return Plugin_Continue;
}
else
{
DeleteParticles(INVALID_HANDLE, particle);
SafeDeleteEntity(chase, "info_goal_infected_chase");
if(EntOk(ent))
{
AcceptEntityInput(ent, "break" );
if(IsClientInGame(client))PrintHintText(client, "bomb exploded");
}
CloseHandle(data);
return Plugin_Stop;
}
}
else
{
CloseHandle(data);
return Plugin_Stop;
}
}
public Action:StopTimer(client)
{
Energe[client]=0.0;
if(Timer[client]!=INVALID_HANDLE)
{
KillTimer(Timer[client]);
}
Timer[client]=INVALID_HANDLE;
return Plugin_Stop;
}
EntOk(ent)
{
if(ent>0 && IsValidEdict(ent) && IsValidEntity(ent))
{
decl String:m_ModelName[PLATFORM_MAX_PATH];
GetEntPropString(ent, Prop_Data, "m_ModelName", m_ModelName, sizeof(m_ModelName));
return ItemModelOk(m_ModelName);
}
return 0;
}
ItemOk(const String:strName[])
{
if(StrEqual(strName, "weapon_oxygentank") ) return 1;
else if(StrEqual(strName, "weapon_propanetank") ) return 1;
else return 0;
}
ItemModelOk(const String:strName[])
{
if(StrContains(strName, "oxygentank01")!=-1) return 1;
else if(StrContains(strName, "propanecanister001a.mdl")!=-1) return 1;
else return 0;
}
public OnEntityDestroyed(entity)
{
if(entity>0 && IsValidEdict(entity) && IsValidEntity(entity))
{
decl String:g_classname[20];
GetEdictClassname(entity, g_classname, 20);
decl String:m_ModelName[PLATFORM_MAX_PATH];
GetEntPropString(entity, Prop_Data, "m_ModelName", m_ModelName, sizeof(m_ModelName));
//PrintToChatAll("destory %s %d ", m_ModelName, entity);
if(ItemModelOk(m_ModelName))
{
g_destory_ent=entity;
new find=0;
for (new i=1;i<=MaxClients;i++)
{
if(entity==ItemEnt[i])
{
find=i;
break;
}
}
if(find)
{
//PrintToChatAll(" find %d -> %d", ItemEnt[find], g_create_ent);
ItemEnt[find]=g_create_ent;
}
}
}
}
public OnEntityCreated(entity, const String:classname[])
{
if(entity>0 && IsValidEdict(entity) && IsValidEntity(entity))
{
if(ItemOk(classname))
{
g_create_ent=entity;
//PrintToChatAll("created %s %d", classname, entity);
}
else if(StrEqual(classname, "physics_prop"))
{
//PrintToChatAll("created %s %d", classname, entity);
g_create_ent=entity;
}
}
}
new String:Gauge1[2] = "-";
new String:Gauge3[2] = "#";
ShowBar(client, String:msg[], Float:pos, Float:max)
{
new i ;
new String:ChargeBar[100];
Format(ChargeBar, sizeof(ChargeBar), "");
new Float:GaugeNum = pos/max*100;
if(GaugeNum > 100.0)
GaugeNum = 100.0;
if(GaugeNum<0.0)
GaugeNum = 0.0;
for(i=0; i<100; i++)
ChargeBar[i] = Gauge1[0];
new p=RoundFloat( GaugeNum);
if(p>=0 && p<100)ChargeBar[p] = Gauge3[0];
/* Display gauge */
PrintCenterText(client, "%s %3.0f %\n<< %s >>", msg, GaugeNum, ChargeBar);
}
public AttachParticle(i_Ent, String:s_Effect[], Float:f_Origin[3])
{
decl i_Particle, String:s_TargetName[32];
i_Particle = CreateEntityByName("info_particle_system");
if(i_Particle>0 && IsValidEdict(i_Particle) && IsValidEntity(i_Particle))
{
f_Origin[2] -= 7.5;
TeleportEntity(i_Particle, f_Origin, NULL_VECTOR, NULL_VECTOR)
FormatEx(s_TargetName, sizeof(s_TargetName), "particle%d", i_Ent)
DispatchKeyValue(i_Particle, "targetname", s_TargetName)
GetEntPropString(i_Ent, Prop_Data, "m_iName", s_TargetName, sizeof(s_TargetName))
DispatchKeyValue(i_Particle, "parentname", s_TargetName)
DispatchKeyValue(i_Particle, "effect_name", s_Effect)
DispatchSpawn(i_Particle)
SetVariantString(s_TargetName)
AcceptEntityInput(i_Particle, "SetParent", i_Particle, i_Particle, 0)
ActivateEntity(i_Particle)
AcceptEntityInput(i_Particle, "Start")
}
else i_Particle=0;
return i_Particle
}
public Action:DeleteParticles(Handle:timer, any:particle)
{
if(particle>0 && IsValidEdict(particle) && IsValidEntity(particle))
{
decl String:classname[64];
GetEdictClassname(particle, classname, sizeof(classname));
if (StrEqual(classname, "info_particle_system", false))
{
AcceptEntityInput(particle, "stop");
AcceptEntityInput(particle, "kill");
RemoveEdict(particle);
}
}
}
public SafeDeleteEntity(any:ent, String:name[])
{
if( ent>0 && IsValidEdict(ent) && IsValidEntity(ent))
{
decl String:classname[64];
GetEdictClassname(ent, classname, sizeof(classname));
if (StrEqual(classname, name, false))
{
AcceptEntityInput(ent, "Kill");
RemoveEdict(ent);
}
}
}
求生之路 给烟鬼坦克安装定时炸弹-源码
评论
(0)