CLEO Help Help with 0AAB

CLEO related
Status
Not open for further replies.

Izumi

New member
Joined
Aug 1, 2014
Messages
2
Reaction score
0
So i am trying to improve this script because the original one cannot read mods if there are spaces in the name.

The problem is with the opcode 0AAB:   file_exists "cleo.asi"
I need to check if the file i entered exists because if i enter an invalid file the game will crash, but i can't make this opcode work to read the input file name.
i tried 0AAB:   file_exists "cleo/%s" but it doesn't work. And if i don't apply this opcode as condition it also doesn't work, so the only work around i found was to check if "cleo.asi" exists then it loads the scripts with spaces in the name successfully. The problem, as i said, is that if i type an invalid file name the game will crash. Any solutions?
Code:
{$CLEO}

0000: NOP
wait 100
0B34: samp register_client_command "cleo" to_label @LOAD

:LOOP
wait 0
goto @LOOP

:LOAD
wait 0
SAMP.IsCommandTyped(2@)
jf @NotExists
0B35: samp 2@ = get_last_command_params
if
0AAB:   file_exists "cleo.asi"
jf @NotExists
0A92: create_custom_thread 2@
0AF8: samp add_message_to_chat "{FF0000}Cleo mod '%s' has been loaded" color -1 2@
SAMP.CmdRet()

:NotExists
wait 0
0AF8: samp add_message_to_chat "{FF0000}The cleo mod name you entered is not valid" color -1
0AF8: samp add_message_to_chat "{BFBFBF}Usage: /cleo <File Name.cs>" color -1
SAMP.CmdRet()
[font=Monaco, Consolas, Courier, monospace]Edit: [/font]
[font=Monaco, Consolas, Courier, monospace]Problem solved, script is now avaliable to download.[/font]
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
if you don't find any better method you could create another command which would have to be typed 2 times. Let's say you have a file called "my mod.txt". First you type "/doublenameload my", the script adds +1 to the counter and waits for the second part so you type "/doublenameload mod.txt" and the script resets the counter + uses the following opcodes to connect the name
0C15: strcat destination 3@ source " " //add the space first
0C15: strcat destination 3@ source 4@ //add the second part

or make wooden solution like:
1. While typing the command use some kind of special character instead of space (character that is almost never used in file names like  £ or !)
2. Get length of the string and check each character to see if it's your special one
3. If it's your special one change it with space by writting 32 at the location of that character
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
272
Just format the script name.

[shcode=cpp]
:LOAD
SAMP.IsCommandTyped(0@)
0C17: 1@ = strlen 0@
if 1@ > 0
then
alloc 2@ = 260
format 2@ "CLEO\%s.cs" 0@
if 0AAB: file_exists 2@
then
format 2@ "%s.cs" 0@
0A92: create_custom_thread 2@
0AF8: "{FF0000}Cleo mod '%s' has been loaded" color -1 2@
else
0AF8: "{FF0000}The cleo mod name you entered is not valid" color -1
0AF8: "{BFBFBF}Usage: /cleo <File Name.cs>" color -1
end
free 2@
end
SAMP.CmdRet()
[/shcode]
 

Izumi

New member
Joined
Aug 1, 2014
Messages
2
Reaction score
0
springfield said:
Just format the script name.

Thanks springfield, it works like a charm.

I'll leave the final version of the script here if anyone is interested. This simply loads/reloads any script you have on your cleo folder.
Syntax: /cleo <File Name>

Code:
{$CLEO}

0000: NOP
wait 100
0B34: samp register_client_command "cleo" to_label @LOAD

:LOOP
wait 0
goto @LOOP

:LOAD
SAMP.IsCommandTyped(0@)
0C17: 1@ = strlen 0@
if 1@ > 0
then
    alloc 2@ = 260
    format 2@ "CLEO\%s.cs" 0@
    if 0AAB:   file_exists 2@
    then 
        format 2@ "%s.cs" 0@  
        0ABA: end_custom_thread_named 2@
        0A92: create_custom_thread 2@
        0AF8: "{FF0000}Cleo mod '%s' has been loaded" color -1 2@
    else
        0AF8: "{FF0000}The cleo mod name you entered is not valid" color -1
    end
    free 2@
else
0AF8: "{FF0000}Usage: /cleo <File Name>" color -1
end
SAMP.CmdRet()
 

Attachments

  • Cleo Loader.cs
    18.1 KB · Views: 17
Status
Not open for further replies.
Top