Raised This Month: $ Target: $400
 0% 

Array and variables


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
L0neW0lf
Member
Join Date: Mar 2006
Location: Denmark
Old 03-23-2006 , 17:06   Array and variables
Reply With Quote #1

This is a definition for time in a banmenu, but i only know Basic so i need som help.

new g_HighBanMenuValues[4] = {5, 60, 6000, 0}

I can see this is an array with 4 values, i would like to convert the values to the following. new g_HighBanMenuValues[4] = {1 Hour,3 Days, 7 Days, Permanent}

My problem is the handling of it, so i need to make those strings as variables and give them a number so when the script runs i takes the number instead of the string......

Hope you understand

/Wolf
L0neW0lf is offline
Send a message via ICQ to L0neW0lf Send a message via MSN to L0neW0lf Send a message via Skype™ to L0neW0lf
L0neW0lf
Member
Join Date: Mar 2006
Location: Denmark
Old 03-23-2006 , 17:21  
Reply With Quote #2

could i define each value as a variable like this:

(it is basic syntax, and hope someone can translate)
dim 1Hour as integer
dim 3Days as integer
dim 7Days as integer
dim Permanent as integer

1Hour = 3600
3Days = 259200
7Days = 604800
Permanent = 0

new g_HighBanMenuValues[4] = {1Hour,3Days,7Days,Permanent}

And when the array is called the value given to the function will be the integer value of the variable.

Cold i do it like that ?
L0neW0lf is offline
Send a message via ICQ to L0neW0lf Send a message via MSN to L0neW0lf Send a message via Skype™ to L0neW0lf
akysiev
Junior Member
Join Date: Mar 2006
Location: Earth
Old 03-23-2006 , 18:03  
Reply With Quote #3

Code:
#define 1Hour 3600 #define 3Days 259200 #define 7Days 604800 #define Permanent 0 new g_HighBanMenuValues[4] = {1Hour, 3Days, 7Days, Permanent};

Strings are null terminated arrays. The defines are preprocessor directives so that 1Hour, 3Days, and other symbols are replaced with the numeric value defined by it right before it is compiled.
akysiev is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-23-2006 , 18:50  
Reply With Quote #4

This is the most dynamic way I can think of.

Also, this is not a string, so it doesn't need a null terminator. It is simply an array.

Code:
#define Second 1 #define Minute 60*Second #define Hour 60*Minute #define Day 24*Hour #define Week 7*Day #define Month 30*Day #define Permanent 0 new g_HighBanMenuValues[4] = {Hour, 3*Day, Week, Permanent}

On a side note, you can do

Code:
new g_HighBanMenuValues[] = {Hour, 3*Day, Week, Permanent}

And it should work.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 03-23-2006 , 20:04  
Reply With Quote #5

Though his example doesn't show it well, I think what L0neW0lf wants is for the menu to display the text but then return the integer value.

i.e.

Menu shows: 1 Hour, 3 Days, 7 Days, Permanent
Menu returns: 3600, 259200, 604800, 0

I think what you'd have to do is just see what text option was chosen and then based on that, assign the appropriate time integer to a variable.
Brad is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-23-2006 , 20:24  
Reply With Quote #6

Quote:
Originally Posted by Brad
Though his example doesn't show it well, I think what L0neW0lf wants is for the menu to display the text but then return the integer value.

i.e.

Menu shows: 1 Hour, 3 Days, 7 Days, Permanent
Menu returns: 3600, 259200, 604800, 0

I think what you'd have to do is just see what text option was chosen and then based on that, assign the appropriate time integer to a variable.
What about that stock you wrote? get_time_length is it?
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 03-23-2006 , 20:35  
Reply With Quote #7

Yes, get_time_length. It could be helpful if he wanted to make it more generic but really the issue is just the conversion from the textual choice the player made to the integer that the plugin needs. That would require either a conversion once the choice was made or if the menuing system allows it, piggybacking the integer value to the menu option somehow and just reading it when the choice is made.
Brad is offline
L0neW0lf
Member
Join Date: Mar 2006
Location: Denmark
Old 03-24-2006 , 01:13  
Reply With Quote #8

Tried to make the piggyback thing i guess
But yet again the code might be basic.

The original handling of the user choise:

if (get_user_flags(id)&HIGHER_BAN_TIME_ADMIN)
{
switch(g_menuOption[id])
{
case 0: g_menuSettings[id] = g_HighBanMenuValues[0]
case 1: g_menuSettings[id] = g_HighBanMenuValues[1]
case 2: g_menuSettings[id] = g_HighBanMenuValues[2]
case 3: g_menuSettings[id] = g_HighBanMenuValues[3]
}
}


My edited handling:

if (get_user_flags(id)&HIGHER_BAN_TIME_ADMIN)
{
switch(g_menuOption[id])
{
case 0: tempTime = g_HighBanMenuValues[0]
case 1: tempTime = g_HighBanMenuValues[1]
case 2: tempTime = g_HighBanMenuValues[2]
case 3: tempTime = g_HighBanMenuValues[3]
}
if temptime = 1Hour then g_menuSettings[id] = 60
if temptime = 1Hour then g_menuSettings[id] = 4320
if temptime = 1Hour then g_menuSettings[id] = 10080
if temptime = 1Hour then g_menuSettings[id] = 0
}


Is that a solution ?
L0neW0lf is offline
Send a message via ICQ to L0neW0lf Send a message via MSN to L0neW0lf Send a message via Skype™ to L0neW0lf
akysiev
Junior Member
Join Date: Mar 2006
Location: Earth
Old 03-24-2006 , 06:57  
Reply With Quote #9

What I'm confused about is what you want g_HighBanMenuValues to refer to, a string or an integer. The code you wrote is equivalent to

Code:
if (get_user_flags(id)&HIGHER_BAN_TIME_ADMIN) {     switch(g_menuOption[id])     {         case 0: g_menuSettings[id] = 60         case 1: g_menuSettings[id] = 4320         case 2: g_menuSettings[id] = 10080         case 3: g_menuSettings[id] = 0     } }

Please tell us exactly how you want the code to operate. By the way, the if clauses are written as such:

Code:
if (boolean) { } else if (boolean) { } else { } //or if (boolean) <in-line code here>
akysiev is offline
L0neW0lf
Member
Join Date: Mar 2006
Location: Denmark
Old 03-24-2006 , 07:05  
Reply With Quote #10

The following is the time minuts for a ban (0 = permanent)

Code:
if (get_user_flags(id)&HIGHER_BAN_TIME_ADMIN) {     switch(g_menuOption[id])     {         case 0: g_menuSettings[id] = 60         case 1: g_menuSettings[id] = 4320         case 2: g_menuSettings[id] = 10080         case 3: g_menuSettings[id] = 0     } }

In the ban menu those numbers are shown, but it can be har to know excactly what those number are in dayes/weeks.

So the thing i want to do is the banmenu shows:
Code:
1. 1Hour 2. 3Days 3. 7Days 4. Permanent

The problem is the function need the time in minuts and not a text string.
L0neW0lf is offline
Send a message via ICQ to L0neW0lf Send a message via MSN to L0neW0lf Send a message via Skype™ to L0neW0lf
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 16:38.


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