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

Solved Do loop stuck in game for 6 to 10 seconds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
born for gaming
Member
Join Date: Aug 2019
Location: Pakistan
Old 08-27-2021 , 01:04   Do loop stuck in game for 6 to 10 seconds
Reply With Quote #1

hi,

i am creating my first plugin
i created a do loop i put a condition in while(SpecialRound == true) if the condition is not true the do loop run again and again
"do loop" do which i want but in game when this code need to be execute the game stuck for 6 to 10 seconds which i not want. I will put sp file below. plz help me. Thanks in Advance

PHP Code:
                new random GetRandomInt(111);
                do{
                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;
                        }
                }
                }while(
SpecialRound == true
Attached Files
File Type: sp Get Plugin or Get Source (funrounds_by_slayer.sp - 96 views - 38.5 KB)

Last edited by born for gaming; 08-28-2021 at 23:51.
born for gaming is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 08-27-2021 , 08:48   Re: Do loop stuck in game for 6 to 10 seconds
Reply With Quote #2

Quote:
if the condition is not true the do loop run again and again
actually your logic is inverse according to your snippet

while (SpecialRound == true)

also...you don't need "== true" for true/false checks just while (SpecialRound) would be enough.

Maybe what you want is

PHP Code:
}while(!SpecialRound
According with the do/loop code you are running this loop forever, thats why is hanging from my analysis

But doesn't make much sense that logic if you will set "SpecialRound" on every option, is like doing the same without the "do"
__________________

Last edited by Marttt; 08-27-2021 at 08:50.
Marttt is offline
born for gaming
Member
Join Date: Aug 2019
Location: Pakistan
Old 08-27-2021 , 10:55   Re: Do loop stuck in game for 6 to 10 seconds
Reply With Quote #3

Quote:
Originally Posted by Marttt View Post
Maybe what you want is

PHP Code:
}while(!SpecialRound
bro thanks for reply
i want "while(SpecialRound)" must be true


for example there are two convar of two special round :
PHP Code:
    sEnabledDeagle CreateConVar("funrounds_deagle""1""Enabled/Disabled Deagle Round comes in Funrounds!"FCVAR_NOTIFY);
    
sEnabledKnife CreateConVar("funrounds_knife""0""Enabled/Disabled Knife Round comes in Funrounds!"FCVAR_NOTIFY); 
and then i create switch statement under do loop
PHP Code:
new random GetRandomInt(1,2);
do{
switch(
random){
       case 
1:
       {
              if(
sEnabledDeagle.IntValue 0)DeagleRound true;SpecialRound true;
       }
       case 
2:
       {
              if(
sEnabledKnife.IntValue 0)KnifeRound true;SpecialRound true;
       } 
}
}while(
SpecialRound); 
i created 2 cases
if switch statement randomly choose case 2
and then in case 2 "if(sEnabledKnife.IntValue > 0)" condition will be checked if condition is not match then it will not true knife round and also will not true special round
then at the end while loop condition will be checked so the condition will not be matched because case 2 not true special round because its off in convar
So do loop run again and if this time switch statement chose case 1 and then "if(sEnabledDeagle.IntValue > 0)" statement will be checked and condition will be match because "sEnabledDeagle = 1" in convar. SO at the end this condition will be check "while(SpecialRound)" and it will be match because special round will be true in case 1 and the plugin work as i want

but in game this process take 7 to 10 seconds

Last edited by born for gaming; 08-27-2021 at 12:13.
born for gaming is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 08-27-2021 , 11:49   Re: Do loop stuck in game for 6 to 10 seconds
Reply With Quote #4

Maybe I don't understand, but reading the code

you set "SpecialRound" = true (for both 1, 2 values) which means that the "while" will run endlessly
then takes 7~10 seconds cause SM will block the plugin execution if it takes too long

The use case is wrong for what you are trying to achieve IMO.
__________________
Marttt is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 08-27-2021 , 12:04   Re: Do loop stuck in game for 6 to 10 seconds
Reply With Quote #5

Here is an example about what I'm trying to say, paste on SPIDER click "Compile" then "Run" (the green button)

PHP Code:
static bool DeagleRound;
static 
bool KnifeRound;
static 
bool SpecialRound false;

static 
int sEnabledDeagle 1;
static 
int sEnabledKnife 1;

public 
void OnPluginStart()
{
    
PrintToServer("SpecialRound %s"SpecialRound "true" "false");
    
    
int random 1;
    
    
PrintToServer("random %i"random);
    
    do
    {
        
PrintToServer("Inside Loop: SpecialRound %s"SpecialRound "true" "false");
        
        switch(
random)
        {
            case 
1: { if (sEnabledDeagle 0DeagleRound trueSpecialRound true; }
            case 
2: { if (sEnabledKnife 0)  KnifeRound  trueSpecialRound true; } 
        }
    } while (
SpecialRound);
    
    
PrintToServer("Exit Loop");

__________________
Marttt is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 08-27-2021 , 12:17   Re: Do loop stuck in game for 6 to 10 seconds
Reply With Quote #6

Quote:
Originally Posted by Marttt View Post
Maybe I don't understand, but reading the code

you set "SpecialRound" = true (for both 1, 2 values) which means that the "while" will run endlessly
then takes 7~10 seconds cause SM will block the plugin execution if it takes too long

The use case is wrong for what you are trying to achieve IMO.
It seems that he's the one who doesn't understand you. I'm seeing the same flaw in his code's logic as you do.

Quote:
Originally Posted by Marttt View Post
also...you don't need "== true" for true/false checks just while (SpecialRound) would be enough.
Just to add to this: It's usually based on preference from what I've seen throughout the years and it actually improves readability for some people, so it's not necessarily wrong to do true/false checks this way.

Quote:
Originally Posted by born for gaming View Post
but in game this process take 7 to 10 seconds
Like Marttt said:

To fix your issue, change this:
Code:
while(SpecialRound == true)
To this:
Code:
while(SpecialRound == false)
__________________
Psyk0tik is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-27-2021 , 21:10   Re: Do loop stuck in game for 6 to 10 seconds
Reply With Quote #7

Quote:
Originally Posted by born for gaming View Post
PHP Code:
switch(random){
       case 
1:
       {
              if(
sEnabledDeagle.IntValue 0)DeagleRound true;SpecialRound true;
       }
       case 
2:
       {
              if(
sEnabledKnife.IntValue 0)KnifeRound true;SpecialRound true;
       } 

This is just one of those things that bother me. If your ConVar value is either going to be true or false then don't use

PHP Code:
IntValue 
Instead you can simply do

PHP Code:
switch(random){
       case 
1:
       {
              if(
sEnabledDeagle.BoolValue)DeagleRound true;SpecialRound true;
       }
       case 
2:
       {
              if(
sEnabledKnife.BoolValue)KnifeRound true;SpecialRound true;
       } 

__________________
Spirit_12 is offline
born for gaming
Member
Join Date: Aug 2019
Location: Pakistan
Old 08-28-2021 , 23:52   Re: Do loop stuck in game for 6 to 10 seconds
Reply With Quote #8

Thank you guys now my problem is solved
born for gaming 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 22:17.


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