GetVersion: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Example changed to promote secure use of event parameters)
No edit summary
 
(21 intermediate revisions by 10 users not shown)
Line 3: Line 3:


This function gives you various version information about MTA and the operating system.
This function gives you various version information about MTA and the operating system.
MTA already has a built in command '/ver' which will show you your client version. Alongside that, there is also '/sver' which will show you the version of the server you are currently connected to. This function unlike [[getPlayerVersion]] shows a lot more information regarding MTA version.
{{Note|Clientside will return the version from the player, and the server-sided will return version from the server.}}
{{Note|Current MTA version: {{CurrentVersion}}}}


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">table getVersion ( )</syntaxhighlight>
<syntaxhighlight lang="lua">table getVersion ( )</syntaxhighlight>
===Required Arguments===
''None.''


===Returns===
===Returns===
Line 22: Line 23:
**'''"Release"''' - A build that is publicly released (provisional).
**'''"Release"''' - A build that is publicly released (provisional).
*'''tag:''' the build tag (from 1.0.3 onwards). Contains infomation about the underlying version used. i.e. The final version of 1.0.3 has the build tag of "1.0.3 rc-9". (This can be confirmed by using the console command 'ver'.)
*'''tag:''' the build tag (from 1.0.3 onwards). Contains infomation about the underlying version used. i.e. The final version of 1.0.3 has the build tag of "1.0.3 rc-9". (This can be confirmed by using the console command 'ver'.)
*'''sortable:''' a 15 character sortable version string (from 1.0.4 onwards). Format of the string is described in [[getPlayerVersion]].


==Example==  
==Example==  
'''Example 1:''' This example will make a script compatible only with version 1.0:
<section name="Server" class="server" show="true">
<section name="Server" class="server" show="true">
This piece of code shows how you can use a simple command and a for loop to dump the output into chatbox, whilst capitalizing 1st character for extra bonus.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function setHoboSkin ( playerSource )
function showVersion(player)
  local version = getVersion ( )
    -- We use a for loop to dump the output into player chatbox
  if version.number < 256 then -- MTA 1.0 version number is 0x0100
    outputChatBox("Version information (Server):", player, 0, 255, 0)
    setPlayerSkin ( playerSource, 137 )
    for ind, dat in pairs(getVersion()) do
  else
        -- Uppercasing first letter too
    setElementModel ( playerSource, 137 )
        outputChatBox(string.upper(string.sub(ind, 1, 1))..string.sub(ind, 2)..": "..dat, player, 0, 255, 0)
  end
    end
end
end
addCommandHandler ( "hobo", setHoboSkin )
addCommandHandler("version", showVersion) -- Define our command handler
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>


'''Example 2:''' This client and server example will kick players that have anything earlier than the final released version of 1.0.3:
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
This piece of code shows how you can use a simple command and a for loop to dump the output into chatbox, whilst capitalizing 1st character for extra bonus. Keep in mind that this is the client sided version of this command which will output version information of your client, whilst the example above outputs information of the server you are connected to.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function sendVersion ()
function showVersion()
  -- Send local player version to the server
    -- We use a for loop to dump the output into player chatbox
  triggerServerEvent ( "onNotifyPlayerVersion", getResourceRootElement(), getVersion() )
    outputChatBox("Version information (Client):", 0, 255, 0)
end
    for ind, dat in pairs(getVersion()) do
addEventHandler ( "onClientResourceStart", getResourceRootElement(), sendVersion )
        -- Uppercasing first letter too
</syntaxhighlight>
        outputChatBox(string.upper(string.sub(ind, 1, 1))..string.sub(ind, 2)..": "..dat, 0, 255, 0)
</section><section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
function handlePlayerVersion( version )
  if version.number > 256 + 3 then  -- Allow anything above 1.0.3
    return
  end
  if version.number == 256 + 3 then  -- Check further if it is exactly 1.0.3
    if version.type == "Release" then -- Check further if it is the "Release" type
      local _,_,buildnumber = string.find( version.tag or "", "(%d)$" )  -- Extract the build number if there
      buildnumber = tonumber(buildnumber) or 0
      if buildnumber >= 9 then  -- Allow 9 and above
        return
      end
     end
     end
  end
  outputConsole( "Kicking player as below 1.0.3 Release build 9" );
  kickPlayer( client, "Upgrade your version at www.mtasa.com" )
end
end
addEvent ( "onNotifyPlayerVersion", true)
addCommandHandler("version", showVersion) -- Define our command handler
addEventHandler ( "onNotifyPlayerVersion", getResourceRootElement(), handlePlayerVersion )
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>


==See Also==
==See Also==
{{Server functions}}
{{Utility functions}}

Latest revision as of 21:53, 25 July 2025

This function gives you various version information about MTA and the operating system.

MTA already has a built in command '/ver' which will show you your client version. Alongside that, there is also '/sver' which will show you the version of the server you are currently connected to. This function unlike getPlayerVersion shows a lot more information regarding MTA version.

[[{{{image}}}|link=|]] Note: Clientside will return the version from the player, and the server-sided will return version from the server.
[[{{{image}}}|link=|]] Note: Current MTA version:

mta -> 1.6
netcode -> 474
number -> 352
sortable -> 1.6.0-9.22279.0
tag -> 1.6-release-22279
type -> Release

Syntax

table getVersion ( )

Returns

Returns a table with version information. Specifically these keys are present in the table:

  • number: the MTA server or client version (depending where the function was called) in pure numerical form, e.g. "256"
  • mta: the MTA server or client version (depending where the function was called) in textual form, e.g. "1.0"
  • name: the full MTA product name, either "MTA:SA Server" or "MTA:SA Client".
  • netcode: the netcode version number.
  • os: returns the operating system on which the server or client is running
  • type: the type of build. can be:
    • "Nightly rX" - A nightly development build. X represents the nightly build revision.
    • "Custom" - A build compiled manually
    • "Release" - A build that is publicly released (provisional).
  • tag: the build tag (from 1.0.3 onwards). Contains infomation about the underlying version used. i.e. The final version of 1.0.3 has the build tag of "1.0.3 rc-9". (This can be confirmed by using the console command 'ver'.)
  • sortable: a 15 character sortable version string (from 1.0.4 onwards). Format of the string is described in getPlayerVersion.

Example

Click to collapse [-]
Server

This piece of code shows how you can use a simple command and a for loop to dump the output into chatbox, whilst capitalizing 1st character for extra bonus.

function showVersion(player)
    -- We use a for loop to dump the output into player chatbox
    outputChatBox("Version information (Server):", player, 0, 255, 0)
    for ind, dat in pairs(getVersion()) do
        -- Uppercasing first letter too
        outputChatBox(string.upper(string.sub(ind, 1, 1))..string.sub(ind, 2)..": "..dat, player, 0, 255, 0)
    end
end
addCommandHandler("version", showVersion) -- Define our command handler
Click to collapse [-]
Client

This piece of code shows how you can use a simple command and a for loop to dump the output into chatbox, whilst capitalizing 1st character for extra bonus. Keep in mind that this is the client sided version of this command which will output version information of your client, whilst the example above outputs information of the server you are connected to.

function showVersion()
    -- We use a for loop to dump the output into player chatbox
    outputChatBox("Version information (Client):", 0, 255, 0)
    for ind, dat in pairs(getVersion()) do
        -- Uppercasing first letter too
        outputChatBox(string.upper(string.sub(ind, 1, 1))..string.sub(ind, 2)..": "..dat, 0, 255, 0)
    end
end
addCommandHandler("version", showVersion) -- Define our command handler

See Also