- Joined
- Feb 18, 2013
- Messages
- 1,123
- Reaction score
- 175
Dynamic Variables
For CLEO 4.1
What is this?:
Dynamic Vars is meant to be a easy expansion for saving data but with an incredible easy interface (variable names).
It allows you todo many powerful things, as it uses variable "names" you can create any kind of combinations for setting & getting data.
Also, it has no limitations on how many variables you can have (only your available ram is your limit ).
Now, is there any example?:
Yes, here's a example that contains some string and a "friend system" with sampfuncs and dynamic vars made by opcode.
Code:
{$CLEO .cs}
0000:
REPEAT
WAIT 0
UNTIL 0AFA: SAMP_IS_READY
0B34: ".ADDFRIEND" @ADDFRIEND
0B34: ".DELFRIEND" @DELFRIEND
0FA5: set_var_as_string name "Credits" value "0x688, Opcode.eXe"
WHILE TRUE
WAIT 0
IF
0AB0: 49 // 1?
THEN
0AC8: 0@ = allocate_memory_size 256
0FA6: 0@ = get_var_as_string name "Credits" //GET
0AD1: show_formatted_text_highpriority "Credits: %s" time 500 0@
0AC9: free_allocated_memory 0@
END
IF
0AB0: 50 // 2?
THEN
0FA9: 1@ = dump_vars to_file "CLEO\\DynVars\\Example.txt"
0AD1: show_formatted_text_highpriority "Dumped %d vars!" time 500 1@
END
IF
0AB0: 51 // 3?
THEN
0FAA: 1@ = load_vars from_file "CLEO\\DynVars\\Example.txt"
0AD1: show_formatted_text_highpriority "Loaded %d vars!" time 500 1@
END
// FriendESP example:
FOR 0@ = 0 TO 1000
IF
0B23: samp is_player_connected 0@
THEN
IF
0B20: samp 1@ = actor_handle_by_samp_player_id 0@
THEN
0B36: samp 2@ = get_player_nickname 0@
0FA4: 3@ = get_var_as_bool 2@//SET
IF
3@ == 1
THEN
04C4: store_coords_to 4@ 5@ 6@ from_actor 1@ with_offset 0.0 0.0 0.0
0B55: convert_3D_coords 4@ 5@ 6@ to_screen 7@ 8@
0B69: render draw_box_pos 7@ 8@ size 50 50 color 0xFFFF0000
END
END
END
END
END
:DELFRIEND
0B35: samp 31@ = get_last_command_params
IF
0AD4: $NO_USE = scan_string 31@ "%d" 30@
THEN
IF
0B23: samp is_player_connected 30@
THEN
0B36: samp 29@ = get_player_nickname 30@
0FA3: set_var_as_bool 29@ value 0 //SET
0AF8: samp add_message_to_chat "{FF0000}[DELFRIEND]{FFFFFF}Player {FF9500}%s{FFFFFF} is no longer your friend!" color 0xFFFFFF 29@
END
ELSE
0AF8: samp add_message_to_chat "Please enter a ID!" color 0xFFFFFF
END
0B43: CMD_RETURN
:ADDFRIEND
0B35: samp 31@ = get_last_command_params
IF
0AD4: $NO_USE = scan_string 31@ "%d" 30@
THEN
IF
0B23: samp is_player_connected 30@
THEN
0B36: samp 29@ = get_player_nickname 30@
0FA3: set_var_as_bool 29@ value 1 //SET
0AF8: samp add_message_to_chat "{FF0000}[ADDFRIEND]{FFFFFF}Player {FF9500}%s{FFFFFF} is now your friend!" color 0xFFFFFF 29@
END
ELSE
0AF8: samp add_message_to_chat "Please enter a ID!" color 0xFFFFFF
END
0B43: CMD_RETURN
Specifications (limits or anything worth to note):
- The current max length for string is fixed at 256 as i saw no need for more, if i'll expand it so it supports and unlimited range of charcters.
- Please, and oh please! Dont use integer's for things you dont need to like only 0/1 values use the bool one to save memory, it get's dynamically allocated.
- Every loaded CLEO Script has it's own pool of variables, I'm planning to allow access to other cleo's pools but as it stands for now it's not necessarry.
Downloads:
As always, you can find them in the attachments.
Try it yourself, cleo scripter's that know what they do also know what todo with this.