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

Cvars in an array with loop


Post New Thread Reply   
 
Thread Tools Display Modes
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-05-2018 , 14:17   Re: Cvars in an array with loop
Reply With Quote #11

Just use SortIntegers.

Made a sample plugin.
PHP Code:
#include <sourcemod>

#pragma semicolon 1

ConVar g_cvTest[2];

public 
void OnPluginStart()
{
    
g_cvTest[0] = CreateConVar("test0""0");
    
g_cvTest[1] = CreateConVar("test1""1");
    
    
int iTest[2];
    
    
iTest[0] = g_cvTest[0].IntValue;
    
iTest[1] = g_cvTest[1].IntValue;
    
    
SortIntegers(iTestsizeof(iTest), Sort_Ascending);

mug1wara is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 08-05-2018 , 14:20   Re: Cvars in an array with loop
Reply With Quote #12

This is the exact code I used to test. Since what you posted wasn't going to compile anyway, I changed it slightly:

PHP Code:
ConVar Cvar[12];
public 
void OnPluginStart()
{
    
Cvar[0]         = CreateConVar"l4d2_cvar1",    "1""");
    
Cvar[1]        = CreateConVar"l4d2_cvar2",     "2""");
    
Cvar[2]         = CreateConVar"l4d2_cvar3",     "3""");
    
Cvar[3]        = CreateConVar"l4d2_cvar4",    "4""");
    
Cvar[4]        = CreateConVar"l4d2_cvar5",    "5""");
    
Cvar[5]        = CreateConVar"l4d2_cvar6",    "6""");
    
Cvar[6]        = CreateConVar"l4d2_cvar7",    "7""");
    
Cvar[7]        = CreateConVar"l4d2_cvar8",    "8""");
    
Cvar[8]        = CreateConVar"l4d2_cvar9",    "9""");
    
Cvar[9]        = CreateConVar"l4d2_cvar10",    "10""");
    
Cvar[10]        = CreateConVar"l4d2_cvar11",    "11""");
    
Cvar[11]        = CreateConVar"l4d2_cvar12",    "12""");

    
RegServerCmd("cvartest"Command_CVARFUNCTION);
}

public 
Action Command_CVARFUNCTION(int argc)
{
    
int len sizeof(Cvar);

    for(
int xlenx++)
    {
        for(
int iCvar[x].IntValuei++ )
        {
            
PrintToServer("CVAR Num: %d"Cvar[x].IntValue);
        }
    }

    return 
Plugin_Handled;

I have no idea what your intention was with the nested loops. If you just wanted to print each cvar once, you should have a single loop.
Fyren is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-05-2018 , 22:50   Re: Cvars in an array with loop
Reply With Quote #13

Quote:
Originally Posted by Fyren View Post
I have no idea what your intention was with the nested loops. If you just wanted to print each cvar once, you should have a single loop.
Let me explain what I need to do. I have 12 cvars with more being added in the future. I'm pretty much doing the same action as item spawn code is the same each time, but each cvar represents different item and its count.

Example:
  • Item1 = 2
  • item2 = 6
  • item = 9

I do not want to hard code the cvars for reason stated above. I want to retrieve these values and pretty much run the loop to spawn them. I'm getting stuck at the fact that I need to run two loops in this case.

One to loop through all cvars and then another to spawn each item based on the count. This is why I was playing around with nested loops. Not sure, if that explanation will get me an answer.
__________________
Spirit_12 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 08-06-2018 , 10:53   Re: Cvars in an array with loop
Reply With Quote #14

Then it loops the number of times you want. Since it prints 1, 2, 2, 3, 3, 3..., if you were spawning an item each time instead of printing, that'd be the right number of times (one of the first, two of the second, three of the third, etc.).
Fyren 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 08:56.


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