Raised This Month: $ Target: $400
 0% 

doing both if and else why?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
whosyourdaddy
Senior Member
Join Date: Apr 2008
Old 08-10-2008 , 21:25   doing both if and else why?
Reply With Quote #1

ok what im trying to make it do is if they have a max_level then do the if satements but if there not in the lvl14.ini file then it should do the else statement but for some reason its doing both the if and else statements

Code:
public function(id){
     new file = fopen(adminfile,"r")
     new steamid[32],parsedid[32],parsedlevel[32], txtlen
 
     if(file_exists(adminfile))
     {     
 
           if(!file)
                 return;
 
           new readdata[128]
           new fsize = file_size(adminfile,1)
           for (new line=0;line<=fsize;line++)
           {     
                 get_user_authid(id,steamid,31)                  
                 read_file(adminfile,line,readdata,127,txtlen)
                 parse(readdata,parsedid,31,parsedlevel,31)
                 if(equali(parsedid,steamid))
                 {
                       MAX_LEVEL = str_to_num(parsedlevel)
 
                       if(MAX_LEVEL == 14 && p_data[id][P_XP] > 250000)
                       {
                             client_print(id,print_chat, "[sFx] You have reached your max level. Join our forums to unlock the rest of the levels. ")
                             p_data[id][P_XP] = 240000
                       }
                       else if(MAX_LEVEL == 15 && p_data[id][P_XP] > 300000)
                       {
                             client_print(id,print_chat, "[sFx] You have reached your max level. Join our forums to unlock the rest of the levels. ")
                             p_data[id][P_XP] = 290000
                       }
                       else if(MAX_LEVEL == 16 && p_data[id][P_XP] > 350000)
                       {
                             client_print(id,print_chat, "[sFx] You have reached your max level. Join our forums to unlock the rest of the levels. ")
                             p_data[id][P_XP] = 340000
                       }
                       else if(MAX_LEVEL == 17 && p_data[id][P_XP] > 400000)
                       {
                             client_print(id,print_chat, "[sFx] CONGRATS FROM THE [sFx] COMMUNITY ON YOUR LEVEL 17. ")
 
                       }
 
                 }                 
                 else 
                 {
 
                       if(p_data[id][P_XP] > 200000)
                       {
                             client_print(id,print_chat, "[sFx] You have reached your max level. Join our forums to unlock the rest of the levels. ")
                             p_data[id][P_XP] = 190000
                       }
                 }
 
           }     
           fclose(file)
     }
}

Last edited by whosyourdaddy; 08-10-2008 at 21:27.
whosyourdaddy is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 08-10-2008 , 23:10   Re: doing both if and else why?
Reply With Quote #2

The else is reflecting whether their steamid matches the one on the current line.
Code:
public function(id){
     new file = fopen(adminfile,"r")
     new steamid[32],parsedid[32],parsedlevel[32], txtlen
 
     new bool:in_file = false;

     if(file_exists(adminfile))
     {     
 
           if(!file)
                 return;
 
           new readdata[128]
           new fsize = file_size(adminfile,1)
           for (new line=0;line<=fsize;line++)
           {     
                 get_user_authid(id,steamid,31)                  
                 read_file(adminfile,line,readdata,127,txtlen)
                 parse(readdata,parsedid,31,parsedlevel,31)
                 if(equali(parsedid,steamid))
                 {
                       in_file = true;
                       MAX_LEVEL = str_to_num(parsedlevel)
 
                       if(MAX_LEVEL == 14 && p_data[id][P_XP] > 250000)
                       {
                             client_print(id,print_chat, "[sFx] You have reached your max level. Join our forums to unlock the rest of the levels. ")
                             p_data[id][P_XP] = 240000
                       }
                       else if(MAX_LEVEL == 15 && p_data[id][P_XP] > 300000)
                       {
                             client_print(id,print_chat, "[sFx] You have reached your max level. Join our forums to unlock the rest of the levels. ")
                             p_data[id][P_XP] = 290000
                       }
                       else if(MAX_LEVEL == 16 && p_data[id][P_XP] > 350000)
                       {
                             client_print(id,print_chat, "[sFx] You have reached your max level. Join our forums to unlock the rest of the levels. ")
                             p_data[id][P_XP] = 340000
                       }
                       else if(MAX_LEVEL == 17 && p_data[id][P_XP] > 400000)
                       {
                             client_print(id,print_chat, "[sFx] CONGRATS FROM THE [sFx] COMMUNITY ON YOUR LEVEL 17. ")
 
                       }
 
                 }  
 
           }     
           fclose(file)

           if( !in_file ) 
           {
 
                  if(p_data[id][P_XP] > 200000)
                  {
                       client_print(id,print_chat, "[sFx] You have reached your max level. Join our forums to unlock the rest of the levels. ")
                       p_data[id][P_XP] = 190000
                  }
            }
     }
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
whosyourdaddy
Senior Member
Join Date: Apr 2008
Old 08-10-2008 , 23:11   Re: doing both if and else why?
Reply With Quote #3

thnks

Last edited by whosyourdaddy; 08-10-2008 at 23:36.
whosyourdaddy is offline
whosyourdaddy
Senior Member
Join Date: Apr 2008
Old 08-12-2008 , 17:57   Re: doing both if and else why?
Reply With Quote #4

how can i put a
Code:
set_task(600.0,"function",id)


in the plugin int
whosyourdaddy is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 08-12-2008 , 18:13   Re: doing both if and else why?
Reply With Quote #5

Quote:
Originally Posted by whosyourdaddy View Post
how can i put a
Code:
set_task(600.0,"function",id)
in the plugin int
Code:
public plugin_init()
{
   set_task(600.0,"function",id)
}

public function(id)
{
    client_print(id,print_chat,"TASK EXECUTED")
}


?????
danielkza is offline
whosyourdaddy
Senior Member
Join Date: Apr 2008
Old 08-12-2008 , 18:16   Re: doing both if and else why?
Reply With Quote #6

im getting an unknown id tho
whosyourdaddy is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 08-12-2008 , 18:35   Re: doing both if and else why?
Reply With Quote #7

Quote:
Originally Posted by whosyourdaddy View Post
im getting an unknown id tho
What i posted is just a snippet. You must adapt it to your needs. Replace id with the variable where you store the player id into. If you wan't to do this for every player,it's better to create a single task (with no 'id' parameter'),and loop through player in it.
danielkza is offline
whosyourdaddy
Senior Member
Join Date: Apr 2008
Old 08-12-2008 , 18:48   Re: doing both if and else why?
Reply With Quote #8

i want to use it for the function posted above by EMP` think u can tell me how to do it

*edited*
would this work correctly?

Code:
 
public Player_scoll(id)
{
new iPlayers[32], iNumPlayers, id;
get_players( iPlayers, iNumPlayers );
 
  for ( i = 0; i < iNumPlayers; i++ )
  {
      id = iPlayers[i];
         function(id)
    }
}

Last edited by whosyourdaddy; 08-12-2008 at 19:19.
whosyourdaddy is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 08-13-2008 , 00:54   Re: doing both if and else why?
Reply With Quote #9

Code:
public plugin_init()
{
  //...

  set_task(600.0, "Player_scoll");
}

public Player_scoll()
{
new iPlayers[32], iNumPlayers, id;
get_players( iPlayers, iNumPlayers );
 
  for ( i = 0; i < iNumPlayers; i++ )
  {
      id = iPlayers[i];
         function(id)
    }
}
Should work, but I would suggest executing your function every so often, not just 10 minutes after server start/map change.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
whosyourdaddy
Senior Member
Join Date: Apr 2008
Old 08-13-2008 , 02:58   Re: doing both if and else why?
Reply With Quote #10

ya its cause my test server was crashing every so often so i thought it might be this but i found out why and it was because if a stupid mistake i made, im pretty much re-writing the whole wc3 mod to have 17 levels, already have it to 13 levels and has been running without crashes for 1 or 2 months no im making it 17 with new skills wasnt sure if it was this new addition or something i did wrong but i found out thanks alot for ur help
whosyourdaddy 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:03.


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