Raised This Month: $ Target: $400
 0% 

diffrent origins from a file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dr.G
Senior Member
Join Date: Nov 2008
Old 02-21-2009 , 09:23   diffrent origins from a file
Reply With Quote #1

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
__________________
Dr.G is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 02-21-2009 , 09:35   Re: diffrent origins from a file
Reply With Quote #2

http://forums.alliedmods.net/showthread.php?t=46218
With FM pev_origin
SnoW is offline
Send a message via MSN to SnoW
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-21-2009 , 09:47   Re: diffrent origins from a file
Reply With Quote #3

Quote:
Originally Posted by Dr.G View Post
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).
__________________
Bugsy is offline
Dr.G
Senior Member
Join Date: Nov 2008
Old 02-21-2009 , 10:47   Re: diffrent origins from a file
Reply With Quote #4

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?
__________________
Dr.G is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-21-2009 , 18:16   Re: diffrent origins from a file
Reply With Quote #5

Quote:
Originally Posted by Dr.G View Post
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.
        
    

__________________

Last edited by Bugsy; 02-21-2009 at 18:32.
Bugsy is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-21-2009 , 18:22   Re: diffrent origins from a file
Reply With Quote #6

Don't use read_file, use "new" file natives.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-21-2009 , 18:35   Re: diffrent origins from a file
Reply With Quote #7

fopen, fgets, feof, etc..
Arkshine is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 02-21-2009 , 18:54   Re: diffrent origins from a file
Reply With Quote #8

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) }
__________________
stupok is offline
Dr.G
Senior Member
Join Date: Nov 2008
Old 02-21-2009 , 21:39   Re: diffrent origins from a file
Reply With Quote #9

thanks!
__________________
Dr.G is offline
Reply



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 16:55.


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