AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-19) (https://forums.alliedmods.net/showthread.php?t=237045)

ThatOneGuy 01-31-2017 21:43

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
Quote:

Originally Posted by DeagLe.Studio (Post 2490902)
Hey, it seems that the EmitSoundToClientAny is not working, but EmitAmbientSoundAny seems to work just fine.

I'm getting an error like this when I use EmitSoundToClientAny even tho the sounds is precached and I tried to precache the sound just before playing it too but it still doesnt work
Code:

SV_StartSound: *sound.mp3 not precached (7229)
PS: The game is CSGO

Check to make sure it is being downloaded properly. Delete it from your csgo sounds folder and see if you re-download it. If not, make sure the plugin is adding it to the downloads table and that it is on your fastDL and everything is named properly.

TheDS1337 02-01-2017 04:32

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
Quote:

Originally Posted by ThatOneGuy (Post 2491676)
Check to make sure it is being downloaded properly. Delete it from your csgo sounds folder and see if you re-download it. If not, make sure the plugin is adding it to the downloads table and that it is on your fastDL and everything is named properly.

Its added in the sounds folder, and no I dont have a server atm so I'm testing in a listen server.

Peace-Maker 02-01-2017 05:24

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
Did you use PrecacheSoundAny in OnMapStart?

TheDS1337 02-01-2017 05:37

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
Quote:

Originally Posted by Peace-Maker (Post 2491740)
Did you use PrecacheSoundAny in OnMapStart?

Yes I did :) I tried also to use it just before starting the song (saw this in Zombie Reloaded's sourcecode) but it didnt work aswell.

thomasjosif 02-02-2017 21:21

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
Quote:

Originally Posted by DeagLe.Studio (Post 2491743)
Yes I did :) I tried also to use it just before starting the song (saw this in Zombie Reloaded's sourcecode) but it didnt work aswell.

Would be better if you posted the code :)

TheDS1337 02-04-2017 10:03

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
Quote:

Originally Posted by thomasjosif (Post 2492287)
Would be better if you posted the code :)

Well here it is.. the code is not fully functional and not completed but you should get me.
Code:

#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#include <emitsoundany>

#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo =
{
        name = "[ZR] Jetpack",
        author = "",
        description = "",
        version = "",
        url = ""
};

#define JETPACK_ENERGY 150                        // Calculated like: secs * 20.0
#define JETPACK_SPEED 350.0
#define JETPACK_ROCKET_DELAY 15.0       
#define JETPACK_ROCKET_SPEED 4000.0
#define JETPACK_ROCKET_MODEL "models/props/cs_italy/bananna.mdl"

bool g_HasJetpack[MAXPLAYERS + 1];
int g_JetpackEnergy[MAXPLAYERS + 1];
float g_NextRocketTime[MAXPLAYERS + 1];

float g_MaxSpeed[MAXPLAYERS + 1];

public void OnPluginStart()
{       
}

public void OnClientPutInServer(int client)
{
        g_HasJetpack[1] = true;
        g_JetpackEnergy[1] = JETPACK_ENERGY;
        g_NextRocketTime[1] = GetGameTime() * GetTickInterval();
       
        SDKHook(client, SDKHook_PreThink, OnPlayerPreThink);
        SDKHook(client, SDKHook_PreThinkPost, OnPlayerPreThink_Post);
}

public void OnMapStart()
{
        AddFileToDownloadsTable("sound/zombie_revolution/jetpack_fly.mp3");
        AddFileToDownloadsTable("sound/zombie_revolution/jetpack_noenergy.mp3");
        AddFileToDownloadsTable("sound/zombie_revolution/jetpack_firerocket.mp3");
       
        PrecacheSoundAny("zombie_revolution/jetpack_fly.mp3");
        PrecacheSoundAny("zombie_revolution/jetpack_noenergy.mp3");
        PrecacheSoundAny("zombie_revolution/jetpack_firerocket.mp3");
       
        PrecacheModel(JETPACK_ROCKET_MODEL);
}

public void OnPlayerPreThink(int client)
{
        if( !IsPlayerAlive(client) || !g_HasJetpack[client] )
        {       
                return;
        }
       
        static float origin[3], eyeAngles[3], velocity[3];
       
        int flags = GetEntityFlags(client);
        int buttons = GetClientButtons(client);
        int entity = 0;
        float gameTime = GetGameTime() * GetTickInterval();       
       
        if( g_JetpackEnergy[client] < JETPACK_ENERGY && ((flags & FL_ONGROUND) || (flags & FL_INWATER)) )
        {       
                g_JetpackEnergy[client]++;
        }               
        else if( g_JetpackEnergy[client] > 0 && (buttons & IN_JUMP) && (buttons & IN_DUCK) )
        {                               
                GetClientAbsOrigin(client, origin);
                GetClientEyeAngles(client, eyeAngles);
               
                eyeAngles[0] = -40.0;
               
                GetAngleVectors(eyeAngles, velocity, NULL_VECTOR, NULL_VECTOR);
                ScaleVector(velocity, JETPACK_SPEED);
               
                velocity[2] *= 0.8;
               
                TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, velocity);
               
                g_JetpackEnergy[client]--;               
               
                if( GetRandomInt(0, 2) == 0 )
                {
                        DataPack data = new DataPack();
                       
                        eyeAngles[0] = 110.0;
                        origin[2] += 25.0;
                       
                        PrecacheSoundAny("zombie_revolution/jetpack_fly.mp3");
                        PrecacheSoundAny("zombie_revolution/jetpack_noenergy.mp3");
       
//                        EmitAmbientSoundAny(g_JetpackEnergy[client] > JETPACK_ENERGY / 4 ? "zombie_revolution/jetpack_fly.mp3" : "zombie_revolution/jetpack_noenergy.mp3", NULL_VECTOR, client);
                        EmitSoundToClientAny(client, g_JetpackEnergy[client] > JETPACK_ENERGY / 4 ? "zombie_revolution/jetpack_fly.mp3" : "zombie_revolution/jetpack_noenergy.mp3", SOUND_FROM_PLAYER, SNDCHAN_ITEM, SNDLEVEL_NORMAL, SND_NOFLAGS, SNDVOL_NORMAL, SNDPITCH_HIGH);
                       
                        static char parentname[32], targetname[32];                       
                        Format(parentname, sizeof(parentname), "jetpack_owner_%d", client);
                       
                        DispatchKeyValue(client, "targetname", targetname);                       

                        entity = CreateEntityByName("env_steam");

                        if( IsValidEdict(entity) )
                        {
                                Format(targetname, sizeof(targetname), "jetpack_flame_%d", client);
                               
                                DispatchKeyValue(entity, "parentname", parentname);
                                DispatchKeyValue(entity, "targetname", targetname);                               
                                DispatchKeyValue(entity, "SpawnFlags", "1");
                                DispatchKeyValue(entity, "Type", "0");
                                DispatchKeyValue(entity, "InitialState", "1");
                                DispatchKeyValue(entity, "Spreadspeed", "10");
                                DispatchKeyValue(entity, "Speed", "400");
                                DispatchKeyValue(entity, "Startsize", "20");
                                DispatchKeyValue(entity, "EndSize", "600");
                                DispatchKeyValue(entity, "Rate", "30");
                                DispatchKeyValue(entity, "JetLength", "200");
                                DispatchKeyValue(entity, "RenderColor", "255 100 30");
                                DispatchKeyValue(entity, "RenderAmt", "180");                               
                                DispatchSpawn(entity);
                               
                                TeleportEntity(entity, origin, eyeAngles, NULL_VECTOR);
                               
                                SetVariantString(parentname);

                                AcceptEntityInput(entity, "SetParent", entity, entity, 0);
                                AcceptEntityInput(entity, "TurnOn");
                               
                                data.WriteCell(entity);
                        }
                       
                        entity = CreateEntityByName("env_steam");
                       
                        if( IsValidEdict(entity) )
                        {
                                Format(targetname, sizeof(targetname), "jetpack_flame02_%d", client);
                               
                                DispatchKeyValue(entity, "parentname", parentname);
                                DispatchKeyValue(entity, "targetname", targetname);                               
                                DispatchKeyValue(entity, "SpawnFlags", "1");
                                DispatchKeyValue(entity, "Type", "1");
                                DispatchKeyValue(entity, "InitialState", "1");
                                DispatchKeyValue(entity, "Spreadspeed", "10");
                                DispatchKeyValue(entity, "Speed", "400");
                                DispatchKeyValue(entity, "Startsize", "20");
                                DispatchKeyValue(entity, "EndSize", "600");
                                DispatchKeyValue(entity, "Rate", "10");
                                DispatchKeyValue(entity, "JetLength", "200");
                                DispatchSpawn(entity);

                                TeleportEntity(entity, origin, eyeAngles, NULL_VECTOR);

                                SetVariantString(parentname);

                                AcceptEntityInput(entity, "SetParent", entity, entity, 0);
                                AcceptEntityInput(entity, "TurnOn");
                               
                                data.WriteCell(entity);
                        }
                       
                        CreateTimer(1.0, Timer_RemoveFlame, data);
                }
        }       
       
        if( g_NextRocketTime[client] <= gameTime && (buttons & IN_ATTACK2) )
        {
                entity = CreateEntityByName("hegrenade_projectile");
               
                if( IsValidEdict(entity) )
                {
                        GetClientAbsOrigin(client, origin);
                        GetClientEyeAngles(client, eyeAngles);                       
               
                        GetAngleVectors(eyeAngles, velocity, NULL_VECTOR, NULL_VECTOR);
                        ScaleVector(velocity, JETPACK_ROCKET_SPEED);                                       
                       
                        SetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity", client);                       
                        SetEntProp(entity, Prop_Send, "m_nSolidType", 2);
                        SetEntProp(entity, Prop_Data, "m_takedamage", 2);
                       
                        SetEntityMoveType(entity, MOVETYPE_FLY);
                        SetEntityModel(entity, JETPACK_ROCKET_MODEL);
                       
                        DispatchSpawn(entity);
                       
                        TeleportEntity(entity, origin, NULL_VECTOR, velocity);
                }
               
                g_NextRocketTime[client] = gameTime + JETPACK_ROCKET_DELAY;
        }
}

public void OnPlayerPreThink_Post(int client)
{
        g_MaxSpeed[client] = GetEntPropFloat(client, Prop_Data, "m_flMaxspeed");
}

public Action Timer_RemoveFlame(Handle timer, DataPack data)
{
        static char classname[32];
       
        data.Reset();
       
        int flameEntity = data.ReadCell();
       
        if( IsValidEdict(flameEntity) )
        {
                GetEdictClassname(flameEntity, classname, sizeof(classname));
               
                if( StrEqual(classname, "env_steam") )
                {
                        AcceptEntityInput(flameEntity, "TurnOff");
                        AcceptEntityInput(flameEntity, "Kill");
                }
        }
       
        flameEntity = data.ReadCell();
       
        if( IsValidEdict(flameEntity) )
        {
                GetEdictClassname(flameEntity, classname, sizeof(classname));
               
                if( StrEqual(classname, "env_steam") )
                {
                        AcceptEntityInput(flameEntity, "TurnOff");
                        AcceptEntityInput(flameEntity, "Kill");
                }
        }
       
        delete data;       
}


Kailo 02-22-2017 13:08

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
1 Attachment(s)
emitsoundany.inc with updated syntax.

TheDS1337 03-02-2017 17:11

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
Quote:

Originally Posted by Kailo (Post 2497564)
emitsoundany.inc with updated syntax.

Did you test this?

Kailo 03-03-2017 09:19

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
Quote:

Originally Posted by DeagLe.Studio (Post 2500245)
Did you test this?

Yes, i tested.

TheDS1337 03-03-2017 10:10

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
Quote:

Originally Posted by Kailo (Post 2500385)
Yes, i tested.

I tested with EmitSoundToClientAny and it didnt work :/


All times are GMT -4. The time now is 02:30.

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