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

[SOLVED]Array "szString" = dInt (trie + dynamic array)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 10-05-2013 , 16:51   [SOLVED]Array "szString" = dInt (trie + dynamic array)
Reply With Quote #1

Hello! I am working on a weapon buy menu. I have already created a function to give the weapons, but now I need to find a way to store all the weapon names as strings with an integer value. for example, (using cs example, but this is NOT for cs! this is ONLY an example)

Quote:
Player1 say !buy m4a1

code sees !buy trigger, strips '!buy ' from szArg

for new i=0 loop through enum? Weapons to see if szArg = a row, if yes {FnGiveWepon(id,Weapons:i?; client_print(id, print_chat, "[AMXX] Bought the %s", szArg); }//szArg is used as I do not know a better way to pull the name from the enum

I need an enum because I have added entire weapon slots that give multiple weapons with an integer value offsetting the list

ex:
enum Weapons
{
weap1 = 1,
weap2,
weap3,
slot1 = 10,
weap4 [= 11],
weap5,
etc,
...,
}
am I right for choosing an enum in this? I was considering a multi-dimensional array, but I don't know if that would be correct for this.

Any and all help would be appreciated.

EDIT: if there is no way around it, I can make it so that the function only uses sequential numbers with no gaps, but I still dont know what I would use to store my data as I need to be able to pull a string and an integer(possibly the row number?) from each value.
__________________
+|- KARMA Respectively


Last edited by HLM; 10-07-2013 at 15:00. Reason: All fixed, thanks everyone! :)
HLM is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 10-05-2013 , 18:32   Re: Array "szString" = dInt
Reply With Quote #2

Are you looking for a weapon index from the name? What is the "integer value"?
If so you'll have to loop a multi-dimensional array. Doing it on a say command is not really a performance issue.
__________________

Last edited by Black Rose; 10-05-2013 at 18:32.
Black Rose is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 10-05-2013 , 19:18   Re: Array "szString" = dInt
Reply With Quote #3

so if im understanding this correctly, ill set up my array in the following manner:
PHP Code:
new const szWeapons[MAX_WEAPONS][MAX_LEN]
{
    
"NULL"
    
"Weapon 1"
    
"Weapon 2"
    
"NULL"
    
...
    ...
    
10 "slot1"

something like this? or can I skip empty rows and just go right from the last weapon and set up the weapon slot?
__________________
+|- KARMA Respectively

HLM is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 10-05-2013 , 20:04   Re: Array "szString" = dInt
Reply With Quote #4

I think I understand now.
Normally people use an enumeration to divide the different variables.
Code:
enum WeaponData {     _Integer,     _String[32] } new WeaponArray[MAX_WEAPONS][WeaponData]; // ... WeaponArray[index][_Integer] WeaponArray[index][_String]

You could also use dynamic arrays.

If I have misunderstood you, tell me what you're trying to do.
__________________

Last edited by Black Rose; 10-05-2013 at 20:07.
Black Rose is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 10-05-2013 , 21:57   Re: Array "szString" = dInt
Reply With Quote #5

I am trying to find a way to search through the data structure with a chat trigger, when it finds the row (we will call it szArg[i]) I need both a string an and integer value from the row, I dont really care about where it is in the array/enum/struct I just need a way to tie an integer value to a string, like a weaponid + weaponname in one.
__________________
+|- KARMA Respectively

HLM is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-06-2013 , 02:20   Re: Array "szString" = dInt
Reply With Quote #6

I think it would be better and easier to assign to each string ("m4a1") in your example, an array containing slot, price, anything you need, and all of this via a trie.

Something like this :

PHP Code:
enum mWeaponsDatas {
    
m_iWeaponIndex,
    
m_iWeaponSlot,
    
// etc...
}

new 
Trie:g_tWeaponsData;

public 
plugin_init()
{
    
g_tWeaponsData TrieCreate();

    new 
Datas[mWeaponsDatas];

    
// "m4a1"
    
Datasm_iWeaponIndex ] = CSW_M4A1;
    
Datasm_iWeaponSlot ] = 1
    
// etc..;

    
TrieSetArray(g_tWeaponsData"m4a1"Datas);

So in the chat all you have to do is send TrieGetArray() and if that natives returns 1 it means the weapon exists and your array has just been filled with weapon info.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 10-06-2013 at 02:21.
ConnorMcLeod is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 10-06-2013 , 14:01   Re: Array "szString" = dInt
Reply With Quote #7

Okay, this is exactly what I need, however instead of manually creating my 'viewable' list of weapon hooks (what the clients have to say to 'buy' the weapons) is there any way I can make a loop to get all of they trie keys? if not, my alternative would be to make a constant multi-dimension array that contains the weapon names.

I will be using this when triegetarray returns 0 to create a motd window that shows the list of proper chat triggers.
Can I add a string as one of the datas in the trie?
__________________
+|- KARMA Respectively


Last edited by HLM; 10-07-2013 at 15:01.
HLM 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 20:56.


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