Raised This Month: $12 Target: $400
 3% 

reduce the distance where you hear bullets


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
fragnichtnach
AlliedModders Donor
Join Date: Oct 2008
Old 04-05-2018 , 14:58   reduce the distance where you hear bullets
Reply With Quote #1

I tested the following code:
Code:
public Action Hook_ShotgunShot(const char[] te_name, const int[] players, int numClients, float delay)
{
    if (!g_bHooked)
        return Plugin_Continue;
    int shooterIndex = TE_ReadNum("m_iPlayer") + 1;
    if(shooterIndex==0 || !IsClientConnected(shooterIndex) || !IsClientInGame(shooterIndex))
       return Plugin_Continue;
    
    int[] newClients = new int[MaxClients];
    int newTotal = 0;
    for (int i = 0; i < numClients; i++) 
    {
        int client = players[i];
        bool rebroadcast = true;
        if(shooterIndex==0 || !IsClientConnected(client) || !IsClientInGame(client))
            rebroadcast = true;        
        else
        {    
            float clientpos[3];
            GetClientAbsOrigin(client, clientpos);
            float shooterpos[3];
            GetClientAbsOrigin(shooterIndex, shooterpos);  
            float distance = (clientpos[0]-shooterpos[0])*(clientpos[0]-shooterpos[0])+(clientpos[1]-shooterpos[1])*(clientpos[1]-shooterpos[1]);
            if(distance<300*300)
                rebroadcast = true;
            else
                rebroadcast = false;
        }
        if (rebroadcast) 
        {
            // This Client should be able to hear it.
            newClients[newTotal] = client;
            newTotal++;
        }
    }
    float vTemp[3];
    TE_Start("Shotgun Shot");
    TE_ReadVector("m_vecOrigin", vTemp);
    TE_WriteVector("m_vecOrigin", vTemp);
    TE_WriteFloat("m_vecAngles[0]", TE_ReadFloat("m_vecAngles[0]"));
    TE_WriteFloat("m_vecAngles[1]", TE_ReadFloat("m_vecAngles[1]"));
    //TE_WriteNum("m_iWeaponID", TE_ReadNum("m_iWeaponID"));
    TE_WriteNum("m_weapon", TE_ReadNum("m_weapon"));
    TE_WriteNum("m_iMode", TE_ReadNum("m_iMode"));
    TE_WriteNum("m_iSeed", TE_ReadNum("m_iSeed"));
    TE_WriteNum("m_iPlayer", TE_ReadNum("m_iPlayer"));
    TE_WriteFloat("m_fInaccuracy", TE_ReadFloat("m_fInaccuracy"));
    TE_WriteFloat("m_fSpread", TE_ReadFloat("m_fSpread"));
    TE_Send(newClients, newTotal, delay);

    return Plugin_Stop;
}
It was working but I got this error messages:

Quote:
L 04/05/2018 - 19:17:25: [SM] [148] Line 331, wase_weapon_sounds.sp::Hook_ShotgunShot
L 04/05/2018 - 19:17:25: [SM] [150] TE_Send
L 04/05/2018 - 19:17:25: [SM] [151] Line 331, wase_weapon_sounds.sp::Hook_ShotgunShot
L 04/05/2018 - 19:17:25: [SM] [153] TE_Send
L 04/05/2018 - 19:17:25: [SM] [154] Line 331, wase_weapon_sounds.sp::Hook_ShotgunShot
L 04/05/2018 - 19:17:25: [SM] [156] TE_Send
L 04/05/2018 - 19:17:25: [SM] [157] Line 331, wase_weapon_sounds.sp::Hook_ShotgunShot
L 04/05/2018 - 19:17:25: [SM] Exception reported: Not enough space on the stack
Additional (I think it is related) it was supersizing the server sv/var?

Last edited by fragnichtnach; 04-05-2018 at 16:25. Reason: added some information
fragnichtnach is offline
fragnichtnach
AlliedModders Donor
Join Date: Oct 2008
Old 04-08-2018 , 23:55   Re: reduce the distance where you hear bullets
Reply With Quote #2

Any information I could provide that would make it easier for helping me?

The error line
Code:
L 04/05/2018 - 19:17:25: [SM] [154] Line 331, wase_weapon_sounds.sp::Hook_ShotgunShot
is spamed in my logs before it finally aborts with
Code:
L 04/05/2018 - 19:17:25: [SM] Exception reported: Not enough space on the stack
fragnichtnach is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 04-09-2018 , 01:38   Re: reduce the distance where you hear bullets
Reply With Quote #3

Infinite recursion, because of this you freeze the server momentarily while the sourcepawn plugin eats resources untill sourcemod shuts it down. That's why you see the variance, too.

You're creating a shotgun shot, which calls Hook_ShotgunShot and creates another shotgun shot. This happens indefinitely (or until you stack overflow).

Last edited by headline; 04-09-2018 at 01:48.
headline is offline
fragnichtnach
AlliedModders Donor
Join Date: Oct 2008
Old 04-10-2018 , 01:12   Re: reduce the distance where you hear bullets
Reply With Quote #4

Quote:
Originally Posted by Headline View Post
Infinite recursion, because of this you freeze the server momentarily while the sourcepawn plugin eats resources untill sourcemod shuts it down. That's why you see the variance, too.

You're creating a shotgun shot, which calls Hook_ShotgunShot and creates another shotgun shot. This happens indefinitely (or until you stack overflow).
Thanks man!

Is there a way to fix it? I don't understand why this one is working:

Code:
public Action:CSS_Hook_ShotgunShot(const String:te_name[], const Players[], numClients, Float:delay)
{
    if (!g_bHooked)
        return Plugin_Continue;

    // Check which clients need to be excluded.
    decl newClients[MaxClients], client, i;
    new newTotal = 0;

    for (i = 0; i < numClients; i++)
    {
        client = Players[i];
        
        if (!g_bStopSound[client])
        {
            newClients[newTotal++] = client;
        }
    }

    // No clients were excluded.
    if (newTotal == numClients)
        return Plugin_Continue;

    // All clients were excluded and there is no need to broadcast.
    else if (newTotal == 0)
        return Plugin_Stop;

        // Re-broadcast to clients that still need it.
    float vTemp[3];
    TE_Start("Shotgun Shot");
    TE_ReadVector("m_vecOrigin", vTemp);
    TE_WriteVector("m_vecOrigin", vTemp);
    TE_WriteFloat("m_vecAngles[0]", TE_ReadFloat("m_vecAngles[0]"));
    TE_WriteFloat("m_vecAngles[1]", TE_ReadFloat("m_vecAngles[1]"));
    //TE_WriteNum("m_iWeaponID", TE_ReadNum("m_iWeaponID"));
    TE_WriteNum("m_weapon", TE_ReadNum("m_weapon"));
    TE_WriteNum("m_iMode", TE_ReadNum("m_iMode"));
    TE_WriteNum("m_iSeed", TE_ReadNum("m_iSeed"));
    TE_WriteNum("m_iPlayer", TE_ReadNum("m_iPlayer"));
    TE_WriteFloat("m_fInaccuracy", TE_ReadFloat("m_fInaccuracy"));
    TE_WriteFloat("m_fSpread", TE_ReadFloat("m_fSpread"));
    TE_Send(newClients, newTotal, delay);

    return Plugin_Stop;
}

Last edited by fragnichtnach; 04-10-2018 at 01:14. Reason: just fixed some spacings
fragnichtnach is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 04-10-2018 , 12:54   Re: reduce the distance where you hear bullets
Reply With Quote #5

Quote:
Originally Posted by fragnichtnach View Post
Thanks man!

Is there a way to fix it? I don't understand why this one is working:

Code:
public Action:CSS_Hook_ShotgunShot(const String:te_name[], const Players[], numClients, Float:delay)
{
    if (!g_bHooked)
        return Plugin_Continue;

    // Check which clients need to be excluded.
    decl newClients[MaxClients], client, i;
    new newTotal = 0;

    for (i = 0; i < numClients; i++)
    {
        client = Players[i];
        
        if (!g_bStopSound[client])
        {
            newClients[newTotal++] = client;
        }
    }

    // No clients were excluded.
    if (newTotal == numClients)
        return Plugin_Continue;

    // All clients were excluded and there is no need to broadcast.
    else if (newTotal == 0)
        return Plugin_Stop;

        // Re-broadcast to clients that still need it.
    float vTemp[3];
    TE_Start("Shotgun Shot");
    TE_ReadVector("m_vecOrigin", vTemp);
    TE_WriteVector("m_vecOrigin", vTemp);
    TE_WriteFloat("m_vecAngles[0]", TE_ReadFloat("m_vecAngles[0]"));
    TE_WriteFloat("m_vecAngles[1]", TE_ReadFloat("m_vecAngles[1]"));
    //TE_WriteNum("m_iWeaponID", TE_ReadNum("m_iWeaponID"));
    TE_WriteNum("m_weapon", TE_ReadNum("m_weapon"));
    TE_WriteNum("m_iMode", TE_ReadNum("m_iMode"));
    TE_WriteNum("m_iSeed", TE_ReadNum("m_iSeed"));
    TE_WriteNum("m_iPlayer", TE_ReadNum("m_iPlayer"));
    TE_WriteFloat("m_fInaccuracy", TE_ReadFloat("m_fInaccuracy"));
    TE_WriteFloat("m_fSpread", TE_ReadFloat("m_fSpread"));
    TE_Send(newClients, newTotal, delay);

    return Plugin_Stop;
}
I suspect it's the "if (!g_bStopSound[client])" check that's preventing the recursion, but I can't be sure without the context of the full code. When are you setting g_bStopSound for a client to true?
headline is offline
fragnichtnach
AlliedModders Donor
Join Date: Oct 2008
Old 04-10-2018 , 17:53   Re: reduce the distance where you hear bullets
Reply With Quote #6

I've found this code inside this plugin:
https://forums.alliedmods.net/showthread.php?p=1694338

The
g_bStopSound[client]
is just toggled in a clients menu.

Last edited by fragnichtnach; 04-10-2018 at 17:55.
fragnichtnach 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 18:44.


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