Raised This Month: $ Target: $400
 0% 

Problem with for-loops


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-03-2011 , 15:04   Re: Problem with for-loops
Reply With Quote #5

DjOptimus is correct. You must check if the player is connected before you use functions on that player everywhere you use a for loop with g_max_clients. You should be seeing errors in your logs. Also remember to enable debug when testing your plugins.

Tip: Any time you see code that repeats more than a few times, you need to optimize:

PHP Code:
public menu_handler(idcountdowneitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(countdowne)
        return 
PLUGIN_HANDLED
    
}
    new 
Data[7], Name[64]
    new 
AccessCallback
    menu_item_getinfo
(countdowneitemAccessData,5Name63Callback)
    new 
Key str_to_num(Data)
    switch(
Key)
    {
        case 
1timer 30
        
case 2timer 60
        
case 3timer 100
    
}
    
menu_destroy(countdowne)

    
set_hudmessage(255255255, -1.00.8606.010.0)
    
show_hudmessage(0"Heute spielen wir verstecken!")

    
get_user_name(idname32)
    
set_task(1.0"countdownv"6875)
    return 
PLUGIN_HANDLED
}

public 
countdownv(id)
{
    if( 
timer <= )
    {
        
set_hudmessage02550, -1.00.5025.08.00.00.010)
        
show_hudmessage(0"Wir hoffen, ihr habt euch gut versteckt!")
        
stop_t_from_moving(id)
    }
    else
    {
        
set_hudmessage02550, -1.00.4025.08.00.00.010)
        
show_hudmessage(0"%s startete einen Countdown.^nZeit bis die CT's kommen: %i"nametimer)
        
timer--
        
set_task(1.0"countdownv"6875)
    }

This will save you about 300 lines of code.
__________________

Last edited by fysiks; 04-03-2011 at 15:13.
fysiks is offline
 



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 14:30.


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