AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved ArrayPushArray problems (https://forums.alliedmods.net/showthread.php?t=325418)

Shadows Adi 06-21-2020 07:37

ArrayPushArray problems
 
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.

HamletEagle 06-21-2020 07:45

Re: ArrayPushArray problems
 
This is a clasic example where you should use a trie, not a dyn array.

Shadows Adi 06-21-2020 09:18

Re: ArrayPushArray problems
 
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.

OciXCrom 06-21-2020 09:35

Re: ArrayPushArray problems
 
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.

Shadows Adi 06-21-2020 11:37

Re: ArrayPushArray problems
 
Solved using trie way :)


All times are GMT -4. The time now is 08:21.

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