Raised This Month: $203 Target: $400
 50% 

[CS:GO] Force shoot & reload


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-06-2020 , 13:58   [CS:GO] Force shoot & reload
Reply With Quote #1

I'm trying to make a function that forces the player to shoot 1 bullet and then reload his weapon.
Basically, the equivalent of "+attack;-attack;+reload;-reload".

Using "FakeClientCommand" doesn't seem to work with '+' commands.
Using "ClientCommand" outputs "FCVAR_SERVER_CAN_EXECUTE prevented server running command" - can I disable this protection?

Any other methods for doing this consistently?
__________________


Dear admins. If somehow you managed to read this, plz fix.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
StrikeR14
AlliedModders Donor
Join Date: Apr 2016
Location: Behind my PC
Old 12-06-2020 , 14:46   Re: [CS:GO] Force shoot & reload
Reply With Quote #2

Use OnPlayerRunCmd buttons.

buttons =| IN_ATTACK
buttons =| IN_RELOAD

return Plugin_Changed when you apply button changes.
__________________
Currently taking TF2/CSGO paid private requests!

My Plugins | My Discord Account

Last edited by StrikeR14; 12-06-2020 at 14:47.
StrikeR14 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-12-2020 , 15:46   Re: [CS:GO] Force shoot & reload
Reply With Quote #3

Any idea why this doesn't work? The message isn't printed either.

Code:
bool g_bDoReload = false public OnPluginStart() {     RegConsoleCmd("testshoot", Cmd_TestShoot) } public Action Cmd_TestShoot(int id, int iArgs) {     g_bDoReload = true     return Plugin_Handled } public Action OnPlayerRunCmd(id, &iButtons) {     if(g_bDoReload)     {         PrintToChat(id, "Called!")         g_bDoReload = false         iButtons |= IN_ATTACK         iButtons |= IN_RELOAD         return Plugin_Changed     }     return Plugin_Continue }

Alternatively, can I somehow force the weapon's reload animation to play?
__________________


Dear admins. If somehow you managed to read this, plz fix.

Last edited by OciXCrom; 12-12-2020 at 16:12.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 12-12-2020 , 20:15   Re: [CS:GO] Force shoot & reload
Reply With Quote #4

For the animation you can try to crate & fire this event
https://wiki.alliedmods.net/Counter-...#weapon_reload
__________________
kratoss1812 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-13-2020 , 15:59   Re: [CS:GO] Force shoot & reload
Reply With Quote #5

Code:
public Action Cmd_TestShoot(int id, int iArgs) {     Event eReload = CreateEvent("weapon_reload")     if(eReload == null)     {         PrintToConsole(id, "Error while creating event.")         return Plugin_Handled     }     eReload.SetInt("userid", GetClientUserId(id))     eReload.Fire()     return Plugin_Handled }

I'm getting the error message.
What am I doing wrong?

Is there no function that can trigger a model's animation?
__________________


Dear admins. If somehow you managed to read this, plz fix.

Last edited by OciXCrom; 12-13-2020 at 16:00.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
eyal282
Veteran Member
Join Date: Aug 2011
Old 12-16-2020 , 07:00   Re: [CS:GO] Force shoot & reload
Reply With Quote #6

Idea:

1. In OnPlayerRunCmd, make the player attack when needed. In OnPlayerRunCmdPost make a variable that sees when the next shot can be fired. You cannot reload while unable to fire due to firing too recently.

2. Wait in OnPlayerRunCmd until you can fire again, then force IN_RELOAD.
__________________
I am looking for devs to help maintain some projects I have

Discord: Eyal282#1334
If you like my work, feel free to donate in appreciation with PayPal or CSGO Skins.

Total Donated: 15$
eyal282 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 12-16-2020 , 13:18   Re: [CS:GO] Force shoot & reload
Reply With Quote #7

I think you can't do RELOAD and FIRE at the same time.

If u gonna do buttons |= IN_RELOAD you should also do buttons &= ~IN_ATTACK
__________________
Marttt is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-17-2020 , 08:28   Re: [CS:GO] Force shoot & reload
Reply With Quote #8

Thank you! This worked. One last problem remains though.
When the player shoots, there is no gunfire sound and no bullet hole is created, even though players do take damage.

Code:
public Action Cmd_TestShoot(int id, int iArgs) {     g_bForceShoot = true     return Plugin_Handled } public Action OnPlayerRunCmd(id, &iButtons) {     if(g_bForceShoot)     {         PrintToChat(id, "Force shoot")         g_bForceShoot = false         iButtons &= ~IN_RELOAD         iButtons |= IN_ATTACK         g_bCheckNextShot = true         return Plugin_Changed     }     else if(g_bForceReload && GetGameTime() >= g_fDoReload)     {         PrintToChat(id, "Force reload")         g_bForceReload = false         iButtons &= ~IN_ATTACK         iButtons |= IN_RELOAD         return Plugin_Changed     }     return Plugin_Continue } public void OnPlayerRunCmdPost(id, iButtons) {     if(g_bCheckNextShot)     {         g_bForceReload = true         g_bCheckNextShot = false         g_fDoReload = GetEntPropFloat(GetEntPropEnt(id, Prop_Send, "m_hActiveWeapon"), Prop_Send, "m_flNextPrimaryAttack")         PrintToChat(id, "Next shot in %f", g_fDoReload)     } }
__________________


Dear admins. If somehow you managed to read this, plz fix.

Last edited by OciXCrom; 12-17-2020 at 08:29.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
eyal282
Veteran Member
Join Date: Aug 2011
Old 12-17-2020 , 09:04   Re: [CS:GO] Force shoot & reload
Reply With Quote #9

Quote:
Originally Posted by OciXCrom View Post
Thank you! This worked. One last problem remains though.
When the player shoots, there is no gunfire sound and no bullet hole is created, even though players do take damage.

Code:
public Action Cmd_TestShoot(int id, int iArgs) {     g_bForceShoot = true     return Plugin_Handled } public Action OnPlayerRunCmd(id, &iButtons) {     if(g_bForceShoot)     {         PrintToChat(id, "Force shoot")         g_bForceShoot = false         iButtons &= ~IN_RELOAD         iButtons |= IN_ATTACK         g_bCheckNextShot = true         return Plugin_Changed     }     else if(g_bForceReload && GetGameTime() >= g_fDoReload)     {         PrintToChat(id, "Force reload")         g_bForceReload = false         iButtons &= ~IN_ATTACK         iButtons |= IN_RELOAD         return Plugin_Changed     }     return Plugin_Continue } public void OnPlayerRunCmdPost(id, iButtons) {     if(g_bCheckNextShot)     {         g_bForceReload = true         g_bCheckNextShot = false         g_fDoReload = GetEntPropFloat(GetEntPropEnt(id, Prop_Send, "m_hActiveWeapon"), Prop_Send, "m_flNextPrimaryAttack")         PrintToChat(id, "Next shot in %f", g_fDoReload)     } }
Try making the button pressed for more than one forward fire?
__________________
I am looking for devs to help maintain some projects I have

Discord: Eyal282#1334
If you like my work, feel free to donate in appreciation with PayPal or CSGO Skins.

Total Donated: 15$
eyal282 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-17-2020 , 13:49   Re: [CS:GO] Force shoot & reload
Reply With Quote #10

That made it shoot out more bullets, but still no sound and visual effect.

Code:
public Action Cmd_TestShoot(int id, int iArgs) {     g_bForceShoot = true
    g_iCurrentCalls = 10
    return Plugin_Handled } public Action OnPlayerRunCmd(id, &iButtons) {     if(g_bForceShoot)     {         PrintToChat(id, "Force shoot %i", g_iCurrentCalls)                 iButtons &= ~IN_RELOAD         iButtons |= IN_ATTACK
        if(--g_iCurrentCalls <= 0)
        {
            g_bForceShoot = false
            g_bCheckNextShot = true
        }
        return Plugin_Changed     }     else if(g_bForceReload && GetGameTime() >= g_fDoReload)     {         PrintToChat(id, "Force reload")         g_bForceReload = false         iButtons &= ~IN_ATTACK         iButtons |= IN_RELOAD         return Plugin_Changed     }     return Plugin_Continue }
__________________


Dear admins. If somehow you managed to read this, plz fix.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Reply


Thread Tools
Display Modes

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 13:45.


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