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

I need help fixing a plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
robotortoise
Senior Member
Join Date: Nov 2013
Old 09-29-2014 , 01:26   I need help fixing a plugin
Reply With Quote #1

So this plugin was made a while back, that would play a .wav from the medic when an nearby undisguised spy called for a medic.

The only problem is the "new g_Radius = 10;" doesn't work.
No matter what I set it to, it always plays the sound clip when I'm a spy calling for medic, whether I'm halfway across the map or right next to a medic.

I'm not a coder myself, so forgive me for asking this, it's just irritating when I can't get it to work...

Does anyone have any ideas?
__________________
-Robotortoise [Palutena's Bro]

If you ever need help with Wii/Gamecube/DS sounds/music/ect., I'm your man!

Contact me via Steam

I don't bite.


How to loop and compress .wav files

Me and my friends' server
robotortoise is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 09-29-2014 , 04:11   Re: I need help fixing a plugin
Reply With Quote #2

The code is actually broken, oddly enough -- they stored the same client's position in both pos_Spy and pos_Med, meaning the vector distance is always 0.

I think you just need to replace
Code:
GetClientEyePosition(client, pos_Spy);
GetClientEyePosition(client, pos_Med);
with
Code:
GetClientEyePosition(client, pos_Spy);
GetClientEyePosition(i, pos_Med);
nosoop is offline
robotortoise
Senior Member
Join Date: Nov 2013
Old 09-29-2014 , 15:36   Re: I need help fixing a plugin
Reply With Quote #3

Quote:
Originally Posted by nosoop View Post
The code is actually broken, oddly enough -- they stored the same client's position in both pos_Spy and pos_Med, meaning the vector distance is always 0.

I think you just need to replace
Code:
GetClientEyePosition(client, pos_Spy);
GetClientEyePosition(client, pos_Med);
with
Code:
GetClientEyePosition(client, pos_Spy);
GetClientEyePosition(i, pos_Med);
Hm. So I tried this code, and it didn't work. Same thing, the medic never says anything, no matter how close or far away I am.
Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <tf2_stocks>

#define SEDUCEME_LENGTH 1.0 // Length of the Seduce Me soundbite, not sure how long it is
#define MAX_FILE_LEN 100 // File path restriction
#define COOLDOWN 15.0 // Cooldown period between between phrases, so to avoid spam

new Handle:CooldownTimers[MAXPLAYERS+1] = INVALID_HANDLE;
new bool:isMedic[MAXPLAYERS+1] = false;
new g_Radius = 20; // Radius that is adequate for the 'later' response
new String:soundPath[] = "vo/taunts/medic/medic_taunt_int_15.wav"; // I put it in the \download\sound\ folder on the server

public OnMapStart()
{
    decl String:filename[MAX_FILE_LEN];
    
    // Precaching the sound
    PrecacheSound(soundPath, true);
    
    // Adding it to the download table
    Format(filename, MAX_FILE_LEN, "sound/%s", soundPath);
    AddFileToDownloadsTable(filename);
}

public OnPluginStart()
{
    AddCommandListener(MedicCall, "voicemenu"); // Listening to MEDIC! command
    HookEvent("player_changeclass", Event_ChangeClass);
}

public Action:MedicCall(client, String:command[], args)
{
    decl String:buffer[2];
    
    GetCmdArg(1, buffer, sizeof(buffer));
    if (StringToInt(buffer) == 0)
    {
        GetCmdArg(2, buffer, sizeof(buffer));
        if (StringToInt(buffer) == 0)
            CheckConditions(client); // Checking other conditions when called for Medic
    }

    return Plugin_Continue;
}

public CheckConditions(client)
{    
    if ( (TF2_GetPlayerClass(client) == TFClass_Spy) && (!TF2_IsPlayerInCondition(client, TFCond_Disguised)) ) // Spy called for Medic and is not currently disguised
    {
        new Float:pos_Spy[3], Float:pos_Med[3];
        for (new i = 1; i < MAXPLAYERS; i++) // Scan for any Medics, friendly or not
        {
            if (isMedic[i] && IsPlayerAlive(i) && IsPlayerAlive(client) && (CooldownTimers[i] == INVALID_HANDLE) )
            {
                GetClientEyePosition(client, pos_Spy);
                GetClientEyePosition(i, pos_Med);
                
                if (GetVectorDistance(pos_Spy, pos_Med, false) <= g_Radius) // Medic is in the radius, play the sound
                {
                    CreateTimer(SEDUCEME_LENGTH, Play_Later, i);
                    CooldownTimers[i] = CreateTimer(SEDUCEME_LENGTH + COOLDOWN, RefreshCooldown, i); // Creating a cooldown timer to prevent spam
                    break;
                }
            }
        }
    }
}

public Event_ChangeClass(Handle:event, const String:name[], bool:dontBroadcast)
{
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    new class = GetEventInt(event, "class");
    
    if (class == 5) // Player changed to Medic
    {
        isMedic[client] = true;
    }
    else // Player not a medic anymore
    {
        if (isMedic[client])
            isMedic[client] = false;
    }
}

public Action:Play_Later(Handle:timer, any:client)
{
    if (IsPlayerAlive(client) && isMedic[client])
    {
        new Float:pos[3], Float:ang[3];
        GetClientEyePosition(client, pos);
        GetClientEyeAngles(client, ang);
        EmitSoundToAll(soundPath, client, SNDCHAN_VOICE, SNDLEVEL_NORMAL, SND_NOFLAGS, SNDVOL_NORMAL, SNDPITCH_NORMAL, -1, pos, ang, true, 0.0);
    }
}

public Action:RefreshCooldown(Handle:timer, any:i)
{
    CooldownTimers[i] = INVALID_HANDLE;
}
__________________
-Robotortoise [Palutena's Bro]

If you ever need help with Wii/Gamecube/DS sounds/music/ect., I'm your man!

Contact me via Steam

I don't bite.


How to loop and compress .wav files

Me and my friends' server
robotortoise is offline
floube
SourceMod Donor
Join Date: Jan 2013
Location: Austria
Old 09-29-2014 , 15:40   Re: I need help fixing a plugin
Reply With Quote #4

You may try a higher value for the radius, like 400, since 20 is pretty much standing inside each other.
__________________
floube is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 09-29-2014 , 16:11   Re: I need help fixing a plugin
Reply With Quote #5

Yep, 20 is less then player width - look here

Last edited by KissLick; 09-29-2014 at 16:12.
KissLick is offline
robotortoise
Senior Member
Join Date: Nov 2013
Old 09-29-2014 , 20:34   Re: I need help fixing a plugin
Reply With Quote #6

Quote:
Originally Posted by floube View Post
You may try a higher value for the radius, like 400, since 20 is pretty much standing inside each other.
That...would explain a lot, actually.

Lemme try that.
__________________
-Robotortoise [Palutena's Bro]

If you ever need help with Wii/Gamecube/DS sounds/music/ect., I'm your man!

Contact me via Steam

I don't bite.


How to loop and compress .wav files

Me and my friends' server
robotortoise 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 14:48.


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