AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   doing both if and else why? (https://forums.alliedmods.net/showthread.php?t=75718)

whosyourdaddy 08-10-2008 21:25

doing both if and else why?
 
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)
    }
}


Emp` 08-10-2008 23:10

Re: doing both if and else why?
 
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
                  }
            }
    }


whosyourdaddy 08-10-2008 23:11

Re: doing both if and else why?
 
thnks

whosyourdaddy 08-12-2008 17:57

Re: doing both if and else why?
 
how can i put a
Code:

set_task(600.0,"function",id)


in the plugin int

danielkza 08-12-2008 18:13

Re: doing both if and else why?
 
Quote:

Originally Posted by whosyourdaddy (Post 668729)
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")
}



?????

whosyourdaddy 08-12-2008 18:16

Re: doing both if and else why?
 
im getting an unknown id tho

danielkza 08-12-2008 18:35

Re: doing both if and else why?
 
Quote:

Originally Posted by whosyourdaddy (Post 668741)
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.

whosyourdaddy 08-12-2008 18:48

Re: doing both if and else why?
 
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)
    }
}


Emp` 08-13-2008 00:54

Re: doing both if and else why?
 
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.

whosyourdaddy 08-13-2008 02:58

Re: doing both if and else why?
 
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


All times are GMT -4. The time now is 03:04.

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