AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [CS:GO] Force shoot & reload (https://forums.alliedmods.net/showthread.php?t=329063)

OciXCrom 12-06-2020 13:58

[CS:GO] Force shoot & reload
 
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?

StrikeR14 12-06-2020 14:46

Re: [CS:GO] Force shoot & reload
 
Use OnPlayerRunCmd buttons.

buttons =| IN_ATTACK
buttons =| IN_RELOAD

return Plugin_Changed when you apply button changes.

OciXCrom 12-12-2020 15:46

Re: [CS:GO] Force shoot & reload
 
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?

kratoss1812 12-12-2020 20:15

Re: [CS:GO] Force shoot & reload
 
For the animation you can try to crate & fire this event
https://wiki.alliedmods.net/Counter-...#weapon_reload

OciXCrom 12-13-2020 15:59

Re: [CS:GO] Force shoot & reload
 
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?

eyal282 12-16-2020 07:00

Re: [CS:GO] Force shoot & reload
 
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.

Marttt 12-16-2020 13:18

Re: [CS:GO] Force shoot & reload
 
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

OciXCrom 12-17-2020 08:28

Re: [CS:GO] Force shoot & reload
 
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)     } }

eyal282 12-17-2020 09:04

Re: [CS:GO] Force shoot & reload
 
Quote:

Originally Posted by OciXCrom (Post 2729047)
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?

OciXCrom 12-17-2020 13:49

Re: [CS:GO] Force shoot & reload
 
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 }


All times are GMT -4. The time now is 03:48.

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