View previous topic :: View next topic |
Author |
Message |
AsaSK
Mafiascene Veteran Modder


Joined: 24 Feb 2013 Posts: 794 Location: London, England 12028 Bank Notes
Items
|
|
Variables, 'flt's or "if" statements can be very confusing if you don't have much experience with them, and little was known about them when I first started modding so it took me years to pick up.
However, now more is known and more modders are starting to use them I thought it would be helpful to introduce them to those who aren't quite sure about their use
However complicated they may seem, variables are incredibly simple.
If YES (1), what happens?
If NO (0), what happens?
In a Mafiascript context, variable scripts are made up of two parts:
1. The 'assignment' command (defining what will be measured)
2. The 'result and consequence' command (defining what happens if the condition we're measuring turns out to be true or false)
For example:
We could pick a command like "human_isweapon XX, YY, ZZ", which measures whether actor XX has weapon ZZ (ZZ being the weapon ID) and stores the resulting 'yes' or 'no' in YY (the name (has to be a number) of a variable that you can choose*).
So, the first half of our script would look like this:
dim_flt 2
dim_act 1
findactor 0, "Tommy"
label CHECKFORCOLT
human_isweapon 0, 1, 9
The script above is asking if actor 0 (defined as Tommy in this script) has weapon with the ID 9 (which is the Colt 1911). It will store the result (yes or no, 1 or 0) in a flt that I have named 1 (the YY number in the middle).
So, now comes the second part of the script: What to do with the resulting 'yes' or 'no' from the previous half of the script that is stored in flt 1.
This is where "if" statements come into play. If statements look like the following: if flt[WW] = XX, YY, ZZ, where WW is the name (number) of the flt (variable), XX is the value that it has to be (1 (yes) or 0 (no)) for the script to jump to label YY. If flt[WW] is not the value of XX (1 or 0) then the script will go to ZZ. Normally ZZ is set to the label at the start of the script, so that it keeps checking and re-checking (in this case) whether the player has a Colt 1911 in their possession or not.
So, the second half of our script would read:
if flt[1] = 1, GAMEOVER, CHECKFORCOLT
label GAMEOVER
endofmission 0
The script above is now telling the game that if the flt named 1 returns a value of 1 (yes) for the player having a Colt 1911, it should jump to the label 'GAMEOVER', which can be seen below as ending the game via the "endofmission" command. If the value is returned as 0 (no), then the script will jump to the label of the script shown before this one, labelled 'CHECKFORCOLT'. This will run the script again an infinite number of times in a loop until the player picks up a Colt 1911.
*You can name the flt whatever number you like, as long as you have allowed for that many 'flt's at the start of the script (if you name the flt '9', you would have to write "dim_flt 10" at the beginning in order for the game to recognise up to 10 'flt's (0 counts as one).
Hopefully this hasn't fried the brains of those reading it too much, just go over it slowly and replicate each stage with your own script step-by-step. Once you've mastered "if" scripts you can do all sorts of things so give it a try and, as always, ask here if you need any help
Good luck! _________________
The official Mafioso Mod thread |
|
Back to top |
|
 |
AsaSK
Mafiascene Veteran Modder


Joined: 24 Feb 2013 Posts: 794 Location: London, England 12028 Bank Notes
Items
|
|
Back to top |
|
 |
MatteoCapoletti
Mafiascene Veteran Modder


Joined: 05 Mar 2013 Posts: 536
1054 Bank Notes
Items
|
|
Back to top |
|
 |
AsaSK
Mafiascene Veteran Modder


Joined: 24 Feb 2013 Posts: 794 Location: London, England 12028 Bank Notes
Items
|
|
Back to top |
|
 |
Rented91951
New Member


Joined: 15 Jan 2021 Posts: 8 Location: Cairo, Egypt 22 Bank Notes
Items
|
|
Really really helpful! Thanks Asa  |
|
Back to top |
|
 |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|