AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem precaching + reading file. (https://forums.alliedmods.net/showthread.php?t=49886)

hlstriker 01-14-2007 22:55

Problem precaching + reading file.
 
Hi, I am trying to have my plugin read a sound filename from a file, then precache that sound.

Here is the code:
Code:
new saveFile[128]; new configsDir[128]; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);     get_configsdir(configsDir, 127);     format(saveFile, 127, "%s/mpn.ini", configsDir); } public plugin_precache() {     new file = fopen(saveFile, "r");     new data[256];         if(file) {         while(!feof(file)) {             fgets(file, data, 255); // Get the current line                         // Break the line into 2 parts, get the 2nd part and rem quotes             new left[128], right[128];             strbreak(data, left, 127, right, 127);             remove_quotes(right);                         new output[128];             if(containi(right, ".wav") > -1) {                 // Precache wav file                 format(output, 127, "themes/%s", right);                 precache_sound(output);             } else if(containi(right, ".mp3") > -1) {                 // Precache mp3 file                 format(output, 127, "sound/themes/%s", right);                 precache_generic(output);             }         }     }     fclose(file); }

Here is the file it's reading from (note the steam ids are for other parts of the plugin):
Quote:

"STEAM_x:x:xxxxxxx" "testwav.wav"
"STEAM_x:x:xxxxx" "testmp3.mp3"

teame06 01-14-2007 23:51

Re: Problem precaching + reading file.
 
Move this to the first line of plugin_precache.

Code:
    get_configsdir(configsDir, 127);     format(saveFile, 127, "%s/mpn.ini", configsDir);


The reason why is because plugin_precache is called before plugin_init.

hlstriker 01-14-2007 23:57

Re: Problem precaching + reading file.
 
Thanks, can you also tell me if there is something wrong with this code below? I think it is crashing my server...

Code:
public client_connect(id) {     // Check to see the clients connection status     new connectCheckNum = 0;     while(connectCheckNum == 0) {         if(is_user_connecting(id) == 1) {             // Do nothing         } else if(is_user_connected(id) == 1) {             connectCheckNum = 1;         } else {             return PLUGIN_HANDLED;         }     }         client_print(0, print_chat, "A player just connected fully...");     // Do more below... }

teame06 01-15-2007 00:02

Re: Problem precaching + reading file.
 
Inifinite loop.


Code:
new connectCheckNum = 0;     while(connectCheckNum == 0) {

connectCheckNum will always = 0. So it will always execute.

hlstriker 01-15-2007 00:03

Re: Problem precaching + reading file.
 
Once the player connects fully though it sets to 1 though, right?

Code:
        } else if(is_user_connected(id) == 1) {             connectCheckNum = 1;

How can I fix this?

teame06 01-15-2007 00:06

Re: Problem precaching + reading file.
 
You should use client_putinserver. It the same as what you are doing.

edit:

Also i'm not sure why you are trying to detect when they are fully joined the server but client_putinserver forward is what you need if you are trying to do that. When client_putinserver is execute they are about to initializing screen I believe.

hlstriker 01-15-2007 00:10

Re: Problem precaching + reading file.
 
EDIT:
Alright it's all fixed except now even if the user has the file being precached it will try and make them download it anyway. Then it doesn't get past downloading and verifying resources when connecting to the server.

Can anyone help with this?


All times are GMT -4. The time now is 22:29.

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