CLEO Help Help Please!

CLEO related
Status
Not open for further replies.

Alexsan

Member
Joined
Aug 12, 2016
Messages
7
Reaction score
0
A few file of me in txt file  , every sec it will write list enemy [ sever TDM , write by CLEO ] and add messenger to samp , but it write everytime and write old again . I want it add messenger what have in txt fristtime and do not add messenger old if have new then add...







Code:
while true
wait 0
if 
0@ == true
then
0A9A: 0@ = openfile "CLEO/enemytxt" mode "rt" // IF and SET
0AC8: 1@ = allocate_memory_size 260
0AD7: read_string_from_file 0@ to 1@ size 260 // IF and SET
    chatmsg "{FFFF00}%s " -1 1@
    2@ = true
             end
    if 
    2@ == true 
    then
    free 1@ 
    0A9B: closefile 0@
    0B00: delete_file "CLEO/enemy.txt"  // IF and SET
    wait 500  
0A9A: 6@ = openfile "CLEO/enemy.txt" mode "rt" // IF and SET
0AC8: 7@ = allocate_memory_size 260
0AD7: read_string_from_file 6@ to 7@ size 260 // IF and SET
0A9A: 8@ = openfile "CLEO/enemy.txt" mode "rt" // IF and SET
0AC8: 9@ = allocate_memory_size 260
0AD7: read_string_from_file 8@ to 9@ size 260 // IF and SET
if 
0C21: stricmp string1 7@ string2 9@
then
free 7@
free 9@ 
0A9B: closefile 6@
0A9B: closefile 8@
0B00: delete_file "CLEO/enemy.txt"  // IF and SET
2@ = true
else 
0@ = true
end
end
end
 

Alexsan

Member
Joined
Aug 12, 2016
Messages
7
Reaction score
0
0x32789 said:
Be more clear maybe?

I have file txt and in txt have messenger "Alexsan is you enemy kill him" fristtime login game i want it add messenger "chatmsg : Alexan is you enemy" once [my code will spam], and one minute later , file txt will have new enemy i want compare it same " Alexsan is you enemy" do not add messenger if not Alexsan then add messenger

p/s: [font=arial, sans-serif][font=arial, sans-serif]I tried a lot of different ways but it was beyond my ability[/font]

[/font]
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
hi, I just tested it and it worked, if "cleo/enemy.txt" file changes then the contents of it are displayed, (each check is made every 700ms)

[shcode=cpp]{$CLEO .cs}
0000:
 
 
repeat
wait 50
until 0AFA:  SAMP_IS_READY

alloc 30@ 1000 // string from the new file
alloc 31@ 1000 // string from the last file

0@ = true

while true
wait 0
    if 0@ == true
    //if key_down 49
    then
    call @GetStringFromFile 2 stringPointer 30@ debug false // the string from file will be written to the memory at address 0@ (so there's no need for return)
        if 0C21: stricmp string1 30@ string2 31@
        then
        //do nothing if the same string was found
        else
        chatmsg "{FFFF00}%s" -1 30@
        0C13: strcpy destination 31@ source 30@ // copy string if the new one is found so it will be compared later
        end
    wait 700
    end
end

:GetStringFromFile
alloc 29@ 1000
0A9A: 31@ = openfile "CLEO/enemy.txt" mode "rb" // IF and SET
0A9C: 30@ = file 31@ size
0C11: memset destination 0@ value 0 size 1000
    while 0AD7: read_string_from_file 31@ to 29@ size 30@ // it reads a single line from the file and returns false if the end of file was reached
    wait 0
    
    
    /*
    this "while" loop could be replaced with for example: "for 20@ = 0 to MAX_LINES" loop for each line in the file,
    then simple line checks could be used like:
    
    if 20@ == 0
    then
    //29@ = first line
    end
    
    if 20@ == 1
    then
    29@ = second line
    end
    
    etc.
    */     
    
                                                
    0C15: strcat destination 0@ source 29@ // append single line (29@) to the main string (0@) which will include all the text within the file
    0C11: memset destination 29@ value 0 size 1000  // clear the line before reading the next one (just in case if 0AD7 isn't doing it automatically)
    end
//0A9D: readfile 31@ size 30@ to 0@ //(maybe it doesn't work with pointers - "If the number of delivered bytes is more than four, the remainder will be written to the next variable (2@ in this case), and so on.")
0A9B: closefile 31@
    if 1@ == true
    then
    chatmsg "File contains: {FFFF00}%s" -1 0@
    end

free 29@
ret 0[/shcode]
tested with cleo 4.1, samp 0.3.7 and sampfuncs 5.3.1
 
Status
Not open for further replies.
Top