Raised This Month: $ Target: $400
 0% 

Writing/Reading floats from a txt-file....


Post New Thread Reply   
 
Thread Tools Display Modes
Harmlos12
Junior Member
Join Date: Oct 2019
Old 10-09-2019 , 15:17   Re: Writing/Reading floats from a txt-file....
Reply With Quote #11

So somehow I got it working with a timer:

PHP Code:
bool ReadDataFile()
{
    
float vecs[3];    
    
    
Handle kvNew CreateKeyValues("Locations");    
    
BuildPath(Path_SMszDataFilesizeof(szDataFile), "data/sm_vec/sm_vec_%s.nav"g_szMapName);
    
    
FileToKeyValues(kvNewszDataFile);

    
ArrayList path = new ArrayList(3); // create a dynamic list, hold enough space for a float[3]
    
    
for (int i 1<= 12i++)
    {
        
// read the vector from your config file...
        
Format(Positionsizeof(Position), "Position%i"i);
        
KvJumpToKey(kvNewPositiontrue);        
        
KvGetVector(kvNewNULL_STRINGvecs);
        if(
== 12)
        {
    
//        PrintToChatAll("Vector: %f : %f : %f", vecs[0], vecs[1], vecs[2]);
            
Handle h=CreateDataPack();
            
WritePackFloat(hvecs[0]);
            
WritePackFloat(hvecs[1]);
            
WritePackFloat(hvecs[2]);

            
CreateTimer(0.01CheckTurnhTIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
        }        
        
KvRewind(kvNew);

        
        
// push your path coords onto the array
        
path.PushArray(vecs);
    }
    
    
SetConVarInt(g_hVecSetup0);
    
SetConVarInt(g_hVecOn1);
    
    
CloseHandle(kvNew);
    
    
    
// below is mostly copied from CreateAll() the other post, I'm going to assume it works
    
char trackname[32];
    
char prevtrackname[32];
    
    
// iterate backwards from the last path entry to the first and create the tracks
    
for (int i path.Lengthi-- > 0;)
    {
        
path.GetArray(ivecs);
        
        
FormatExtracknamesizeoftrackname ), "_track%i");
        
CreatePathtracknamevecsprevtrackname );
        
strcopyprevtracknamesizeofprevtrackname ), trackname );
    }
    
    
delete path// this closes our ArrayList instance

    // Create func_tracktrain
    
int tracktrain CreateTrackTrain"_train""_track0""200" );
    
    
// Create our "helicopter"
    
int prop CreateTrainProp"_prop" );
    
    
// Parent it to func_tracktrain
    
ParentToEntityproptracktrain );
    
    return 
true;    

and in the timer:
PHP Code:
public Action CheckTurn(Handle timer,any h)
{
    
ResetPack(h);
    
float pos[3];
    
pos[0]=ReadPackFloat(h);
    
pos[1]=ReadPackFloat(h);
    
pos[2]=ReadPackFloat(h);
    
    
    
float vecs[3];
    
int ent = -1;
    while ((
ent FindEntityByClassname(ent"func_tracktrain")) != -1)
    {
        if (
IsValidEntity(ent))
        {
            
GetEntPropVector(entProp_Send"m_vecOrigin"vecs);
    
//        PrintToChatAll("Vector: %f: %f: %f",vecs[0], vecs[1], vecs[2] );
            
float distance;
            
distance GetVectorDistance(posvecs);
            if (
distance 50)
            {            
                
AcceptEntityInput(ent"Reverse");
            }
        }
    }

maybe there is an easier method or better way someone knows here ?
Harmlos12 is offline
Stugger
Member
Join Date: Sep 2007
Old 10-17-2019 , 15:36   Re: Writing/Reading floats from a txt-file....
Reply With Quote #12

Quote:
Originally Posted by Harmlos12 View Post
I´m lost to implement the function of this : https://forums.alliedmods.net/archiv.../t-286275.html

Any help to get this working would be really appreciated, thanks.
I made a plugin based off that exact snippet last month, you can take a look at my code if you want some ideas.

https://forums.alliedmods.net/showthread.php?t=318751
Stugger is offline
Harmlos12
Junior Member
Join Date: Oct 2019
Old 10-18-2019 , 11:38   Re: Writing/Reading floats from a txt-file....
Reply With Quote #13

Thanks, I found another solution by adding a HookSingleEntityOutput(ent, "OnPass", OnEntityOutPut);
in the Create_Path block like nosoop suggested and than do something like this:

PHP Code:
public OnEntityOutPut(const char[] outputcalleractivatorfloat delay)
{    
    
int curCount g_Count[activator];
    
g_Count[activator]++;    
           
     
int ent = -1;
    while ((
ent FindEntityByClassname(ent"func_tracktrain")) != -1)
    {
        if (
IsValidEntity(ent))
        {
            if(
curCount == 10)    
            {                
                
AcceptEntityInput(ent"Reverse");
            }
            if(
curCount == 20)    
            {                
                
AcceptEntityInput(ent"Reverse");
            }
            if(
curCount == 30)    
            {                
                
AcceptEntityInput(ent"Reverse");
            }
            if(
curCount == 40)    
            {                
                
AcceptEntityInput(ent"Reverse");
            }
            if(
curCount == 50)    
            {                
                
AcceptEntityInput(ent"Reverse");
            }            
        }
     }       

Not the best but it works , maybe there is a method to put this into an infinite loop.........
Harmlos12 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 18:55.


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