AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] infinite loop due to invalid value (https://forums.alliedmods.net/showthread.php?t=105042)

HLM 09-30-2009 14:53

[HELP] infinite loop due to invalid value
 
PHP Code:

public hook_KeyValue(entIdkvd_id)
{
    
server_print("[MedicMod] keyvalue has been hooked.. entity hooked is ^"%d^"",entId)
    new 
maxteams 0
    
if(!pev_valid(entId))
        return 
FMRES_HANDLED;
    
    new 
className[64];
    
pev(entIdpev_classnameclassName63);
    
    if(
containi(className"info_tfdetect") != -&& !tfdetectMade)
    {
        while (
maxteams != || maxteams != || maxteams != || maxteams != 4)
        {
            
get_keyvalue(entId"number_of_teams"szValuesizeof(szValue)-1)
            
maxteams str_to_num(szValue)
            
server_print("[MedicMod] Looping to get maxteams : %d"szValue)
            
        }
        
        
server_print("[MedicMod] About to remove entity, maxteams = ^"%d^"",maxteams)
        
engfunc(EngFunc_RemoveEntityentId);
        
        if(!
tfdetectMade)
        {
            switch(
maxteams)
            {
                case 
1:
                {
                    new 
entFloat:entOrg[3];
                    
tfdetectMade true;
                    
                    
// Make the new tfdetect entity
                    
ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_tfdetect"));
                    
engfunc(EngFunc_SetOriginententOrg);
                    
engfunc(EngFunc_SetSizeentFloat:{-1.0,-1.0,-1.0}, Float:{1.0,1.0,1.0});
                    
set_pev(entpev_classname"info_tfdetect");
                    
set_pev(entpev_solidSOLID_NOT);
                    
set_pev(entpev_movetypeMOVETYPE_FLY);
                    
                    
// Add the keys and values to the entity
                    
set_keyvalue(ent"number_of_teams""1");
                    
set_keyvalue(ent"team1_name""Team L33T!");
                    
//set_keyvalue(ent, "team2_name", "Team pWn0rs!");
                    //set_keyvalue(ent, "team3_name", "Team h4wt!");
                    //set_keyvalue(ent, "team4_name", "Team sm3xi!");
                    
set_keyvalue(ent"toggleflags""0");
                    
set_keyvalue(ent"maxammo_shells""1007");
                    
//set_keyvalue(ent, "maxammo_nails", "1007");
                    //set_keyvalue(ent, "maxammo_rockets", "1007");
                    //set_keyvalue(ent, "maxammo_cells", "1007");
                    
set_keyvalue(ent"team1_allies""0");
                    
//set_keyvalue(ent, "team2_allies", "0");
                    //set_keyvalue(ent, "team3_allies", "0");
                    //set_keyvalue(ent, "team4_allies", "0");
                
}
                case 
2:
                {
                    new 
entFloat:entOrg[3];
                    
tfdetectMade true;
                    
                    
// Make the new tfdetect entity
                    
ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_tfdetect"));
                    
engfunc(EngFunc_SetOriginententOrg);
                    
engfunc(EngFunc_SetSizeentFloat:{-1.0,-1.0,-1.0}, Float:{1.0,1.0,1.0});
                    
set_pev(entpev_classname"info_tfdetect");
                    
set_pev(entpev_solidSOLID_NOT);
                    
set_pev(entpev_movetypeMOVETYPE_FLY);
                    
                    
// Add the keys and values to the entity
                    
set_keyvalue(ent"number_of_teams""2");
                    
set_keyvalue(ent"team1_name""Team h4x~!");
                    
set_keyvalue(ent"team2_name""Team pWn0rs!");
                    
//set_keyvalue(ent, "team3_name", "Team h4wt!");
                    //set_keyvalue(ent, "team4_name", "Team sm3xi!");
                    
set_keyvalue(ent"toggleflags""0");
                    
set_keyvalue(ent"maxammo_shells""1007");
                    
set_keyvalue(ent"maxammo_nails""1007");
                    
//set_keyvalue(ent, "maxammo_rockets", "1007");
                    //set_keyvalue(ent, "maxammo_cells", "1007");
                    
set_keyvalue(ent"team1_allies""0");
                    
set_keyvalue(ent"team2_allies""0");
                    
//set_keyvalue(ent, "team3_allies", "0");
                    //set_keyvalue(ent, "team4_allies", "0");    
                
}
                case 
3:
                {
                    
log_amx("maxteams was logged to be %d",szValue)
                    
pause("ad","medicmod-cutsom.amxx")
                }
                case 
4:
                {
                    new 
entFloat:entOrg[3];
                    
tfdetectMade true;
                    
                    
// Make the new tfdetect entity
                    
ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_tfdetect"));
                    
engfunc(EngFunc_SetOriginententOrg);
                    
engfunc(EngFunc_SetSizeentFloat:{-1.0,-1.0,-1.0}, Float:{1.0,1.0,1.0});
                    
set_pev(entpev_classname"info_tfdetect");
                    
set_pev(entpev_solidSOLID_NOT);
                    
set_pev(entpev_movetypeMOVETYPE_FLY);
                    
                    
// Add the keys and values to the entity
                    
set_keyvalue(ent"number_of_teams""4");
                    
set_keyvalue(ent"team1_name""Team h4x~!");
                    
set_keyvalue(ent"team2_name""Team pWn0rs!");
                    
set_keyvalue(ent"team3_name""Team h4wt!");
                    
set_keyvalue(ent"team4_name""Team sm3xi!");
                    
set_keyvalue(ent"toggleflags""0");
                    
set_keyvalue(ent"maxammo_shells""1007");
                    
set_keyvalue(ent"maxammo_nails""1007");
                    
set_keyvalue(ent"maxammo_rockets""1007");
                    
set_keyvalue(ent"maxammo_cells""1007");
                    
set_keyvalue(ent"team1_allies""0");
                    
set_keyvalue(ent"team2_allies""0");
                    
set_keyvalue(ent"team3_allies""0");
                    
set_keyvalue(ent"team4_allies""0");    
                }
                
            }
        }
    }
    return 
FMRES_HANDLED;


it originally wouldnt loop, but now its looping because maxteams ALWAYS equals 0.. anyone know why this might be? I know for a fact it does NOT equal 0.. since maxteams needs to have atleast one team

did I leave anything out?

Sylwester 09-30-2009 18:44

Re: [HELP] infinite loop due to invalid value
 
No matter what maxteams equals the loop will never end. It's exactly like this one:
PHP Code:

new a=0
while(!= || != 2)
{
    
a++


Try checking conditions in few iterations and you will understand (if you have basic programming knowledge).

HLM 09-30-2009 20:01

Re: [HELP] infinite loop due to invalid value
 
not quite sure, I set it to while(maxteams = 0).. I just now noticed it lags the whole datacenter.. I dunno.. anyways im lost =/

Sylwester 10-01-2009 02:40

Re: [HELP] infinite loop due to invalid value
 
Maybe you want while(maxteams == 0) ?
Why do you use loop? It looks like it is not necessary there. I don't understand what are you trying to do with this plugin.

Before you continue you should read:
http://forums.alliedmods.net/showthread.php?t=91207
Especially "Part 3 - Conditional Statements".

HLM 10-01-2009 15:42

Re: [HELP] infinite loop due to invalid value
 
ahh, yes I did, and this code will get the uhh 'maxteams' key and then depending on what the value is, use a switch for when it creates the new entity, this is code from the medicmod plugin..

basically this plugin would originally create one type of entity 'info_tfdetect' that consisted of just two teams.. I want the ability for 1, 2, and 4 teams.. that is why im trying to get this working

edit: what other ways can I get the keyvalue, it seems to be looping with it equaling 0.. doesnt that mean its not getting a value?


All times are GMT -4. The time now is 22:39.

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