Monthly Target: $400 Donations: $23
 5% 

Read models in .txt


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 05-01-2012 , 17:33   Read models in .txt
Reply With Quote #1

I must make my script read information from a. Txt.

example:

A. Txt models.txt was named in a folder and it would be listed SourceMod model by model:

models/player/slow/aliendrone_v3/slow_alien.mdl;oldmodel
models/player/slow/aliendrone_v3/slow_alien_hs.mdl;hs
models/player/slow/aliendrone_v3/slow_alien_head.mdl;head
player.mdl ...; oldmodel
...

oldmodel for default model
hs for headless model
head for head model

And everything was being set up, out instead to be done in the script, as below:

PHP Code:
        if (StrEqual(oldmodel"models/player/slow/aliendrone_v3/slow_alien.mdl"false))
        {
            
bodymodel "models/player/slow/aliendrone_v3/slow_alien_hs.mdl";
            
headmodel "models/player/slow/aliendrone_v3/slow_alien_head.mdl";
        } 
With support for putting more than one model.

How can I do this?

Thanks.
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM

Last edited by rodrigo286; 05-01-2012 at 17:35.
rodrigo286 is offline
TheAvengers2
BANNED
Join Date: Jul 2011
Old 05-01-2012 , 18:37   Re: Read models in .txt
Reply With Quote #2

I would suggest using a KeyValue file, however, if you want to do something custom and write your own parser, then you can do so with these functions. You can then load the data into arrays and iterate through it.

Last edited by TheAvengers2; 05-01-2012 at 18:41.
TheAvengers2 is offline
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 05-01-2012 , 19:23   Re: Read models in .txt
Reply With Quote #3

In the case I only need:

PHP Code:
ReadFileString
buildpath 
To read a text from .txt file that the user will create.

Correct?
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM
rodrigo286 is offline
TheAvengers2
BANNED
Join Date: Jul 2011
Old 05-01-2012 , 20:44   Re: Read models in .txt
Reply With Quote #4

I would suggest using ReadFileLine and looping through. Something like: while(ReadFileLine(hndl, sBuffer, sizeof(sBuffer))) {}

You'll then need to break up the string and figure out which array it goes into.

Last edited by TheAvengers2; 05-01-2012 at 20:48.
TheAvengers2 is offline
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 05-01-2012 , 21:08   Re: Read models in .txt
Reply With Quote #5

You can make this more directed to my plugin?

Still do not understand.

Thanks ^^
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM
rodrigo286 is offline
TheAvengers2
BANNED
Join Date: Jul 2011
Old 05-01-2012 , 21:32   Re: Read models in .txt
Reply With Quote #6

Code:
new String:g_sOldModel[64][128], g_iOldModelPos;
new String:g_sBodyModel[64][128], g_iBodyModelPos;
new String:g_sHeadModel[64][128], g_iHeadModelPos;

public OnPluginStart()

    new Handle:hndl = OpenFile("models.txt", "r");
    decl String:sBuffer[128], String:sBufferArray[2][128];

    while (ReadFileLine(hndl, sBuffer, sizeof(sBuffer)))
    {
        if (ExplodeString(sBuffer, ";", sBufferArray, sizeof(sBufferArray), sizeof(sBufferArray[]))
        {
            if (StrEqual(sBufferArray[1], "oldmodel"))
            {
                strcopy(g_sOldModel[(g_iOldModelPos++)], sizeof(g_sOldModel[]), sBufferArray[0]);
            }
            else if (StrEqual(sBufferArray[1], "hs"))
            {
                strcopy(g_sBodyModel[(g_iBodyModelPos++)], sizeof(g_sBodyModel[]), sBufferArray[0]);
            }
            else if (StrEqual(sBufferArray[1], "oldmodel"))
            {
                strcopy(g_sHeadModel[(g_iHeadModelPos++)], sizeof(g_sHeadModel[]), sBufferArray[0]);
            }
        }
    }

    if (g_iOldModelPos != g_iBodyModelPos || g_iBodyModelPos != g_iHeadModelPos) // a problem?

    CloseHandle(hndl);
}
Code:
for (new i = 1; i <= g_iOldModelPos; i++)
{
    if (StrEqual(oldmodel, g_sOldModel[i], false))
    {
        strcopy(bodymodel, sizeof(bodymodel), g_sBodyModel[i]);
        strcopy(headmodel, sizeof(headmodel), g_sHeadModel[i]);
        // do something?
    }
}
I think this is right... I haven't tested, nor am I familiar with the functions.

Last edited by TheAvengers2; 05-01-2012 at 21:40.
TheAvengers2 is offline
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 05-01-2012 , 21:40   Re: Read models in .txt
Reply With Quote #7

Thanks, I'll test this model.txt should be in the folder addons / SourceMod?

Thanks again.
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM
rodrigo286 is offline
TheAvengers2
BANNED
Join Date: Jul 2011
Old 05-01-2012 , 21:43   Re: Read models in .txt
Reply With Quote #8

I'd recommend using BuildPath to getting it to where you want it. It's currently using /cstrike/models.txt
TheAvengers2 is offline
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 05-02-2012 , 20:58   Re: Read models in .txt
Reply With Quote #9

Change here to Head right?

Before
PHP Code:
            else if (StrEqual(sBufferArray[1], "head"))
            {
                
strcopy(g_sHeadModel[(g_iHeadModelPos++)], sizeof(g_sHeadModel[]), sBufferArray[0]);
            } 
After
PHP Code:
            else if (StrEqual(sBufferArray[1], "head"))
            {
                
strcopy(g_sHeadModel[(g_iHeadModelPos++)], sizeof(g_sHeadModel[]), sBufferArray[0]);
            } 
Standing as below with build patch:

PHP Code:
new String:g_sOldModel[64][128], g_iOldModelPos;
new 
String:g_sBodyModel[64][128], g_iBodyModelPos;
new 
String:g_sHeadModel[64][128], g_iHeadModelPos;

public 
OnPluginStart()

    
    new 
String:configPath[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMconfigPathsizeof(configPath), "configs/models.txt");

    new 
Handle:hndl OpenFile("models.txt""r");
    
decl String:sBuffer[128], String:sBufferArray[2][128];

    while (
ReadFileLine(hndlsBuffersizeof(sBuffer)))
    {
        if (
ExplodeString(sBuffer";"sBufferArraysizeof(sBufferArray), sizeof(sBufferArray[]))
        {
            if (
StrEqual(sBufferArray[1], "oldmodel"))
            {
                
strcopy(g_sOldModel[(g_iOldModelPos++)], sizeof(g_sOldModel[]), sBufferArray[0]);
            }
            else if (
StrEqual(sBufferArray[1], "hs"))
            {
                
strcopy(g_sBodyModel[(g_iBodyModelPos++)], sizeof(g_sBodyModel[]), sBufferArray[0]);
            }
            else if (
StrEqual(sBufferArray[1], "head"))
            {
                
strcopy(g_sHeadModel[(g_iHeadModelPos++)], sizeof(g_sHeadModel[]), sBufferArray[0]);
            }
        }
    }

    
CloseHandle(hndl);

PHP Code:
for (new 1<= g_iOldModelPosi++)
{
    if (
StrEqual(oldmodelg_sOldModel[i], false))
    {
        
strcopy(bodymodelsizeof(bodymodel), g_sBodyModel[i]);
        
strcopy(headmodelsizeof(headmodel), g_sHeadModel[i]);
        
// do something?
    
}

__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM
rodrigo286 is offline
TheAvengers2
BANNED
Join Date: Jul 2011
Old 05-02-2012 , 23:18   Re: Read models in .txt
Reply With Quote #10

yeah, that's right. silly copy & paste always making problems.

edit:
Quote:
Originally Posted by rodrigo286 View Post
public OnPluginStart()
{
new String:configPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, configPath, sizeof(configPath), "configs/models.txt");

new Handle:hndl = OpenFile(configPath, "r");
decl String:sBuffer[128], String:sBufferArray[2][128];
You might want to do that as well. The evil bracket managed to escape somehow.

Last edited by TheAvengers2; 05-02-2012 at 23:32.
TheAvengers2 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 21:22.


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