Games

Write a script to change skin of the player (a mini SkinSelector) for GTA San Andreas

Much time has passed since writing my first article for a quick start in the programming under the library CLEO4. For some of you it was useful, others not so much, but if you want to learn is not a simple matter and don't know where to start, you should read this article - Write your first CLEO script, it will give you a first idea about scripting and working with the program Sanny Builder.
This article is intended for those who are a little versed in the build scripts, and it's probably something I tried to write. And so, down to business!

For starters, let's see what will our script, list the points:
1) Should be able to change the skin
2) Should be able to return the skin Charles by default.
3) Save the settings, the current skin
4) When you start the game to load the type of the skin from the settings


In this example, I broke the whole script code into 3 functions - load at startup, scan the keyboard and change the skin, everything in order:

In the beginning of the script declare a variable (let's call it a Flag) which will tell us what is currently installed skin, if set to 1, it is the default skin of Karl otherwise any ID skins(I chose Army or 287), then just go to the upload function, that's the way it looks in the code:

{$CLEO .cs}
2@ = 1
gosub @Load


Download when you start the game(Load):
Here we will use the opcode to read the numbers in the INI format file.
But first, a little about the format of ini files is a convenient way to store settings for programs, it can store numbers, text, floating point numbers, and more.
A simple INI file consists of sections, whose name is specified in square brackets,
in sections can be keys each of which has its own value, the values separated by the sign =. In one ini file can be located several sections.
For example:


[секция1]
key1 = value
Key2 = value
[секция2]
key1 = value
Key2 = value


The format figured out now, consider the function Load.
Here we must first check for the existence of our ini file, this is done with the following opcode: 0AAB: file_exists "cleo\skin.ini"if file exists, read the value which is stored in our file into a variable 2@, then move on to changing the skin and then pass control to scan the keyboard.
Here's the code:

:Load
wait 0
if 0AAB: file_exists "cleo\\skin.ini"
then
0AF0: 2@ = get_int_from_ini_file "cleo\\skin.ini" section "settings" key "skin"
gosub @SkinChange
end
jump @Scan


Skin change! Here you are at last! Look code:

:SkinChange
wait 0
if statement and // check if
player.Defined(0) // player created and
not actor.Dead($PLAYER_ACTOR) // not dead
jf @SkinChange
// change skin
if 2@ == 1 // if flag is 1 then
then // return the skin of CJ-I
09C7: change_player $PLAYER_CHAR model_to 0
0AF1: write_int 2@ to_ini_file "cleo\\skin.ini" section "settings" key "skin" // save the setting
2@ = #ARMY // toggle the flag
else
// if the flag is not equal to 1 then
Model.Load(2@) // downloadable models of our skin
038B: load_requested_models // always use this function after loading the models
if Model.Available(2@) // if our model is available that
then
09C7: change_player $PLAYER_CHAR model_to 2@ // change skin
Model.Destroy(2@) // free the memory
0AF1: write_int 2@ to_ini_file "cleo\\skin.ini" section "settings" key "skin" // save the settings
2@ = 1 // toggle the flag
end
end
return // back to where the function was called

The view function looks scary will notice you, but believe me, it only seems <!--smile:smile-->smile<!--/smile--> here I specifically commented every line of code that would make it easier to navigate. In a nutshell: Check whether all is fine with the player, if Yes then check the flag. If our flag is equal to 1 then return true form of Charles, or in my case perevoploschat in the army. Save the settings and toggle a flag indicating which one to load next time when you click.
Replaceable skins opcode - 09C7: change_player $PLAYER_CHAR model_to 0, where 0 is the ID of the skin. But before use, be sure the downloadable model and check the availability.

Scan the keyboard:
It's pretty simple, when you press P(English) or S(Rus.) go to the function change of the skin:

:Scan
wait 0
if
0AB0: key_pressed 0x50
jf @Scan
gosub @SkinChange
wait 100
jump @Scan


That's all left to see the full script code and compile:


{$CLEO .cs}
2@ = 1
gosub @Load

:Load
wait 0
if 0AAB: file_exists "cleo\\skin.ini"
then
0AF0: 2@ = get_int_from_ini_file "cleo\\skin.ini" section "settings" key "skin"
gosub @SkinChange
end
jump @Scan
:SkinChange
wait 0
if and
player.Defined(0)
not actor.Dead($PLAYER_ACTOR)
jf @SkinChange
if 2@ == 1
then
09C7: change_player $PLAYER_CHAR model_to 0
0AF1: write_int 2@ to_ini_file "cleo\\skin.ini" section "settings" key "skin"
2@ = #ARMY
else
Model.Load(2@)
038B: load_requested_models
if Model.Available(2@)
then
09C7: change_player $PLAYER_CHAR model_to 2@
Model.Destroy(2@)
0AF1: write_int 2@ to_ini_file "cleo\\skin.ini" section "settings" key "skin"
2@ = 1
end
end
return
:Scan
wait 0
if
0AB0: key_pressed 0x50
jf @Scan
gosub @SkinChange
wait 100
jump @Scan


Ini file you do not need to create, he created the first press of the P key, and the trigger for writing a value to an ini.
You also want to wish you good luck in scripting, comment, ask questions if anything is unclear and suggest ideas for future articles. Download the finished script here - link

To copy material should provide a link to Gamemodding.net!
0
18
Like:  18
smalloff
smalloff

Published on 3 April 2014

To favorites
Share
Share:
Information
There are no comments yet. Your comment will be first.
Information
You must be registered to leave a comment on this publication.

Site rules и privacy policy

© 2012-2024 GameModding.com All rights reserved.