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

Arrays


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 06-19-2015 , 01:17   Arrays
Reply With Quote #1

I have a quick question for you guys.

How would I push a value into an array in a specific location.

For example this puts them to the end of the array:

PHP Code:
new iIndex FindValueInArray(g_aQueueiClient);
if(
iIndex == -1)
    
iIndex PushArrayCell(g_aQueueiClient); 
How would I push a value to the front or to a specified location in the array?
Addicted. is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 06-19-2015 , 01:48   Re: Arrays
Reply With Quote #2

Not exactly sure about that, but I would try to use ShiftArrayUp and then SetArrayCell.
KissLick is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 06-19-2015 , 02:03   Re: Arrays
Reply With Quote #3

Something like this then?

PHP Code:
new iIndex FindValueInArray(g_aQueueiClient);
if(
iIndex == -1)
{
    if (
CheckCommandAccess(iClient""ADMFLAG_RESERVATIONtrue))
    {
        
ShiftArrayUp(g_aQueue0);
        
SetArrayCell(g_aQueue0iClient);
        
iIndex g_aQueue[iClient];
    }

    else
    {
    
iIndex PushArrayCell(g_aQueueiClient);
    }

Addicted. is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 06-19-2015 , 03:21   Re: Arrays
Reply With Quote #4

Guess so, I never did something like this.
KissLick is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 06-19-2015 , 04:00   Re: Arrays
Reply With Quote #5

Why do you want to do this? Maybe a trie (hash map) might work better?
Potato Uno is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 06-19-2015 , 04:25   Re: Arrays
Reply With Quote #6

Quote:
Originally Posted by Potato Uno View Post
Why do you want to do this? Maybe a trie (hash map) might work better?
I am trying to allow clients with a specific flag to bypass a queue that can be entered by any user via a command.

Last edited by Addicted.; 06-19-2015 at 04:25.
Addicted. is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 06-19-2015 , 10:14   Re: Arrays
Reply With Quote #7

So I tested what I wrote above and it does not seem to be working. Do you guys have any ideas?
Addicted. is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-19-2015 , 11:06   Re: Arrays
Reply With Quote #8

When you say array, you are talking about an adt_array (aka ArrayList) right?
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 06-19-2015 , 11:11   Re: Arrays
Reply With Quote #9

Code:
PHP Code:
#include <sourcemod>

public Plugin:myinfo =
{
    
name "Test-Array",
    
author "Raska",
    
description "Test Array",
    
version "0.1",
    
url ""
}

public 
OnPluginStart()
{
    new 
Handle:hArray CreateArray();
    
    
PushArrayCell(hArray'A');
    
PushArrayCell(hArray'B');
    
PushArrayCell(hArray'C');
    
PushArrayCell(hArray'D');
    
    for (new 
0GetArraySize(hArray); i++) {
        
LogMessage("Array[%d] = '%c'"iGetArrayCell(hArrayi));
    }
    
    
ShiftArrayUp(hArray0);
    
SetArrayCell(hArray0'+');
    
    for (new 
0GetArraySize(hArray); i++) {
        
LogMessage("Array[%d] = '%c'"iGetArrayCell(hArrayi));
    }

Log:
PHP Code:
L 06/19/2015 17:09:51: [Test-Array.smx] Array[0] = 'A'
L 06/19/2015 17:09:51: [Test-Array.smx] Array[1] = 'B'
L 06/19/2015 17:09:51: [Test-Array.smx] Array[2] = 'C'
L 06/19/2015 17:09:51: [Test-Array.smx] Array[3] = 'D'

L 06/19/2015 17:09:51: [Test-Array.smx] Array[0] = '+'
L 06/19/2015 17:09:51: [Test-Array.smx] Array[1] = 'A'
L 06/19/2015 17:09:51: [Test-Array.smx] Array[2] = 'B'
L 06/19/2015 17:09:51: [Test-Array.smx] Array[3] = 'C'
L 06/19/2015 17:09:51: [Test-Array.smx] Array[4] = 'D' 
KissLick is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 06-19-2015 , 13:21   Re: Arrays
Reply With Quote #10

Thanks KissLick!

I realized I had to mess around with some other functions too but the ShiftArrayUp then SetArrayCell worked like a charm.
Addicted. 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 01:57.


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