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

Solved Load a script at certain days of the week


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 04-30-2019 , 12:48   Load a script at certain days of the week
Reply With Quote #1

Hello everyone,
I'm trying to create a plugin that switches to gungame mod at certain days of the week.

Using the weekdays array I'm able to set a value by default of strings I put inside it.
By that value I check if cvar contains any of that number and if that's true it loads a script, if there are in the same day.

Code:
new iCvar; new weekdays[8][10] = {     "",  // 0     "Monday",   // 1     "Tuesday"// 2     "Wednesday",    // 3     "Thursday"// 4     "Friday",   // 5     "Saturday"// 6     "Sunday"    // 7 }; public plugin_init(){     iCvar = register_cvar("gungame_days_list", "1357");         if (LoadDays()){         // load_gungame stuff     } } bool:LoadDays(){     new bool:b_return = false;          new day[10];     get_time("%A", day, charsmax(day));     new szCvar[8];     get_pcvar_string(iCvar, szCvar, charsmax(szCvar));         new len = strlen(szCvar);     new p_iCvar;         for (new i = 0; i < len; i++){         p_iCvar = get_pcvar_num(szCvar[i]);                 for (new j = 0; j < sizeof(weekdays); j++){             if (equal(day, weekdays[j]) && p_iCvar == j){                 b_return = true;                 break;             }         }     }     return bool:b_return; }
__________________

Last edited by Relaxing; 04-30-2019 at 15:19.
Relaxing is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 04-30-2019 , 14:05   Re: Load a script at certain days of the week
Reply With Quote #2

And what is the issue here?
__________________
edon1337 is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 04-30-2019 , 14:46   Re: Load a script at certain days of the week
Reply With Quote #3

The server seems to crash. Tested locally and same results. Something might be wrong but logically this should've worked.
__________________
Relaxing is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 04-30-2019 , 15:03   Re: Load a script at certain days of the week
Reply With Quote #4

PHP Code:
p_iCvar get_pcvar_num(szCvar[i]); 
->
PHP Code:
p_iCvar str_to_num(szCvar[i]); 
PHP Code:
return b_return
Try this, not sure if this is the cause of the crash but it may be.
__________________
Airkish is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 04-30-2019 , 15:18   Re: Load a script at certain days of the week
Reply With Quote #5

Quote:
Originally Posted by Airkish View Post
PHP Code:
p_iCvar get_pcvar_num(szCvar[i]); 
->
PHP Code:
p_iCvar str_to_num(szCvar[i]); 
PHP Code:
return b_return
Try this, not sure if this is the cause of the crash but it may be.
Heck, str_to_num slipped through my head. Well that change makes the code work just fine.
Thanks
__________________
Relaxing is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 04-30-2019 , 15:21   Re: Load a script at certain days of the week
Reply With Quote #6

You were using get_pcvar_num on szCvar which contained "1357", so it probably always returned 0/-1.

Quote:
Originally Posted by Airkish View Post
PHP Code:
return b_return
Try this, not sure if this is the cause of the crash but it may be.
The function is a bool and so is the return value.
__________________
edon1337 is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 04-30-2019 , 15:59   Re: Load a script at certain days of the week
Reply With Quote #7

Quote:
Originally Posted by edon1337 View Post
You were using get_pcvar_num on szCvar which contained "1357", so it probably always returned 0/-1.



The function is a bool and so is the return value.

IIRC you don't need to tag return to bool.
__________________

Last edited by Airkish; 04-30-2019 at 15:59.
Airkish is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 04-30-2019 , 16:02   Re: Load a script at certain days of the week
Reply With Quote #8

Quote:
Originally Posted by Airkish View Post
IIRC you don't need to tag return to bool.
You're not wrong either, either way is ok.
__________________
edon1337 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-30-2019 , 21:25   Re: Load a script at certain days of the week
Reply With Quote #9

Quote:
Originally Posted by edon1337 View Post
You're not wrong either, either way is ok.
The return variable is already tagged as boolean so it's redundant.
__________________
fysiks 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:44.


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