AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   Prop Spawn help (https://forums.alliedmods.net/showthread.php?t=236431)

tedoficialsteam 03-04-2014 20:42

Prop Spawn help
 
Hi, i'm trying to make a plugin that spawns chairs at my aim. everything works fine, but the deal is to remove only one with my aim, not all the chairs. can someone help me?

Code:

#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <sdktools_sound>
#include <smlib>
#include <sdkhooks>


#define PLUGIN_VERSION "v1.2"
#define MAX_FILE_LEN 80

new Handle:g_CvarSoundName = INVALID_HANDLE;
new Handle:cvarIngameMenu = INVALID_HANDLE;

new String:g_soundName[MAX_FILE_LEN];

public Plugin:myinfo =
{
        name = "Cadeira",
        author = "Dk--",
        description = "Spawn Props",
        version = PLUGIN_VERSION,
};

public OnPluginStart()
{
                g_CvarSoundName = CreateConVar("sm_join_sound", "music/cadeira/cadeira.mp3", "The sound to play");
                cvarIngameMenu = CreateConVar("cadeira_ingamemenu", "1", "Enabled menu", FCVAR_NONE, true, 0.0, true, 1.0);
        RegAdminCmd("sm_cadeiras", Cadeira, ADMFLAG_GENERIC);
                LoadTranslations("common.phrases");
}

public OnConfigsExecuted()
{
    GetConVarString(g_CvarSoundName, g_soundName, sizeof(g_soundName)); //Gets the cvar value from g_CvarSoundName in OnPluginStart and puts it inside the string g_soundName
    decl String:buffer[MAX_FILE_LEN]; //Creates a string called buffer
    PrecacheSound(g_soundName, true); //Precaches the sound
    Format(buffer, sizeof(buffer), "sound/%s", g_soundName); //Formats the buffer string with the directory to the sound file
    AddFileToDownloadsTable(buffer); //Adds buffer (The sound file) to the downloads table
}

public Action:Cadeira(client,args)
{
                if(!GetConVarBool(cvarIngameMenu))
                return;
                {
                if(client == 0)
                {
                        PrintToServer("%t","Command is in-game only");
                        return;
                }
                        DID2(client);
                PrintToConsole(client, "Menu de cadeiras esta aberto");
                }


public bool:RayDontHitSelf(entity, contentsMask, any:data)
{
        return (entity != data);
}

public OnMapStart()
{
        PrecacheModel("models/props/gg_tibet/modernchair.mdl");
        PrecacheSound("music/cadeira/cadeira.mp3");
}
 


stock FindEntityByClassname2(startEnt, const String:classname[])
{

        while (startEnt > -1 && !IsValidEntity(startEnt)) startEnt--;
       
        return FindEntityByClassname(startEnt, classname);
       
}

public Action:DID(clientId)
{
        new Handle:menu = CreateMenu(DIDMenuHandler);
        SetMenuTitle(menu, "Começar ou Pausar musica");

        AddMenuItem(menu, "option1", "Play");
        AddMenuItem(menu, "option2", "Stop");
        SetMenuExitButton(menu, true);
        DisplayMenu(menu, clientId, 15);
       
        return Plugin_Handled;
}

public DIDMenuHandler(Handle:menu, MenuAction:action, client, itemNum)
{
        if ( action == MenuAction_Select )
        {
                new String:info[32];
               
                GetMenuItem(menu, itemNum, info, sizeof(info));

                if ( strcmp(info,"option1") == 0 )
                {
                        {
                                DID(client);
                                EmitSoundToAll(g_soundName, _, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, SNDVOL_NORMAL, SNDPITCH_NORMAL);
                                PrintToChatAll("Iniciando Musica");
                        }
                       
                }
               
                else if ( strcmp(info,"option2") == 0 )
                {
                        {
                                DID(client);
                                for (new i = 1; i < GetMaxClients(); i++)
                                {
                                        StopSoundPerm(i, g_soundName);
                                        AddNormalSoundHook(SoundHook);
                                }
                                PrintToChatAll("Pausando Musica");
                        }
                       
                }
        }
}

public Action:SoundHook(clients[64], &numClients, String:sound[PLATFORM_MAX_PATH], &Ent, &channel, &Float:volume, &level, &pitch, &flags)
{
    if (StrEqual(sound, "g_soundName", false)) return Plugin_Stop;
    return Plugin_Continue;




stock StopSoundPerm( client, String:sound[ ] )
{
    StopSound( client, SNDCHAN_AUTO, sound );
    StopSound( client, SNDCHAN_WEAPON, sound );
    StopSound( client, SNDCHAN_VOICE, sound );
    StopSound( client, SNDCHAN_ITEM, sound );
    StopSound( client, SNDCHAN_BODY, sound);
    StopSound( client, SNDCHAN_STREAM, sound );
    StopSound( client, SNDCHAN_VOICE_BASE, sound );
    StopSound( client, SNDCHAN_USER_BASE, sound );


public Action:DID2(clientId)
{
        new Handle:menu2 = CreateMenu(DID2MenuHandler);
        SetMenuTitle(menu2, "Crie sua cadeira");

        AddMenuItem(menu2, "option1", "Criar cadeira");
        AddMenuItem(menu2, "option3", "Deletar cadeiras");
        AddMenuItem(menu2, "option2", "Menu de Musica");
        SetMenuExitButton(menu2, true);
        DisplayMenu(menu2, clientId, 15);
       
        return Plugin_Handled;
}

public DID2MenuHandler(Handle:menu2, MenuAction:action, client, itemNum)
{
        if ( action == MenuAction_Select )
        {
                new String:info[32];
               
                GetMenuItem(menu2, itemNum, info, sizeof(info));

                if ( strcmp(info,"option1") == 0 )
                {
                                DID2(client);
                                decl Float:start[3], Float:angle[3], Float:end[3], Float:normal[3], Float:fOrigin[3];
                                GetClientEyePosition(client, start);
                                GetClientEyeAngles(client, angle);
               
                                TR_TraceRayFilter(start, angle, MASK_SOLID, RayType_Infinite, RayDontHitSelf, client);
                                if (TR_DidHit(INVALID_HANDLE))
                                {
                                        TR_GetEndPosition(end, INVALID_HANDLE);
                                        TR_GetPlaneNormal(INVALID_HANDLE, normal);
                                        GetVectorAngles(normal, normal);
                                        normal[0] += 90.0;
                       
                                        new ent = CreateEntityByName("prop_physics_override");
                                       
                                        if(ent == -1)
                                        return Plugin_Handled;
                                       
                                        SetEntityModel(ent, "models/props/gg_tibet/modernchair.mdl");
                                        DispatchKeyValue(ent, "StartDisabled", "false");
                                        DispatchKeyValue(ent, "physdamagescale", "50.0");
                                        DispatchKeyValue(ent, "spawnflags", "8");
                                        DispatchKeyValue(ent, "Solid", "6");
                                        DispatchKeyValue(ent, "classname", "models/props/gg_tibet/modernchair.mdl");
                                        DispatchSpawn(ent);
                                        SetEntPropEnt(ent, Prop_Send, "m_hOwnerEntity", client);
                                        SetEntProp(ent, Prop_Data, "m_iHealth", 50);
                                       
                                        if ( DispatchSpawn(ent) )
                                        {
                                                SetEntPropEnt(ent, Prop_Send, "m_hEffectEntity", client);
                                                TeleportEntity(ent, end, normal, NULL_VECTOR); 
                                                SetEntProp(ent, Prop_Send, "m_usSolidFlags",  152);
                                                SetEntProp(ent, Prop_Send, "m_CollisionGroup", 8);
                                                AcceptEntityInput(ent, "DisableMotion");
                                               
                                                return ent;
                                        }
       
                                        return -1;

                                }

                                PrintToChat(client, "\x04[\x04Brazuka Gamers\x01] \x01Voce criou uma cadeira ^^"); // english
                }
               
                else if ( strcmp(info,"option3") == 0 )
                {
                        //For delete only my prop!!
                       
                        //This delete all created
                        new index = -1;
                        while ((index = FindEntityByClassname2(index, "prop_physics_override")) != -1)
                        AcceptEntityInput(index, "Kill");
                        return Plugin_Handled;
                }

               
                else if ( strcmp(info,"option2") == 0 )
                {
                        DID(client);
                }
        }
}


MasterOfTheXP 03-04-2014 21:30

Re: Prop Spawn help
 
You'll have to keep track of the props that you're spawning, either using a global array, or by assigning names onto the props (such as "sm_chair").

P.S. Use the Scripting forum next time for posts like these.

tedoficialsteam 03-04-2014 22:38

Re: Prop Spawn help
 
I tried this, but not find the right prop!

Code:

else if ( strcmp(info,"option3") == 0 )
                {
                        new prop = GetClientAimTarget(client, false);
                        new String:EntName[256];
                        Entity_GetName(prop, EntName, sizeof(EntName));
                        new validProp = StrContains(EntName, "prop_physics_override");
                       
                        if(validProp > -1)
                        {
                                //Remove the prop
                                /* Find the client index in the string */
                                new String:tempInd[3];
                                tempInd[0] = EntName[15];
                                tempInd[1] = EntName[16];
                                tempInd[2] = EntName[17];
                               
                               
                                /* We should now have the numbers somewhere, let's find out where */
                                ReplaceString(tempInd, sizeof(tempInd), "_", "");
                                AcceptEntityInput(prop, "kill");
                        }
                        else
                        {
                                PrintToChat(client, "Youn cannot delete this prop!");
                        }


tedoficialsteam 03-04-2014 23:12

Re: Prop Spawn help
 
Solved problem, thanks to MasterOfTheXP.

Please close this thread!


All times are GMT -4. The time now is 11:58.

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