GetVersion: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Added 'tag' description and example)
Line 20: Line 20:
**'''"Nightly rX"''' - A nightly development build.  '''X''' represents the nightly build revision.
**'''"Nightly rX"''' - A nightly development build.  '''X''' represents the nightly build revision.
**'''"Custom"''' - A build compiled manually
**'''"Custom"''' - A build compiled manually
**'''"Release"''' - A build that is publically 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'.)


==Example==  
==Example==  
Line 37: Line 38:
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
 
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">
<syntaxhighlight lang="lua">
function sendVersion ()
  -- Send local player version to the server
  triggerServerEvent ( "onNotifyPlayerVersion", getLocalPlayer(), getVersion() )
end
addEventHandler ( "onClientResourceStart", getRootElement(), sendVersion )
</syntaxhighlight>
</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
  outputConsole( "Kicking player as below 1.0.3 Release build 9" );
  kickPlayer( source, "Upgrade your version at www.mtasa.com" )
end
addEvent ( "onNotifyPlayerVersion", true)
addEventHandler ( "onNotifyPlayerVersion", getRootElement(), handlePlayerVersion )
</syntaxhighlight>
</section>
==See Also==
==See Also==
{{Server functions}}
{{Server functions}}

Revision as of 13:09, 19 December 2009

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

Syntax

table getVersion ( )

Required Arguments

None.

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'.)

Example

This example will make a script compatible only with version 1.0:

Click to collapse [-]
Server
function setHoboSkin ( playerSource )
  local version = getVersion ( )
  if version.number < 256 then -- MTA 1.0 version number is 0x0100
    setPlayerSkin ( playerSource, 137 )
  else
    setElementModel ( playerSource, 137 )
  end
end
addCommandHandler ( "hobo", setHoboSkin )

This client and server example will kick players that have anything earlier than the final released version of 1.0.3:

Click to collapse [-]
Client
function sendVersion ()
  -- Send local player version to the server
  triggerServerEvent ( "onNotifyPlayerVersion", getLocalPlayer(), getVersion() )
end
addEventHandler ( "onClientResourceStart", getRootElement(), sendVersion )
Click to collapse [-]
Server
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
  outputConsole( "Kicking player as below 1.0.3 Release build 9" );
  kickPlayer( source, "Upgrade your version at www.mtasa.com" )
end
addEvent ( "onNotifyPlayerVersion", true)
addEventHandler ( "onNotifyPlayerVersion", getRootElement(), handlePlayerVersion )

See Also