Writing String To Dialog From Game

Status
Not open for further replies.

KamikazeSripterul

Well-known member
Joined
Jun 30, 2019
Messages
353
Reaction score
23
So I've thought of this idea of writing a specific message from the game. What i need exactly is the dialog box with the list of strings added throughout the game. The proccess is:
> Type command [/list] (example) > Show the empty dialog with 2 buttons ADD and CLOSE
> When press CLOSE, close the dialog
> When presss ADD, another dialog should appear asking for player's name you wish to add ( i guess you get the player's id then their name ) > After you enter their name, another dialog should appear asking for the current date as the following format : 24/12/2019 ( or the program could automatically put the date ) [The dialog's buttons should be CONTINUE and BACK] > Once the date and the player's name has been entered, go back to the main dialog > If i press on a existent string added to the dialog, it should make a dialog (style 0) showing the name and the date added giving the option of BACK or REMOVE > REMOVE should remove the player's name from the main dialog https://imgur.com/a/VjZihFl

Is it a bit too hard? :'(

- The only part I am struggling with is placing the player's name in the main dialog and removing it. Can anyone help or give any advices with this piece of code?

@Parazitas
@monday
@springfield
 
Last edited:

Ravenous

Active member
Joined
Jan 21, 2016
Messages
61
Reaction score
4
Nu e greu dar de ce vrei sa faci treaba asta? Nu e mai usor sa iei o foaie de hartie si sa scii datele astea?
 

KamikazeSripterul

Well-known member
Joined
Jun 30, 2019
Messages
353
Reaction score
23
Nu e greu dar de ce vrei sa faci treaba asta? Nu e mai usor sa iei o foaie de hartie si sa scii datele astea?
E mai usor dar eu vreau sa invat mai multe… Stiu ca tii se pare o prostie sa invat pt nimic.. totusi e samp si nu ajuta cu nimic, dar eu vreau sa invat cat se poate de mult + ca mi se pare o idee destul de buna. Ma poti ajuta?
 

Ravenous

Active member
Joined
Jan 21, 2016
Messages
61
Reaction score
4
All i can give you is this, commands are /list to show the list and /additem <text> to add to the list, the items get saved to a file inside your cleo folder and you can seee them even after you close the game

Code:
{$CLEO}
{$INCLUDE SF}

const
EVENT_BUTTON_CLICKED                = 257
EVENT_COMBOBOX_SELECTION_CHANGED    = 513
EVENT_RADIOBUTTON_CHANGED           = 769
EVENT_CHECKBOX_CHANGED              = 1025
EVENT_SLIDER_VALUE_CHANGED          = 1281
EVENT_EDITBOX_STRING                = 1537
EVENT_EDITBOX_CHANGE                = 1538
EVENT_LISTBOX_ITEM_DBLCLK           = 1793
EVENT_LISTBOX_SELECTION             = 1794
end
0000:
repeat
wait 0
until samp.Available()
chatmsg "{FFF08B}[FailList] {FFFFFF}by {5AD9F9}gumball3000 {FFFFFF}has loaded!" -1
chatmsg "{FFF08B}Use /flist to show the list of fails." -1
0B34: samp register_client_command "list" to_label @show
0B34: samp register_client_command "additem" to_label @additem
6@ = 0
0B80: dialog 0@ = create "Useless list"
0B84: dialog 0@ set_pos_XY 50 220 size 1000 360
0B82: dialog 0@ add_button id 4 text "CLOSE" pos_XY 900 300 size 100 40
0B99: dialog 0@ add_listbox id 3 pos_XY 0 0 size  1000 300
dialog.SetVisible(0@, 0)

IF
0AAB:   file_exists "CLEO\test.list"
THEN
0A9A: 31@ = openfile "CLEO\test.list" mode "rb"
    repeat
    wait 0
    alloc 9@ 256
    0C11: memset destination 9@ value 0 size 256
    0AD7: read_string_from_file 31@ to 9@ size 256
    0C17: 18@ = strlen 9@
        if
        18@ > 0
        then
        0B9A: dialog 0@ listbox 3 insert_element 9@ with_data 1 after 0
        end
    free 9@
    UNTIL 0AD6:   end_of_file 31@ reached
    0A9B: closefile 31@ 
END

while true
wait 0
    if
    dialog.IsVisible(0@)
    then
    SAMP.ToggleCursor(1)
    end
    
    if
    0B81: dialog 0@ pop_event_to 1@ control_id_to 2@
    then
        if 1@ == EVENT_BUTTON_CLICKED
        then
            if 2@ == 4
            then
            0B86: dialog 0@ set_visible false
            SAMP.ToggleCursor(0)
            6@ = 0
            end
        end
    end
end

:show
0B12: 6@ = 6@ XOR 1
if 6@ == 0
then
6@ = 1
end
IF
6@ == 1
THEN
dialog.SetVisible(0@, 6@)
END
samp.CmdRet()

:additem
SAMP.IsCommandTyped(20@)
0C17: 18@ = strlen 20@
if
18@ > 0
then
0B9A: dialog 0@ listbox 3 insert_element 20@ with_data 1 after 0
0A9A: 31@ = openfile "CLEO\test.list" mode "a+"
0AD9: write_formatted_text "%s%c" in_file 31@ 20@ 10
0A9B: closefile 31@
end
samp.CmdRet()
 

KamikazeSripterul

Well-known member
Joined
Jun 30, 2019
Messages
353
Reaction score
23
Okay so this is what I did.
Code:
{$CLEO}
{$INCLUDE SF}

const
EVENT_BUTTON_CLICKED                = 257
EVENT_COMBOBOX_SELECTION_CHANGED    = 513
EVENT_RADIOBUTTON_CHANGED           = 769
EVENT_CHECKBOX_CHANGED              = 1025
EVENT_SLIDER_VALUE_CHANGED          = 1281
EVENT_EDITBOX_STRING                = 1537
EVENT_EDITBOX_CHANGE                = 1538
EVENT_LISTBOX_ITEM_DBLCLK           = 1793
EVENT_LISTBOX_SELECTION             = 1794
end
0000:
repeat
wait 0
until samp.Available()
chatmsg "{FFF08B}[FailList] {FFFFFF}by {5AD9F9}gumball3000 {FFFFFF}has loaded!" -1
chatmsg "{FFF08B}Use /flist to show the list of fails." -1
0B34: samp register_client_command "list" to_label @show
0B34: samp register_client_command "additem" to_label @additem
6@ = 0
0B80: dialog 0@ = create ">> {00ffff}POLICE"
0B84: dialog 0@ set_pos_XY 500 200 size 500 365
0B82: dialog 0@ add_button id 4 text "CLOSE" pos_XY 400 305 size 90 40
0B82: dialog 0@ add_button id 8 text "REMOVE" pos_XY 300 305 size 90 40
0B99: dialog 0@ add_listbox id 3 pos_XY 0 0 size  500 300
dialog.SetVisible(0@, 0)

IF
0AAB:   file_exists "CLEO\test.list"
THEN
0A9A: 31@ = openfile "CLEO\test.list" mode "rb"
    repeat
    wait 0
    alloc 9@ 256
    0C11: memset destination 9@ value 0 size 256
    0AD7: read_string_from_file 31@ to 9@ size 256
    0C17: 18@ = strlen 9@
        if
        18@ > 0
        then
        0B9A: dialog 0@ listbox 3 insert_element 9@ with_data 1 after 0
        end
    free 9@
    UNTIL 0AD6:   end_of_file 31@ reached
    0A9B: closefile 31@
END

while true
wait 0
    if
    dialog.IsVisible(0@)
    then
    SAMP.ToggleCursor(1)
    end
    
    if
    0B81: dialog 0@ pop_event_to 1@ control_id_to 2@
    then
        if 1@ == EVENT_BUTTON_CLICKED
        then
            if 2@ == 4
            then
            0B86: dialog 0@ set_visible false
            SAMP.ToggleCursor(0)
            6@ = 0
            end
            
            if 2@ == 8
            then
                0B9B: dialog 0@ listbox 3 selected_element_to 3@ elements_count_to 4@
                0B9C: dialog 0@ listbox 3 delete_element 3@
            end
        end
    end
end

:show
0B12: 6@ = 6@ XOR 1
if 6@ == 0
then
6@ = 1
end
IF
6@ == 1
THEN
dialog.SetVisible(0@, 6@)
END
samp.CmdRet()

:additem
SAMP.IsCommandTyped(20@)
0C17: 18@ = strlen 20@
if
18@ > 0
then
0B9A: dialog 0@ listbox 3 insert_element 20@ with_data 1 after 0
0A9A: 31@ = openfile "CLEO\test.list" mode "a+"
0AD9: write_formatted_text "%s%c" in_file 31@ 20@ 10
0A9B: closefile 31@
end
samp.CmdRet()

I basically added another button that successfully removes a selected item from the list and changed the size of the box. Now what I need help with is in the command /additem I need to scan the string for the format of %d %s. As example, the command could look like /additem 25 need to arrest him. 25 is the id of the player so I need the NAME not the id to be added to the listbox along with the 'need to arrest him'. But my question is, what is the meaning behind '0AD9: write_formatted_text "%s%c" in_file 31@ 20@ 10' if you could help me with that, please.
 

Ravenous

Active member
Joined
Jan 21, 2016
Messages
61
Reaction score
4
31@ is the file, 20@ is the string you want to write, and 10 is the ascii code for the new line character.

to get player nickname you can do something like this maybe
11@ is the player nickname and 22@ is the other string
SAMP.IsCommandTyped(20@)
if
0AD4: 20@ = scan_string 20@ format "%d %s" 21@ 22@
then
0B36: samp 11@ = get_player_nickname 21@
end
 

KamikazeSripterul

Well-known member
Joined
Jun 30, 2019
Messages
353
Reaction score
23
Code:
:additem
SAMP.IsCommandTyped(20@)
0C17: 18@ = strlen 20@
if
18@ > 0
then
    if
    0AD4: 20@ = scan_string 20@ format "%d %s" 21@ 22@
    then
    0B36: samp 11@ = get_player_nickname 21@
end
0B9A: dialog 0@ listbox 3 insert_element 20@ with_data 1 after 0
0A9A: 31@ = openfile "CLEO\test.list" mode "a+"
0AD9: write_formatted_text "%s%s%c" in_file 31@ 11@ 22@ 10
0A9B: closefile 31@
end
samp.CmdRet()

This gives me a lot of crashes when I type the command and I am 80% sure it is from this line
>> 0AD9: write_formatted_text "%s%s%c" in_file 31@ 11@ 22@ 10 I'm not sure what the %c stands for
 
Status
Not open for further replies.
Top