View Single Post
Author Message
paulo_crash
AlliedModders Donor
Join Date: May 2016
Location: Brazil
Old 06-17-2021 , 16:34   Help with bind +USE for sparys
Reply With Quote #1

I have the sprays plugin, it has the sm_spray command to use the sprays, which I can bind with this command and such.

But you have the option of activating that when I activate the +USE bind, key "E" in CSGO in case he uses the direct spray.

The source code part of the plugin with this feature would be this:
PHP Code:
public Action:OnPlayerRunCmd(iClient, &buttons, &impulse)
{    
    if(!
g_use || !IsClientInGame(iClient))
        return 
Plugin_Continue;
    
    if (
buttons IN_USE)
    {
        if(!
IsPlayerAlive(iClient))
        {
            if(
g_showMsg)
            {
                
PrintToChat(iClient"\x01[ \x02ZK Servidores™ \x01] \x04Você precisa estar vivo para usar spray!");
            }
            return 
Plugin_Handled;
        }

        new 
iTime GetTime();
        new 
restante = (iTime g_iLastSprayed[iClient]);
    
        if(
restante g_time)
        {
            if(
g_showMsg)
            {
                
PrintToChat(iClient"\x01[ \x02ZK Servidores™ \x01] \x04Você precisa esperar \x02%i segundo(s) \x04para usar spray novamente!"g_time-restante);
            }
            return 
Plugin_Handled;
        }

        
decl Float:fClientEyePosition[3];
        
GetClientEyePosition(iClientfClientEyePosition);

        
decl Float:fClientEyeViewPoint[3];
        
GetPlayerEyeViewPoint(iClientfClientEyeViewPoint);

        
decl Float:fVector[3];
        
MakeVectorFromPoints(fClientEyeViewPointfClientEyePositionfVector);

        if(
GetVectorLength(fVector) > g_distance)
        {
            if(
g_showMsg)
            {
                
PrintToChat(iClient"\x01[ \x02ZK Servidores™ \x01] \x04Você está muito longe da parede para usar spray!");
            }
            return 
Plugin_Handled;
        }

        if(
g_sprayElegido[iClient] == 0)
        {
            new 
sprays[g_sprayCount], spraysCount;
            for (new 
i=1i<g_sprayCount; ++i)
                if(
HasFlag(iClientg_sprays[i][flag]))
                    
sprays[spraysCount++] = i;
            
            
TE_SetupBSPDecal(fClientEyeViewPointg_sprays[sprays[GetRandomInt(0spraysCount-1)]][index]);
        }
        else
        {
            if(
g_sprays[g_sprayElegido[iClient]][index] == 0)
            {
                if(
g_showMsg)
                {
                    
PrintToChat(iClient"\x01[ \x02ZK Servidores™ \x01] \x04Seu spray não funciona, digite \x02!sprays \x04e escolha outro!");
                }
                return 
Plugin_Handled;
            }
            
TE_SetupBSPDecal(fClientEyeViewPointg_sprays[g_sprayElegido[iClient]][index]);
            
            
// Save spray position and identifier
            
if(g_sprayIndexLast == g_maxMapSprays)
            
            
g_sprayIndexLast 0;
            
g_spraysMapAll[g_sprayIndexLast][vecPos] = fClientEyeViewPoint;
            
g_spraysMapAll[g_sprayIndexLast][index3] = g_sprays[g_sprayElegido[iClient]][index];
            
g_sprayIndexLast++;
            if(
g_sprayMapCount != g_maxMapSprays)
                
g_sprayMapCount++;
        }
        
TE_SendToAll();

        if(
g_showMsg)
        {
            
PrintToChat(iClient"\x01[ \x02ZK Servidores™ \x01] \x04Você usou seu spray.");
        }
        
        
//EmitAmbientSoundAny(SOUND_SPRAY_REL, fVector, iClient, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.4);
        //EmitSoundToClient(iClient, SOUND_SPRAY_REL, fVector, iClient, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.4);

        
g_iLastSprayed[iClient] = iTime;
        return 
Plugin_Handled;
    }

Problem I'm having, when I press the E key, +USE in CSGO it uses the spray but the player hangs while pressing the key and there is a loop of the messages that I configured to appear, this for all messages.

Would you like to know how I can fix it? Could anyone provide some light?

Below is a video showing the message loop and the crash it has when using the CSGO +USE key.

https://vimeo.com/564348706

When I compile the plugin it shows the following messages:
PHP Code:
//SourceMod Batch Compiler
// by the SourceMod Dev Team


//// valvesprays.sp
//
// D:\Google Drive\ZK ServidoresÖ\Servidores CSGO\Editar Plugins\addons\sourcemod\scripting\valvesprays.sp(48) : warning 241: Array-based enum structs will be removed in 1.11. See https://wiki.alliedmods.net/SourcePawn_Transitional_Syntax#Enum_Structs
// D:\Google Drive\ZK ServidoresÖ\Servidores CSGO\Editar Plugins\addons\sourcemod\scripting\valvesprays.sp(52) : warning 241: Array-based enum structs will be removed in 1.11. See https://wiki.alliedmods.net/SourcePawn_Transitional_Syntax#Enum_Structs
// D:\Google Drive\ZK ServidoresÖ\Servidores CSGO\Editar Plugins\addons\sourcemod\scripting\valvesprays.sp(180) : warning 234: symbol "GetMaxClients" is marked as deprecated: Use MaxClients variable instead.
//
//
// D:\Google Drive\ZK ServidoresÖ\Servidores CSGO\Editar Plugins\addons\sourcemod\scripting\valvesprays.sp(364) : warning 234: symbol "GetMaxClients" is marked as deprecated: Use MaxClients variable instead.
//
//
// D:\Google Drive\ZK ServidoresÖ\Servidores CSGO\Editar Plugins\addons\sourcemod\scripting\valvesprays.sp(519) : warning 209: function "OnPlayerRunCmd" should return a value
// Code size:            15768 bytes
// Data size:           187996 bytes
// Stack/heap size:      16384 bytes
// Total requirements:  220148 bytes
//
// 5 Warnings.
//
// Compilation Time: 0,25 sec
// ----------------------------------------

Press enter to exit ... 

Last edited by paulo_crash; 06-18-2021 at 20:40.
paulo_crash is offline