AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   diffrent origins from a file (https://forums.alliedmods.net/showthread.php?t=86135)

Dr.G 02-21-2009 09:23

diffrent origins from a file
 
i need a way to pick out an origin from a file, and use it in set_user_origin(id, Origin), so it needs to be a diffrent origin/origin on the next line for every time. how do i do that? and are there a better way then set_user_origin?

cheers

SnoW 02-21-2009 09:35

Re: diffrent origins from a file
 
http://forums.alliedmods.net/showthread.php?t=46218
With FM pev_origin

Bugsy 02-21-2009 09:47

Re: diffrent origins from a file
 
Quote:

Originally Posted by Dr.G (Post 765914)
i need a way to pick out an origin from a file, and use it in set_user_origin(id, Origin), so it needs to be a diffrent origin/origin on the next line for every time. how do i do that? and are there a better way then set_user_origin?

cheers

These functions should take care of what you are trying to do. Use a for-loop to cycle from line 1->file_size.

file_size http://www.amxmodx.org/funcwiki.php?go=func&id=91
read_file http://www.amxmodx.org/funcwiki.php?go=func&id=87

Use fm_set_user_origin(id, fOrigin) to set a players origin and pev(id,pev_origin,fOrigin) to get an origin. new Float:fOrigin[3] is the type needed to get\set origins with fakemeta as it uses floats and not integers like get\set origin does.

Remember that before using the origin read from file, it must be converted to a float array containing the 3 origin coordinates (x,y,z).

Dr.G 02-21-2009 10:47

Re: diffrent origins from a file
 
thanks!

so something like:

PHP Code:

new line 1
 
read_file 
( const file[], line++, text[], len, &txtLen 

to get it to take the next line every time right?

Bugsy 02-21-2009 18:16

Re: diffrent origins from a file
 
Quote:

Originally Posted by Dr.G (Post 765953)
thanks!

so something like:

PHP Code:

new line 1
 
read_file 
( const file[], line++, text[], len, &txtLen 

to get it to take the next line every time right?

This will read each individual line of a text file. Untested

PHP Code:

    new szFile[] = "c:\originfile.txt"
    
new iNumLines file_size szFile);
    new 
iLineLen;
    
    if( 
file_size(szFile,) )
        
iNumLines--;
        
    for( new 
iCurLine 1iCurLine<= iNumLinesiCurLine++)
    {
        new 
szReadBuffer[256];
        
read_file szFileiCurLineszReadBuffer255,iLineLen);
        
//szReadBuffer holds the line of text. You will need to split this up into 3 floats to go into your origin array.
        
    



ConnorMcLeod 02-21-2009 18:22

Re: diffrent origins from a file
 
Don't use read_file, use "new" file natives.

Arkshine 02-21-2009 18:35

Re: diffrent origins from a file
 
fopen, fgets, feof, etc..

stupok 02-21-2009 18:54

Re: diffrent origins from a file
 
Like this:

yourfile.txt:
Code:

0 0 0
185.564 5461.4 1.111
12 16 86.5

Code:
#define FILE "yourfile.txt" public do_stuff() {     // open file in R ead T ext mode, assign handle     new fh = fopen(FILE, "rt")         // failed to open     if(!fh) return         new szBuffer[64]     new szOrigin1[16]     new szOrigin2[16]     new szOrigin3[16]     new Float:fOrigin[3]         // keep going until end of file     while(!feof(fh))     {         // read a line into szBuffer         fgets(fh, szBuffer, charsmax(szBuffer))                 // split szBuffer into 3 parts         parse(szBuffer, szOrigin1, charsmax(szOrigin1), szOrigin2, charsmax(szOrigin2), szOrigin3, charsmax(szOrigin3))                 // convert string to float         fOrigin[0] = str_to_float(szOrigin1)         fOrigin[1] = str_to_float(szOrigin2)         fOrigin[2] = str_to_float(szOrigin3)                 // do something with the origin         // ...     }         // always close if you open     fclose(fh) }

Dr.G 02-21-2009 21:39

Re: diffrent origins from a file
 
thanks!


All times are GMT -4. The time now is 16:55.

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