CLEO Help [LOCK] Get Player from a txt file [LOCK]

CLEO related
Status
Not open for further replies.

Grubitsh

Active member
Joined
Jul 28, 2014
Messages
104
Reaction score
0
Hi,

For one of my CLEO, I need to have a list of player that are already written in a .txt file. I tried this code from a Russian forum, but it only gives me the last name of the text file. (and I don't speak russian !)
Can you help me please ?

Code:
0A9A: 8@ = openfile "CLEO\test.txt" mode "rt" // IF and SET
0AC8: 9@ = allocate_memory_size 260
 
 
 WHILE 8AD6:  end_of_file 8@ reached
 wait 0
   
 0AD7: read_string_from_file 8@ to 9@ size 260 // IF and SET
 0AF8: samp add_message_to_chat "%s" color 0xFF61BB 9@
       for 10@ = 0 to 1000
   
             if
             samp.IsPlayerConnected(10@)
              then
              11@ = samp.GetPlayerNickname(10@)
            
                  if
                  0C14: strcmp string1 9@ string2 11@     
                 then
                 0AF8: samp add_message_to_chat "%s" color 0xFFFFFF 11@
                 // Do things here

end
end
end
end

NOTE: In fact I think the problem is in: "0C14: strcmp string1 9@ string2 11@  " because I can't go trhough that IF
This part
Code:
0AD7: read_string_from_file 8@ to 9@ size 260 // IF and SET
0AF8: samp add_message_to_chat "%s" color 0xFF61BB 9@

works very well it gives me the complete list of the .txt file.

But this part
Code:
 if 0C14: strcmp string1 9@ string2 11@     
then
0AF8: samp add_message_to_chat "%s" color 0xFFFFFF 11@
does not get me anything instead of the LAST NAME in the .TXT file. Maybe because of the double LOOP ?
(and yes the players where conected when I tried it)
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
272
Re: [TO ADMIN CHECKER CREATOR] Get Player from a txt file

Code:
0A9A: 8@ = openfile "CLEO\test.txt" mode "rt" // IF and SET
0AC8: 9@ = allocate_memory_size 260
 
WHILE 8AD6:  end_of_file 8@ reached
WAIT 0
    IF 0AD7: read_string_from_file 8@ to 9@ size 260 // IF and SET
    THEN
        0C17: 10@ = 9@
        dec(10@)
        0AC8: 11@ = 32
        0C11: 11@ 0 32
        0C10: 11@ 9@ 10@
        FOR 12@ = 0 to 1000
            IF 0B23: 12@
            THEN 0B36: 13@ = 12@
                IF 0C14: strcmp s1 11@ s2 13@
                THEN 0AF8: "%s(%d) is in test.txt file" -1 13@ 12@
                END
            END
        END 
        0AC9: 11@
    END
END

It's because 0B36 returns a pointer in memory(not null terminated) when 0AD7 does. Strcmp will return false if one string is longer.

Also your text file should look like this
Code:
name1
name2
name3
name4
..
name50
 

Grubitsh

Active member
Joined
Jul 28, 2014
Messages
104
Reaction score
0
Re: [TO ADMIN CHECKER CREATOR] Get Player from a txt file

You are the man !
THANKS !

Last question.

At the first time I put it at the begining of the code before the main(before the WHILE TRUE LOOP).
Now I would like to put it in the LOOP, to check at all time if this player is conected.
It works but It slows my main loop (I got a  Render.DrawText in it so the  Render.DrawText flash now).
it's due to the wait 0 in the second loop
Code:
    
While true
wait 0
// Do things
WHILE 8AD6:  end_of_file 21@ reached
    wait 0
// Do things
END
// Do things
END
When i put the "wait 0" in comment it works good, but I don't know if it's good for scripting to let the "While end of file" without a "wait 0"
Plus every loop I open/close the txt file. Does it take a lot of memory to do this ?
How can I put the same function into the main loop safer and smarter?
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
272
Re: [TO ADMIN CHECKER CREATOR] Get Player from a txt file

While/repeat loops require a 'wait 0' instruction. You should always read the file once, loop reading is not recommended. Easiest way would be to read once, store all names to an array then in the main loop check all connected players names against those from array. Eventually add some commands to re-read file or write names in the file, in case you want to live update the file/settings etc.

:sadpepe:
 

Grubitsh

Active member
Joined
Jul 28, 2014
Messages
104
Reaction score
0
Re: [TO ADMIN CHECKER CREATOR] Get Player from a txt file

OK I am gonna try this. THX.

Is it the way you did it for you Admin Checker ?
 
Status
Not open for further replies.
Top