I wrote this a year or so ago back in '0.5', ive added a few notes to the bottom for the the updates in 'mtasa:race'
I know noone asked for it, but if anyones interested in learning some basic scripting, this should help.
scripting help by [uVA]Scooby.
Written for mtavc 0.5 (see notes at bottom)
over the last few yrs people have been asking for help with scripting,
since there is no proper tutorial for mta scripting i know in the beginning it can be kinda hard.
some have picked up the basics and need help with harder stuff, some dont know a thing.
heres a little something i thought id write for anyone wanting to understand it more.
its very basic stuff, but should help you on your way to making you first script.
scripts are written into a text file in .mrc format - some people use mirc script editor,
some use notepad and some use other programs - to be honest, it doesnt really matter
as long as u can type and save as .mrc
ok i will show u an extremely basic script, then explain a few things about it.
on *:SIGNAL:mta.command:{
if ($3 == !moo) mta.say $1 $mta.name($1,$2) says moooooooo!
if ($3 == !hp) mta.msg $1 $2 Your Health is at $mta.health($1,$2) $+ %
}
so there we have it... thrilling eh.
ok the first line 'on *:SIGNAL:mta.command:{' this is where all the stuff u type with a ! is looked at.
ok so, by typing !moo it displays in the chat '[uVA]Scooby says moooooooo!'
$mta.name($1,$2) is what we use to return the name of the person who typed the info.
and by typing !hp we get a pm telling us our health. mta.msg is used for this.
$mta.health($1,$2) is what we use to return the health of the person typing the info
after comes $+ this is used to remove the space between text if it wasnt used it would show as 100 %
rather that 100%. finally, its finished with a }
you will find that these are very important. when a { is used it must always be finished with a }
also note, when sending a pm its a little different to mta.say
the $1 $2 and $3 may look a little confusing to you. i'll explain what they do as easily as poss.
$1 = Server
$2 = PlayerID
$3 = the first word u type
$4 = the second word u type
$5 = the 3rd word u type... and so on
u can also use a minus sign after, this is the same as saying 'the rest of the info'
$3- = the first word and all the words that come after the first word.
so if u wanted to find out if the word 'moo' was bein typed, you would use: if (moo isin $3-)
ok that should have been easy enough for you to follow - if not - give up.
there is a list of all the identifiers in the scripting help files that came with mtama.
please remember when writing a script, there is always more than one way to do it,
if ($3 == !moo) mta.say $1 $mta.name($1,$2) says moooooooo!
if $3 == !moo { mta.say $1 $mta.name($1,$2) says moooooooo! }
if ($3 == !moo) { mta.say $1 $mta.name($1,$2) says moooooooo! }
if ($3 == !moo) {
mta.say $1 $mta.name($1,$2) says moooooooo!
}
all these lines will work..
however, the top one is the most common.
ok so we're still doing really really basic stuff - lets make it more interesting by adding a variable
var %a = $iif($4 == $null,$2,$mta.getid($1,$4))
looks complicated huh... ok i'll explain the line.
$iif is commonly used however at this stage i'll just briefly explain what it does.
$iif(1 == 2,yes,no) would return no
or
$iif(1 == 1,yes,no) would return yes
so lets take our line: $iif($4 == $null,$2,$mta.getid($1,$4))
it says if $4 == $null, $4 is our second word, $null means 'empty',
$2 is the ID who typed it, $mta.getid is an alias that finds a name from a number or part name
so basically it says: if the second word is empty, use your ID, else get the ID from the name given.
On *:SIGNAL:mta.command: is an alias - it contains whatever u choose. These are commands that begin with !
very soon you will be making your own alises, however,
mtama has several aliases that come with it, which we will be using for now.
so if we use the 'var %a =' line within our previous commands we can make it do a lot more.. here it is again.
on *:SIGNAL:mta.command:{
var %a = $iif($4 == $null,$2,$mta.getid($1,$4))
if ($3 == !moo) {
if ($4 == $null) mta.say $1 $mta.name($1,$2) says moooooooo!
else mta.say $1 $mta.name($1,$2) says mooooooo to $mta.name($1,%a)
}
if ($3 == !hp) {
if ($4 == $null) mta.msg $1 $2 Your Health is at $mta.health($1,$2) $+ %
else mta.msg $1 $2 $mta.name($1,%a) $+ s health is at $mta.health($1,%a) $+ %
}
}
ok now u can see we've introduced an 'else'
so we ask... is $4 empty? - is there a second word?
if there is no second word... do this, else do this
you will find that if u add this script, it will work, but it still has one fault.
your probably confused enough so i will just explain.
the alias mta.getid does just that, it gets the id number, from the name u typed.
so if u type !hp bob, it looks thru all 26 players for the word bob
if bob is not there it returns -1
if bob is there it returns the id number
if u specify the id number, eg !hp 4 - it looks to see if id 4 is used, and returns -1 if the slot is empty
so we need to add another few lines to our script just in case someone types !hp bob, and bob isnt there.
here it is.
on *:SIGNAL:mta.command:{
var %a = $iif($4 == $null,$2,$mta.getid($1,$4))
if ($3 == !moo) {
if (%a == -1) mta.msg $1 $2 Error: Invalid Name/ID.
elseif ($4 == $null) mta.say $1 $mta.name($1,$2) says moooooooo!
else mta.say $1 $mta.name($1,$2) says mooooooo to $mta.name($1,%a)
}
if ($3 == !hp) {
if (%a == -1) mta.msg $1 $2 Error: Invalid Name/ID.
elseif ($4 == $null) mta.msg $1 $2 Your Health is at $mta.health($1,$2) $+ %
else mta.msg $1 $2 $mta.name($1,%a) $+ s health is at $mta.health($1,%a) $+ %
}
}
ok almost complete... however there is still more we can add.
at the moment the script contains 2 commands, the first looking for the word !moo, and the second !hp,
but if we type !moo then we're obviously not typing !hp. so by adding 'else' to the second command,
will just about do us. its not majorly important and will work fine without it, but if you have 200 commands,
it has to check all 200 every time a ! is used in the chat.
if you have a big script this can slow things down.
so the final script should look like this:
on *:SIGNAL:mta.command:{
var %a = $iif($4 == $null,$2,$mta.getid($1,$4))
if ($3 == !moo) {
if (%a == -1) mta.msg $1 $2 Error: Invalid Name/ID.
elseif ($4 == $null) mta.say $1 $mta.name($1,$2) says moooooooo!
else mta.say $1 $mta.name($1,$2) says mooooooo to $mta.name($1,%a)
}
elseif ($3 == !hp) {
if (%a == -1) mta.msg $1 $2 Error: Invalid Name/ID.
elseif ($4 == $null) mta.msg $1 $2 Your health is at $mta.health($1,$2) $+ %
else mta.msg $1 $2 $mta.name($1,%a) $+ s health is at $mta.health($1,%a) $+ %
}
}
there you have it. you made your script. this is still very basic,
but by now you should be starting to understand it. if u dont fully understand what u just did
start again. dont copy and paste what i wrote, type it out so u get used to it.
now by looking at mtama scripting help you can find a list of other identifiers u can use.
so far we have used just 3 - $mta.name, $mta.health and $mta.getid
the $ at the beginning of these points to an alias within a script - the ones we have used
are writtin into mta.mrc, they return information sent from the second part of it, we used ($1,$2) and ($1,%a)
we sent the alias $2 and %a and it returned the info on each.
-----------------------------------------------------------------------------------------------------
writing to .ini files.
ok so u need info saving to a file. lets start with something basic.
on *:SIGNAL:mta.command:{
if ($3 == !seen) {
if ($4 == $null) mta.msg $1 $2 Error: please specify name.
elseif ($readini(seen.ini,seen,$4) == $null) mta.say $1 $4 has never been seen in this server.
else mta.say $1 $4 was last seen on $readini(seen.ini,seen,$4)
}
}
on *:SIGNAL:mta.part:{
!writeini -n seen.ini seen $mta.name($1,$2) $time $date
}
there we have it. as people leave your server - their name is written to a ini file with the time and date.
and by typing !seen it looks through the ini file for the name u specified
and retuns the info stored, if none is found says they have never been seen here.
inis are a simple way of storing information in text format - it can be easily opened and viewed by you
if the ini is going to be small - just a few lines, the -n is not needed, but i would reccomend it.
!writeini -n
so inside the ini you have sections you can have as many as you like within 1 ini.
however, try to keep them as small as possible.
so our ini is called seen.ini, inside it we have
[seen]
bla=time and date last seen
moo=time and date last seen
bob=time and date last seen
and to read this info $readini( , , ) this will return the info stored
it will return $null if nothing is stored for the name u gave.
so if u typed !seen bob
it looked in the ini called seen.ini
it looked for the section called seen
it then looked down the list the the name 'bob' and returned the info stored.
ok so we can add this to your script. it should look like this now.
on *:SIGNAL:mta.command:{
var %a = $iif($4 == $null,$2,$mta.getid($1,$4))
if ($3 == !moo) {
if (%a == -1) mta.msg $1 $2 Error: Invalid Name/ID.
elseif ($4 == $null) mta.say $1 $mta.name($1,$2) says moooooooo!
else mta.say $1 $mta.name($1,$2) says mooooooo to $mta.name($1,%a)
}
elseif ($3 == !hp) {
if (%a == -1) mta.msg $1 $2 Error: Invalid Name/ID.
elseif ($4 == $null) mta.msg $1 $2 Your health is at $mta.health($1,$2) $+ %
else mta.msg $1 $2 $mta.name($1,%a) $+ s health is at $mta.health($1,%a) $+ %
}
elseif ($3 == !seen) {
if ($4 == $null) mta.msg $1 $2 Error: please specify name.
elseif ($readini(seen.ini,seen,$4) == $null) mta.say $1 $4 has never been seen in this server.
else mta.say $1 $4 was last seen on $readini(seen.ini,seen,$4)
}
}
on *:SIGNAL:mta.part:{
!writeini -n seen.ini seen $mta.name($1,$2) $time $date
}
ini's can be very handy to use when beginning with scripts,
people have big ideas and this is an easy way to store info.
this can be adapted now to save any info u want to save.
good luck and keep at it:D
NOTES:
These are the changes in the different versions.
MTA0.5 -> MTASA:Race
mta.name -> mta.nick
mta.say -> mta.text
mta.msg -> mta.pm
mta.health -> Not Added