Raised This Month: $32 Target: $400
 8% 

Hooking +attack?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 05-28-2009 , 01:20   Hooking +attack?
Reply With Quote #1

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.

Last edited by Spunky; 05-28-2009 at 02:17.
Spunky is offline
Send a message via AIM to Spunky
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 05-28-2009 , 03:26   Re: Hooking +attack?
Reply With Quote #2

AFAIK +attack can't be hooked. Try using an extension.
__________________
For admins: My plugins

For developers: Colors library
exvel is offline
Send a message via ICQ to exvel
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 05-28-2009 , 03:48   Re: Hooking +attack?
Reply With Quote #3

What do you mean?
Spunky is offline
Send a message via AIM to Spunky
paegus
Senior Member
Join Date: Nov 2004
Location: Extreme low earth orbit
Old 05-28-2009 , 04:51   Re: Hooking +attack?
Reply With Quote #4

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.
__________________
Live and learn or die and teach by example.
Plugins Mine | Hidden:SourceMod
paegus is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 05-28-2009 , 05:56   Re: Hooking +attack?
Reply With Quote #5

Hook this event

http://wiki.alliedmods.net/Left_4_De...ts#weapon_fire
__________________
CrimsonGT is offline
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 05-29-2009 , 01:57   Re: Hooking +attack?
Reply With Quote #6

How would I hook it? Sorry, I'm really completely new to SM.
Spunky is offline
Send a message via AIM to Spunky
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 05-29-2009 , 03:39   Re: Hooking +attack?
Reply With Quote #7

HookEvent("weapon_fire", Event_WeaponFire);

and make a callback.
__________________
CrimsonGT is offline
Wazz
SourceMod Donor
Join Date: Mar 2009
Old 05-29-2009 , 08:15   Re: Hooking +attack?
Reply With Quote #8

http://wiki.alliedmods.net/Events_(SourceMod_Scripting)
That alongside what Crimson has said should get you going
Wazz is offline
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 05-29-2009 , 08:41   Re: Hooking +attack?
Reply With Quote #9

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 }
Spunky is offline
Send a message via AIM to Spunky
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 05-29-2009 , 08:45   Re: Hooking +attack?
Reply With Quote #10

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.
__________________
CrimsonGT is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:50.


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