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

Solved ArrayPushArray problems


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 06-21-2020 , 07:37   ArrayPushArray problems
Reply With Quote #1

Hello,
I tried to make a VIP Plugin with a vips.ini file for reading vips.
But when I introduce the data in file, it not shows me exactly what I wanna get from that array.

Code:
Code:
public CheckVIP() {     new path[64];     get_localinfo("amxx_configsdir", path, charsmax(path));     format(path, charsmax(path), "%s/vips.ini", path);         new file = fopen(path, "r+");         if(!file_exists(path))     {         write_file(path, ";VIPs.ini file");     }         if(vips_number)     {         ArrayClear(vip_array);         vips_number = 0;     }         new text[121], p_name[32], expir_date[32], vip_infos[vip_data];     while(!feof(file))     {         fgets(file, text, charsmax(text));         trim(text);                 if(text[0] == ';' || !strlen(text))         {             continue;         }                 if(parse(text, p_name, charsmax(p_name), expir_date, charsmax(expir_date)) != 2)         {             log_to_file(LOGFILE, "[AMXX] Can't (%s). Este scrisa gresit.", text);             continue;         }                 copy(vip_infos[user_name], charsmax(vip_infos), p_name);         copy(vip_infos[expire_date], charsmax(vip_infos), expir_date);
        ArrayPushArray(vip_array, vip_infos);
        vips_number++;     }         fclose(file); }

putinserver client phase:

Code:
public client_putinserver(id) { new p_name[32];     get_user_info(id, "name", p_name, charsmax(p_name));     is_user_vip[id] = false;     new vip_infos[vip_data], i;         for(i = 0; i < ArraySize(vip_array); i++)     {         ArrayGetArray(vip_array, i, vip_infos);         if(equal(vip_infos[user_name], p_name))         {             is_user_vip[id] = true;             set_task(10.0, "Task_ShowExpire")         }         break;     } }

Show Expire Task:
Code:
public Task_ShowExpire(id) {     new vip_infos[vip_data]     for(new i = 0; i < ArraySize(vip_array); i++)     {         ArrayGetArray(vip_array, i, vip_infos);     }     color_chat(id, "!y[!gV.I.P!y] Your !gVIP Status !yExpire on: !g%s", vip_infos[expire_date]) }

vips.ini file:
Code:
"Adi" "Permanent VIP" "Test" "30.06.2020"
In the public Task_ShowExpire it prints me the value from the last Array from the file. Example:
Adi is joining the server. Adi has VIP and server prints his vip's expire is on "30.06.2020" instead to print "Permanent VIP"
Test is joining the server. Test has not VIP, but he is written in the file.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 06-21-2020 at 12:02.
Shadows Adi is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-21-2020 , 07:45   Re: ArrayPushArray problems
Reply With Quote #2

This is a clasic example where you should use a trie, not a dyn array.
__________________
HamletEagle is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 06-21-2020 , 09:18   Re: ArrayPushArray problems
Reply With Quote #3

I don't want to use a trie, I want to use an dynamic array to parse the entire line as here:
Code:
"Adi" "Permanent VIP" "Test" "30.06.2020"
I read about tries and I didn't found something saying that a trie can do this. If I am wrong, explain me.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 06-21-2020 , 09:35   Re: ArrayPushArray problems
Reply With Quote #4

If you don't need to loop through all entries in the list, you should use a trie. It works like this:

"key" = "value"

In your case "key" is the player's name and "value" is the expiration date, so no array is needed.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Old 06-21-2020, 09:53
HamletEagle
This message has been deleted by HamletEagle.
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 06-21-2020 , 11:37   Re: ArrayPushArray problems
Reply With Quote #5

Solved using trie way
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Reply


Thread Tools
Display Modes

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 07:11.


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