Community Resources: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Prettified)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
==Community calls documentation==
This page lists PHP calls that MTA Community allows you to use in your scripts, via [[callRemote]].
only use:
 
==community.mtasa.com/mta/resources.php==
 
Retrieves the latest version number for a resource available on MTA Community.
 
'''Arguments''':
<syntaxhighlight lang="lua">
string "version", string resourceName
</syntaxhighlight>
'''Returns:'''
*a string with the resource name
*a string of the resource version in format of "x.x.x", or integer 0 if an error has occurred
*a number which is the community id for the resource, or nil if an error has occurred
 
===Example===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
callRemote()
addEventHandler( "onResourceStart", getResourceRootElement(),
  function()
      callRemote( "http://community.mtasa.com/mta/resources.php", handleVersionCheck, "version", getResourceName(getThisResource()) )
  end
)
 
function handleVersionCheck( resName, commVer, commId )
    local thisVer = getResourceInfo(getThisResource(), "version")
    if commId and thisVer ~= commVer then
        outputChatBox( getResourceName(getThisResource()) .. " is outdated. Your version: " .. thisVer .. " | Current: " .. commVer )
        outputChatBox( "Please download the update @ http://community.multitheftauto.com/index.php?p=resources&s=details&id=" .. commId )
    end
end
</syntaxhighlight>
</syntaxhighlight>


<!--
==community.mtasa.com/mta/verify.php==
==community.mtasa.com/mta/verify.php==


Line 15: Line 42:
'''Returns:''' an integer, 1 if user is valid, 0 otherwise
'''Returns:''' an integer, 1 if user is valid, 0 otherwise


==Example==
===Example===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onPlayerJoin", getRootElement(), function()
addEventHandler ( "onPlayerJoin", getRootElement(), function()
Line 29: Line 56:
end
end
</syntaxhighlight>
</syntaxhighlight>
 
-->
==community.mtasa.com/mta/groups.php==
==community.mtasa.com/mta/groups.php==


'''Calls:'''
Retrieves group information from MTA Community.


Info:
'''Arguments''':
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string "info", int groupID
string "info", int groupID
</syntaxhighlight>  
</syntaxhighlight>  
'''Returns 5 values:'''<br />
'''Returns 5 values:'''
1. Group name<br />
* Group name
2. Owner username<br />
* Owner username
3. Number of members<br />
* Number of members
4. Public. Integer: 1 if the group is public, 0 otherwise<br />
* Public. Integer: 1 if the group is public, 0 otherwise
5. Registration time<br />
* Registration time




Line 52: Line 79:
'''Returns:''' a table of usernames in the group
'''Returns:''' a table of usernames in the group


==Examples==
===Examples===
<section name="Group Example" class="server" show="false">
<section name="Group Example" class="server" show="false">
This outputs the servers group name, if the group is public or private, and the registration time.
This outputs the servers group name, if the group is public or private, and the registration time.
Line 82: Line 109:
</section>
</section>


==community.mtasa.com/mta/resources.php==
'''Calls:'''
'''PLEASE NOTE:''' The resource that uses this, needs to be added to the ACL.xml in the Admin Group.
Latest resource version:
<syntaxhighlight lang="lua">
string "version", string resourceName
</syntaxhighlight>
'''Returns:''' a string, resource version in format of "x.x.x". Integer 0 if an error has occurred
==Example==
<syntaxhighlight lang="lua">
addEventHandler( "onResourceStart", getResourceRootElement(),
  function()
      callRemote( "http://community.mtasa.com/mta/resources.php", handleVersionCheck, "version", getResourceName(getThisResource()) )
  end
)
function handleVersionCheck( resName, commVer, commId )
    local thisVer = getResourceInfo(getThisResource(), "version")
    if commId and thisVer ~= commVer then
        outputChatBox( getResourceName(getThisResource()) .. " is outdated. Your version: " .. thisVer .. " | Current: " .. commVer )
        outputChatBox( "Please download the update @ http://community.multitheftauto.com/index.php?p=resources&s=details&id=" .. commId )
    end
end
</syntaxhighlight>


[[Category:Scripting Concepts]]
[[Category:Scripting Concepts]]

Latest revision as of 09:25, 23 June 2016

This page lists PHP calls that MTA Community allows you to use in your scripts, via callRemote.

community.mtasa.com/mta/resources.php

Retrieves the latest version number for a resource available on MTA Community.

Arguments:

string "version", string resourceName

Returns:

  • a string with the resource name
  • a string of the resource version in format of "x.x.x", or integer 0 if an error has occurred
  • a number which is the community id for the resource, or nil if an error has occurred

Example

addEventHandler( "onResourceStart", getResourceRootElement(), 
   function()
      callRemote( "http://community.mtasa.com/mta/resources.php", handleVersionCheck, "version", getResourceName(getThisResource()) )
   end
)

function handleVersionCheck( resName, commVer, commId )
    local thisVer = getResourceInfo(getThisResource(), "version")
    if commId and thisVer ~= commVer then
        outputChatBox( getResourceName(getThisResource()) .. " is outdated. Your version: " .. thisVer .. " | Current: " .. commVer )
        outputChatBox( "Please download the update @ http://community.multitheftauto.com/index.php?p=resources&s=details&id=" .. commId )
    end
end

community.mtasa.com/mta/groups.php

Retrieves group information from MTA Community.

Arguments:

string "info", int groupID

Returns 5 values:

  • Group name
  • Owner username
  • Number of members
  • Public. Integer: 1 if the group is public, 0 otherwise
  • Registration time


Members list:

string "members", int groupID

Returns: a table of usernames in the group

Examples

Click to expand [+]
Group Example
Click to expand [+]
Members Example