AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Hooking +attack? (https://forums.alliedmods.net/showthread.php?t=93368)

Spunky 05-28-2009 01:20

Hooking +attack?
 
How would I hook +attack to check for a condition? I'm just now starting out in SM.

Edit: I should elaborate on what I'm trying to do since I've hooked the command and it's not working.

Code:
#include <sourcemod> new bool:g_bModeToggle[32] public Plugin:myinfo = {     name = "Fire Mode",     author = "Spunky",     description = "Allows players to fire a single round every time",     version = "1.0",     url = "" }; public OnPluginStart() {     RegConsoleCmd("+spec_attack", cmd_attack)     RegConsoleCmd("l4d_firemode", cmd_firemode) } public Action:cmd_attack(client, args) {     if (g_bModeToggle[client - 1])     {         ClientCommand(client, "+attack")         ClientCommand(client, "-attack")         return Plugin_Handled     }     return Plugin_Continue } public Action:cmd_firemode(client, args) {     new iIndex = client - 1     if (g_bModeToggle[iIndex])     {         g_bModeToggle[iIndex] = false         PrintToChat(client, "[L4D] You have switched firing mode to full-auto.")     }     else     {         g_bModeToggle[iIndex] = true         PrintToChat(client, "[L4D] You have switched firing mode to semi-auto.")     }     return Plugin_Handled }

As you can see, I just want to create a semi-auto firing mode for L4D but it's not working.

exvel 05-28-2009 03:26

Re: Hooking +attack?
 
AFAIK +attack can't be hooked. Try using an extension.

Spunky 05-28-2009 03:48

Re: Hooking +attack?
 
What do you mean?

paegus 05-28-2009 04:51

Re: Hooking +attack?
 
he means that there are extensions (namely Duke Hacks) that may be able to do this for you. You can find them in the Extensions/Snippets forum.

alternatively you can use the dreaded OnGameFrame to detect the IN_ATTACK button flag. but I don't think ClientCommand will work that well for the -attack command.

CrimsonGT 05-28-2009 05:56

Re: Hooking +attack?
 
Hook this event

http://wiki.alliedmods.net/Left_4_De...ts#weapon_fire

Spunky 05-29-2009 01:57

Re: Hooking +attack?
 
How would I hook it? Sorry, I'm really completely new to SM.

CrimsonGT 05-29-2009 03:39

Re: Hooking +attack?
 
HookEvent("weapon_fire", Event_WeaponFire);

and make a callback.

Wazz 05-29-2009 08:15

Re: Hooking +attack?
 
http://wiki.alliedmods.net/Events_(SourceMod_Scripting)
That alongside what Crimson has said should get you going

Spunky 05-29-2009 08:41

Re: Hooking +attack?
 
Hmm. I still can't quite figure out how to limit it to just 1 shot per click though.

Code:
#include <sourcemod> new bool:g_bModeToggle[32] public Plugin:myinfo = {     name = "Fire Mode",     author = "Spunky",     description = "Allows players to fire a single round every time",     version = "1.0",     url = "" }; public OnPluginStart() {     HookEvent("weapon_fire", fnWeaponFire, EventHookMode_Pre)     RegConsoleCmd("l4d_firemode", cmd_firemode) } public Action:fnWeaponFire(Handle:hEvent, const String:szName[], bool:bDontBroadcast) {     new const client = GetClientOfUserId(GetEventInt(hEvent, "userid")), iIndex = client - 1     if (!g_bModeToggle[iIndex])         return Plugin_Continue     // We have ammo, so fire 1 shot     if (GetEventInt(hEvent, "count") > 0)     {     }     return Plugin_Handled } public Action:cmd_firemode(client, args) {     new iIndex = client - 1     if (g_bModeToggle[iIndex])     {         g_bModeToggle[iIndex] = false         PrintToChat(client, "[L4D] You have switched firing mode to full-auto.")     }     else     {         g_bModeToggle[iIndex] = true         PrintToChat(client, "[L4D] You have switched firing mode to semi-auto.")     }     return Plugin_Handled }

CrimsonGT 05-29-2009 08:45

Re: Hooking +attack?
 
Well you cant block an attack with just an event hook, thats simply a notification when they fire. What you can do is hook it, and add 0.1 to their m_flPrimaryAttack or whatever that netprop is, so they will have to wait 0.1 second before firing again.


All times are GMT -4. The time now is 12:42.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.