Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Plugin Template generated by Pawn Studio */
- #include <sourcemod>
- #include <sdktools>
- #include <sdktools_functions>
- #include <sdkhooks>
- new GrenadeLauncherClip[MAXPLAYERS+1];
- new GrenadeLauncherAmmo[MAXPLAYERS+1];
- new GrenadeLauncherReloadState[MAXPLAYERS+1];
- new WeaponEnt[MAXPLAYERS+1];
- new LastClip[MAXPLAYERS+1];
- new bool:Hooked[MAXPLAYERS+1];
- new Handle:l4d_gl_clips;
- new Handle:l4d_gl_count;
- new GameMode;
- new L4D2Version;
- new ammoOffset ;
- public Plugin:myinfo =
- {
- name = "Multi-Clip Grenade Launcher",
- author = "Pan Xiaohai",
- description = "need sdk hook",
- version = "1.3",
- url = "<- URL ->"
- }
- public OnPluginStart()
- {
- ammoOffset = FindSendPropInfo("CTerrorPlayer", "m_iAmmo");
- l4d_gl_clips = CreateConVar("l4d_gl_clips", "5", " max clips for grenade launcher, 0 disable this plugin", FCVAR_PLUGIN);
- l4d_gl_count = CreateConVar("l4d_gl_count", "2", "clip count for every reloading, must >0", FCVAR_PLUGIN);
- GameCheck();
- if(L4D2Version && GameMode!=2)
- {
- HookEvent("weapon_reload", weapon_reload );
- HookEvent("player_spawn", player_spawn);
- HookEvent("player_death", player_death);
- HookEvent("player_bot_replace", player_bot_replace );
- HookEvent("bot_player_replace", bot_player_replace );
- HookEvent("round_end", round_end );
- HookEvent("map_transition", round_end );
- }
- AutoExecConfig(true, "l4d_grenade_launcher_v11");
- }
- GameCheck()
- {
- decl String:GameName[16];
- GetConVarString(FindConVar("mp_gamemode"), GameName, sizeof(GameName));
- if (StrEqual(GameName, "survival", false))
- GameMode = 3;
- else if (StrEqual(GameName, "versus", false) || StrEqual(GameName, "teamversus", false) || StrEqual(GameName, "scavenge", false) || StrEqual(GameName, "teamscavenge", false))
- GameMode = 2;
- else if (StrEqual(GameName, "coop", false) || StrEqual(GameName, "realism", false))
- GameMode = 1;
- else
- {
- GameMode = 0;
- }
- GetGameFolderName(GameName, sizeof(GameName));
- if (StrEqual(GameName, "left4dead2", false))
- {
- L4D2Version=true;
- }
- else
- {
- L4D2Version=false;
- }
- L4D2Version=!!L4D2Version;
- }
- ResetClientState(client)
- {
- Hooked[client]=false;
- GrenadeLauncherReloadState[client]=0;
- WeaponEnt[client]=0;
- }
- public player_bot_replace(Handle:Spawn_Event, const String:Spawn_Name[], bool:Spawn_Broadcast)
- {
- new client = GetClientOfUserId(GetEventInt(Spawn_Event, "player"));
- new bot = GetClientOfUserId(GetEventInt(Spawn_Event, "bot"));
- ResetClientState(client);
- ResetClientState(bot);
- HookWeaponSwitch(client, false);
- HookWeaponSwitch(bot, false );
- }
- public bot_player_replace(Handle:Spawn_Event, const String:Spawn_Name[], bool:Spawn_Broadcast)
- {
- new client = GetClientOfUserId(GetEventInt(Spawn_Event, "player"));
- new bot = GetClientOfUserId(GetEventInt(Spawn_Event, "bot"));
- ResetClientState(client);
- ResetClientState(bot);
- HookWeaponSwitch(client, true);
- HookWeaponSwitch(bot, false );
- }
- public Action:player_spawn(Handle:hEvent, const String:strName[], bool:DontBroadcast)
- {
- new client = GetClientOfUserId(GetEventInt(hEvent, "userid"));
- ResetClientState(client);
- HookWeaponSwitch(client, true);
- }
- public Action:player_death(Handle:hEvent, const String:strName[], bool:DontBroadcast)
- {
- new client = GetClientOfUserId(GetEventInt(hEvent, "userid"));
- ResetClientState(client);
- HookWeaponSwitch(client, false);
- }
- public Action:weapon_reload (Handle:hEvent, const String:strName[], bool:DontBroadcast)
- {
- if(GetConVarInt(l4d_gl_clips)>1)
- {
- new client = GetClientOfUserId(GetEventInt(hEvent, "userid"));
- if(!Hooked[client])HookWeaponSwitch(client, true);
- }
- }
- new HookType=SDKHook_PreThink;
- public Action:OnWeaponSwitch(client, weapon)
- {
- if(GetConVarInt(l4d_gl_clips)>1)
- {
- new String:sweapon[32];
- GetEdictClassname(weapon, sweapon, 32);
- GrenadeLauncherReloadState[client]=0;
- //PrintToChatAll("switch %s", sweapon);
- if(StrEqual(sweapon, "weapon_grenade_launcher"))
- {
- SDKUnhook(client, HookType, GLPreThinkPostHook);
- SDKHook(client, HookType, GLPreThinkPostHook);
- //PrintToChatAll("start ");
- }
- else
- {
- SDKUnhook(client, HookType, GLPreThinkPostHook);
- //PrintToChatAll("end ");
- }
- }
- }
- HookWeaponSwitch(client, bool:hook)
- {
- if(client>0)
- {
- SDKUnhook(client, SDKHook_WeaponSwitch, OnWeaponSwitch);
- SDKUnhook(client, HookType, GLPreThinkPostHook);
- Hooked[client]=false;
- if(hook && IsClientInGame(client) && GetClientTeam(client)==2 && !IsFakeClient(client) && IsPlayerAlive(client))
- {
- SDKHook(client, SDKHook_WeaponSwitch, OnWeaponSwitch);
- Hooked[client]=true;
- //PrintToChatAll("Start HookWeaponSwitch");
- }
- }
- }
- public Action:round_end(Handle:event, const String:name[], bool:dontBroadcast)
- {
- for(new i=1; i<=MaxClients; i++)
- {
- if(IsClientInGame(i))
- {
- HookWeaponSwitch(i, false);
- }
- }
- }
- public GLPreThinkPostHook(client)
- {
- new launcher=0;
- launcher=GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon" );
- if(launcher<=0)return;
- decl String:weapon[64];
- GetEdictClassname(launcher, weapon, 64);
- if (!StrEqual(weapon, "weapon_grenade_launcher"))
- {
- return;
- }
- if(launcher!=WeaponEnt[client])
- {
- WeaponEnt[client]=launcher;
- }
- new inreload=GetEntProp(launcher, Prop_Send, "m_bInReload");
- new lastReloadState=GrenadeLauncherReloadState[client];
- new clip ,ammo;
- GetGrenadeLauncherAmmoClip(client, launcher, ammo, clip);
- if(inreload)
- {
- //PrintToChatAll("reloading ammo %d, clip %d", ammo, clip);
- if(!lastReloadState)
- {
- //PrintToChatAll("start reload %d", clip);
- SetGrenadeLauncherAmmoClip(client, launcher, GrenadeLauncherAmmo[client], GrenadeLauncherClip[client]);
- }
- }
- else
- {
- new button=GetClientButtons(client);
- if(lastReloadState && clip==1)
- {
- //PrintToChatAll("realod end ");
- clip=GrenadeLauncherClip[client]+GetConVarInt(l4d_gl_count);
- ammo=GrenadeLauncherAmmo[client]-GetConVarInt(l4d_gl_count);
- if(ammo<0)
- {
- new o=ammo;
- clip+=o;
- ammo=0;
- }
- if(clip>GetConVarInt(l4d_gl_clips))
- {
- new o=clip-GetConVarInt(l4d_gl_clips);
- clip=GetConVarInt(l4d_gl_clips);
- ammo+=o;
- }
- SetGrenadeLauncherAmmoClip(client, launcher, ammo, clip);
- }
- else if(!lastReloadState && clip==1 && (button & IN_RELOAD))
- {
- if(clip<GetConVarInt(l4d_gl_clips))
- {
- //PrintToChatAll("press reload");
- if(ForeceGrenadeLauncherReload(client, launcher))
- {
- GrenadeLauncherClip[client]=clip;
- GrenadeLauncherAmmo[client]=ammo;
- }
- }
- }
- GrenadeLauncherClip[client]=clip;
- GrenadeLauncherAmmo[client]=ammo;
- }
- GrenadeLauncherReloadState[client]=inreload;
- LastClip[client]=clip;
- return ;
- }
- ForeceGrenadeLauncherReload(client, launcher )
- {
- new bool:ok=false;
- if (launcher > 0)
- {
- new ammo;
- new clip;
- clip = GetEntProp(launcher, Prop_Send, "m_iClip1");
- ammo = GetEntData(client, ammoOffset+(68));
- if(ammo>0 && clip>0 && clip<GetConVarInt(l4d_gl_clips))
- {
- SetEntProp(launcher, Prop_Send, "m_iClip1", 0);
- ok=true;
- }
- }
- return ok;
- }
- GetGrenadeLauncherAmmoClip(client, launcher, &ammo, &clip )
- {
- clip = GetEntProp(launcher, Prop_Send, "m_iClip1");
- ammo = GetEntData(client, ammoOffset+(68));
- //ammo=GetEntProp(launcher, Prop_Send, "m_iExtraPrimaryAmmo");
- }
- SetGrenadeLauncherAmmoClip(client, launcher, ammo, clip )
- {
- SetEntData(client, ammoOffset+(68), ammo);
- SetEntProp(launcher, Prop_Send, "m_iClip1", clip);
- }
- HaveGrenadeLauncher(client)
- {
- new index=GetPlayerWeaponSlot(client, 0);
- if (index > 0)
- {
- new String:weapon[32];
- GetEdictClassname(index, weapon, 32);
- if (StrEqual(weapon, "weapon_grenade_launcher"))
- {
- }
- else
- {
- index=0;
- }
- }
- return index;
- }
- HoldGrenadeLauncher(client)
- {
- new g=0;
- new String:weapon[32];
- GetClientWeapon(client, weapon, 32);
- if (StrEqual(weapon, "weapon_grenade_launcher"))
- {
- g=HaveGrenadeLauncher(client);
- }
- return g;
- }
- //code from "DJ_WEST"
- public Action:DisplayHint(Handle:h_Timer, any:i_Client)
- {
- if ( IsClientInGame(i_Client)) ClientCommand(i_Client, "gameinstructor_enable 1")
- CreateTimer(0.3, DelayDisplayHint, i_Client)
- }
- public Action:DelayDisplayHint(Handle:h_Timer, any:i_Client)
- {
- DisplayInstructorHint(i_Client, "Press reload button to add a granade for grenade launcher", "+reload");
- }
- public DisplayInstructorHint(i_Client, String:s_Message[256], String:s_Bind[])
- {
- decl i_Ent, String:s_TargetName[32], Handle:h_RemovePack
- i_Ent = CreateEntityByName("env_instructor_hint")
- FormatEx(s_TargetName, sizeof(s_TargetName), "hint%d", i_Client)
- ReplaceString(s_Message, sizeof(s_Message), "\n", " ")
- DispatchKeyValue(i_Client, "targetname", s_TargetName)
- DispatchKeyValue(i_Ent, "hint_target", s_TargetName)
- DispatchKeyValue(i_Ent, "hint_timeout", "5")
- DispatchKeyValue(i_Ent, "hint_range", "0.01")
- DispatchKeyValue(i_Ent, "hint_color", "255 255 255")
- DispatchKeyValue(i_Ent, "hint_icon_onscreen", "use_binding")
- DispatchKeyValue(i_Ent, "hint_caption", s_Message)
- DispatchKeyValue(i_Ent, "hint_binding", s_Bind)
- DispatchSpawn(i_Ent)
- AcceptEntityInput(i_Ent, "ShowHint")
- h_RemovePack = CreateDataPack()
- WritePackCell(h_RemovePack, i_Client)
- WritePackCell(h_RemovePack, i_Ent)
- CreateTimer(5.0, RemoveInstructorHint, h_RemovePack)
- }
- public Action:RemoveInstructorHint(Handle:h_Timer, Handle:h_Pack)
- {
- decl i_Ent, i_Client
- ResetPack(h_Pack, false)
- i_Client = ReadPackCell(h_Pack)
- i_Ent = ReadPackCell(h_Pack)
- CloseHandle(h_Pack)
- if (!i_Client || !IsClientInGame(i_Client))
- return Plugin_Handled
- if (IsValidEntity(i_Ent))
- RemoveEdict(i_Ent)
- ClientCommand(i_Client, "gameinstructor_enable 0")
- DispatchKeyValue(i_Client, "targetname", "")
- return Plugin_Continue
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement