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

Solved Need Help with a plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
born for gaming
Member
Join Date: Aug 2019
Location: Pakistan
Old 08-02-2021 , 11:30   Need Help with a plugin
Reply With Quote #1

Hi,

I am making my first plugin ( I am noob )

I am creating a plugin of special round. Means after 4 round one special round come randomly.

I created this funrounds_by_slayer.sp and this is working perfectly in CSGO but problem in this sp file is that i need to enter rounds interval of every special round.
heres the convars :
PHP Code:
    sRoundIntervalBhop CreateConVar("round_bhop_interval""6""Set number of rounds between Only BHOP round"FCVAR_NOTIFYtrue0.0);
    
sRoundIntervalBhopNoscope CreateConVar("round_noscope_interval""5""Set number of rounds between an BHOP+Noscope round"FCVAR_NOTIFYtrue0.0);
    
sRoundIntervalBhopknife CreateConVar("round_knife_interval""4""Set number of rounds between an Knife+Bhop round"FCVAR_NOTIFYtrue0.0);
    
sRoundIntervalBhopZeus CreateConVar("round_zeus_interval""3""Set number of rounds between an Zeus+Bhop round"FCVAR_NOTIFYtrue0.0);
    
sRoundIntervalDeagleHeadshot CreateConVar("round_deagle_interval""2""Set number of rounds between an Deagle+Headshot round"FCVAR_NOTIFYtrue0.0); 
but i want special rounds come randomly after every 4 rounds like this
PHP Code:
sRoundInterval CreateConVar("round_interval""4""Set number of rounds between a Fun/Special round"FCVAR_NOTIFYtrue0.0); 
Means plugin choose any special round from :
1. Zeus+bhop round
2. Noscope+bhop round
3. Deagle+Headshot Round
4. Only Bhop round
5. Knife+bhop round


i try to make it myself but not works :



heres the sp file : funrounds_by_slayer1.sp

Please Help Me!

Thanks in Advance

Last edited by born for gaming; 08-27-2021 at 00:40.
born for gaming is offline
born for gaming
Member
Join Date: Aug 2019
Location: Pakistan
Old 08-27-2021 , 00:45   Re: Need Help with a plugin
Reply With Quote #2

PHP Code:
ConVar sFunRoundsEnabled;
ConVar sRoundInterval;
int g_round_interval;

public 
void OnPluginStart()
{
    
sFunRoundsEnabled CreateConVar("funrounds_enabled""1""Enable/disable plugin"FCVAR_NOTIFY|FCVAR_REPLICATED);
    
sRoundInterval CreateConVar("funrounds_interval""2""Set number of rounds between a Fun/Special round (0=Everyround will be funround)"FCVAR_NOTIFY);
    
HookEvent("round_end"Event_OnRoundEndEventHookMode_PostNoCopy);
}
public 
void Event_OnRoundEnd(Handle event, const char[] namebool dontBroadcast)
{
g_round_interval++;
if(
sFunRoundsEnabled.IntValue == 1)
{
        if(
sRoundInterval.IntValue > -1)
        {
            if(
g_round_interval == sRoundInterval.IntValue)
            {
                
g_round_interval = -1;
                new 
random GetRandomInt(111);
                switch(
random)
                {
                    case 
1:
                    {
                        if(
sEnabledBhop.IntValue 0)BhopRound true;SpecialRound true;
                    }
                    case 
2:
                    {
                        if(
sEnabledAWP.IntValue 0)AWP_Round true;SpecialRound true;
                    }
                    case 
3:
                    {
                        if(
sEnabledKnife.IntValue 0)KnifeRound true;SpecialRound true;
                    }
                    case 
4:
                    {
                        if(
g_Game == Engine_CSGO && sEnabledZeus.IntValue 0)ZeusRound true;SpecialRound true;
                    }
                    case 
5:
                    {
                        if(
sEnabledDeagle.IntValue 0)DeagleRound true;SpecialRound true;ServerCommand("sm_cvar sm_restrict_deagle_ct -1");ServerCommand("sm_cvar sm_restrict_deagle_t -1");
                    }
                    case 
6:
                    {
                        if(
sEnabledScout.IntValue 0)ScoutRound true;SpecialRound true;
                    }
                    case 
7:
                    {
                        if(
sEnabledNegav.IntValue 0)NegavRound true;SpecialRound true;
                    }
                    case 
8:
                    {
                        if(
sEnabledAK.IntValue 0)AkRound true;SpecialRound true;
                    }
                    case 
9:
                    {
                        if(
sEnabledShotgun.IntValue 0)ShotgunRound true;SpecialRound true;
                    }
                    case 
10:
                    {
                        if(
sEnabledGaygun.IntValue 0)GaygunRound true;SpecialRound true;
                    }
                    case 
11:
                    {
                        if(
sEnabledNade.IntValue 0)NadeRound true;SpecialRound true;
                    }
                }
            }
        }
    }


Last edited by born for gaming; 08-27-2021 at 00:57.
born for gaming is offline
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 09-10-2021 , 13:15   Re: Need Help with a plugin
Reply With Quote #3

Seems like you found the way to do it, however, here is the same part of code, but written a bit better, according to me

Code:
ConVar sFunRoundsEnabled;
ConVar sRoundInterval;
int g_round_interval = -1;

public void OnPluginStart()
{
    sFunRoundsEnabled = CreateConVar("funrounds_enabled", "1", "Enable/disable plugin", FCVAR_NOTIFY|FCVAR_REPLICATED);
    sRoundInterval = CreateConVar("funrounds_interval", "2", "Set number of rounds between a Fun/Special round (0=Everyround will be funround)", FCVAR_NOTIFY);
    HookEvent("round_end", Event_OnRoundEnd, EventHookMode_PostNoCopy);
}
public void Event_OnRoundEnd(Handle event, const char[] name, bool dontBroadcast)
{
	g_round_interval++;
	if (!sFunRoundsEnabled.BoolValue || sRoundInterval.IntValue <= -1 || g_round_interval != sRoundInterval.IntValue)
		return;
	
	g_round_interval = -1;
	int random = GetRandomInt(1, 11);
	switch(random)
	{
		case 1:
		{
			if (!sEnabledBhop.BoolValue)
				return;
			BhopRound = true;
        }
        case 2:
        {
            if (!sEnabledAWP.BoolValue)
				return;
			AWP_Round = true;
        }
        case 3:
        {
            if (!sEnabledKnife.BoolValue)
            	return;
            KnifeRound = true;
        }
        case 4:
        {
            if(g_Game != Engine_CSGO || !sEnabledZeus.BoolValue)
            	return;
            ZeusRound = true;
        }
        case 5:
        {
            if (!sEnabledDeagle.BoolValue)
            	return;
            DeagleRound = true;
            ServerCommand("sm_cvar sm_restrict_deagle_ct -1");
            ServerCommand("sm_cvar sm_restrict_deagle_t -1");
        }
        case 6:
        {
            if (!sEnabledScout.BoolValue)
            	return;
            ScoutRound = true;
        }
        case 7:
        {
            if (!sEnabledNegav.BoolValue)
            	return;
            NegavRound = true;
        }
        case 8:
        {
            if (!sEnabledAK.BoolValue)
            	return;
            AkRound = true;
        }
        case 9:
        {
            if (!sEnabledShotgun.BoolValue)
            	return;
            ShotgunRound = true;
        }
        case 10:
        {
            if (!sEnabledGaygun.BoolValue)
            	return;
            GaygunRound = true;
        }
        case 11:
        {
            if (!sEnabledNade.BoolValue)
            	return;
            NadeRound = true;
        }
    }
    SpecialRound = true;
}
new random = old syntax, use int random instead

same for new String: , use char sExampleString[16];

don't draw a montain with your code, avoid making 1 IF per indentation, use them on the same line, ex:
Code:
if (test > 5)
{
   if (test2 > 3)
   {
       // do things..
   }
}
can be changed to
Code:
if (test > 5 && test2 > 3)

avoid doing any indentation if possible. For example, instead of doing
Code:
if (sFunRoundsEnabled.BoolValue)
{
   // do things...
}
// if you don't enter this IF, well.. nothing happens
do

Code:
if (!sFunRoundsEnabled.BoolValue)
   return;
// do things...
Sorry for (bumping) a resolved thread

Good luck with your plugins! If you need any help, you can create a new thread and message me (or even add me on discord)
__________________
GitHub | Discord: @azalty | Steam

Last edited by azalty; 09-10-2021 at 13:15.
azalty 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 03:14.


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