AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Array and variables (https://forums.alliedmods.net/showthread.php?t=25922)

L0neW0lf 03-23-2006 17:06

Array and variables
 
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 03-23-2006 17:21

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 ?

akysiev 03-23-2006 18:03

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.

Hawk552 03-23-2006 18:50

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.

Brad 03-23-2006 20:04

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.

Hawk552 03-23-2006 20:24

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?

Brad 03-23-2006 20:35

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.

L0neW0lf 03-24-2006 01:13

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 ?

akysiev 03-24-2006 06:57

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>

L0neW0lf 03-24-2006 07:05

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.


All times are GMT -4. The time now is 16:38.

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