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

[SOLVED] Code breaks after loop?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dataviruset
AlliedModders Donor
Join Date: Feb 2009
Location: Hong Kong
Old 11-03-2009 , 15:49   [SOLVED] Code breaks after loop?
Reply With Quote #1

Hello!

I don't understand why my RoundStart-event just stops working in a loop.
No code afterwards is being executed, why?

PHP Code:
public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
ct_give GetConVarInt(sm_hosties_ct_start);

    
// strip all weapons and give new stuff
    
new wepIdx;
    for(new 
i=1<= GetMaxClients(); i++)
    {
        if ( (
IsClientConnected(i)) && (IsClientInGame(i)) && (IsPlayerAlive(i)) ) // if player exists and is alive
        
{
            for (new 
04s++)
            {
                if ((
wepIdx GetPlayerWeaponSlot(is)) != -1)
                {
                    
RemovePlayerItem(iwepIdx);
                    
RemoveEdict(wepIdx);
                }
            }
        }

        
// if player == T
        
if (GetClientTeam(i) == 2)
        {
            
GivePlayerItem(i"weapon_knife");
        }
        
// if player == CT
        
else if (GetClientTeam(i) == 3)
        {
            
GivePlayerItem(i"weapon_knife");
            if (
ct_give 0)
                
GivePlayerItem(i"weapon_deagle");
            if (
ct_give 1)
                
GivePlayerItem(i"weapon_m4a1");
        }

        
PrintToChatAll("\x04[SM_Hosties DEBUG] \x01Weapon stripper: Loop %d finished."i);
    }

    
// everything done, enable player weapon dropping again
    
AllowWeaponDrop true// >THIS< will not be executed?


Last edited by dataviruset; 11-04-2009 at 02:53.
dataviruset is offline
BrutalGoerge
AlliedModders Donor
Join Date: Jul 2007
Old 11-03-2009 , 16:05   Re: Code breaks after loop?
Reply With Quote #2

if its halting, then chances are there's something in your error logs that could help

perhaps check to make sure they're alive when you give the weapons?
__________________
My Pluggies If you like, consider to me.
BrutalGoerge is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 11-03-2009 , 16:22   Re: Code breaks after loop?
Reply With Quote #3

Throw some PrintToChatAll() debug messages in your code and try to locate where it's bugging down at. Also, you might want to look into using a SDK call to strip players rather then having to do all that fun stuff.

Minor optimization: replace GetMaxClients() with MaxClients
__________________
thetwistedpanda is offline
dataviruset
AlliedModders Donor
Join Date: Feb 2009
Location: Hong Kong
Old 11-03-2009 , 16:29   Re: Code breaks after loop?
Reply With Quote #4

This was a bit embarrasing, the error was BrutalGoerge's guess (that I should have checked to make sure that the players are alive when I give the weapons ).
But thanks to both of you, I will check that SDKCall out aswell!
dataviruset is offline
meng
Veteran Member
Join Date: Oct 2005
Location: us
Old 11-03-2009 , 18:56   Re: Code breaks after loop?
Reply With Quote #5

you already check if they are in game and alive. just give weapons inside that bracket
PHP Code:
    for (new 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && IsPlayerAlive(i)) // if player exists and is alive
        
{
            for (new 
04s++)
            {
                if ((
wepIdx GetPlayerWeaponSlot(is)) != -1)
                {
                    
RemovePlayerItem(iwepIdx);
                    
RemoveEdict(wepIdx);
                }
            }
            
// if player == T
            
if (GetClientTeam(i) == 2)
            {
                
GivePlayerItem(i"weapon_knife");
            }
            
// if player == CT
            
else if (GetClientTeam(i) == 3)
            {
                
GivePlayerItem(i"weapon_knife");
                if (
ct_give 0)
                    
GivePlayerItem(i"weapon_deagle");
                if (
ct_give 1)
                    
GivePlayerItem(i"weapon_m4a1");
            }
        }
    } 
meng is offline
Send a message via Yahoo to meng
dataviruset
AlliedModders Donor
Join Date: Feb 2009
Location: Hong Kong
Old 11-04-2009 , 02:52   Re: Code breaks after loop?
Reply With Quote #6

I know, solved it. Perhaps I should add [SOLVED] to the beggining of the topic
dataviruset 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 21:30.


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