Community Resources: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 95: Line 95:
==Example==
==Example==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),function(startedRes)
addEventHandler( "onResourceStart", getResourceRootElement(),  
   ver = getResourceInfo(startedRes,"version") --Get the resource version
   function()
  name = getResourceName(startedRes) -- Get the name of the resource
      callRemote( "http://community.mtasa.com/mta/resources.php", handleVersionCheck, "version", getResourceName(getThisResource()) )
  callRemote("http://community.mtasa.com/mta/resources.php",resource,ver,name) --Call the site to see if the resource if the latest
  end
end)
)


function resource(version)
function handleVersionCheck( resName, commVer, commId )
  if(version==getResourceInfo(getThisResource(),"version"))then --Check if the resource is the latest
    local thisVer = getResourceInfo(getThisResource(), "version")
      outputChatBox("This resource is the latest resource available.",root,0,100,0) --if it is, then output this
    if commId and thisVer ~= commVer then
  else
        outputChatBox( getResourceName(getThisResource()) .. " is outdated. Your version: " .. thisVer .. " | Current: " .. commVer )
      outputChatBox("This resource is old, get the latest resource at community.mtasa.com",root,100,0,0) --if it's not, then output this
        outputChatBox( "Please download the update @ http://community.multitheftauto.com/index.php?p=resources&s=details&id=" .. commId )
  end
    end
end
end
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 17:01, 14 December 2014

Community calls documentation

only use:

callRemote()

community.mtasa.com/mta/verify.php

Calls:

User validation:

player thePlayer, string Username, string Serial

Returns: an integer, 1 if user is valid, 0 otherwise

Example

addEventHandler ( "onPlayerJoin", getRootElement(), function()
  local username = getPlayerUserName ( source )
  local serial = getPlayerSerial ( source )
  callRemote ( "http://community.mtasa.com/mta/verify.php", validatePlayer, source, username, serial )
end )

function validatePlayer ( player, result )
  local valid = "invalid"
  if ( result == 1 ) then valid = "valid" end
  outputChatBox ( getPlayerName ( player ).."'s username is "..valid )
end

community.mtasa.com/mta/groups.php

Calls:

Info:

string "info", int groupID

Returns 5 values:
1. Group name
2. Owner username
3. Number of members
4. Public. Integer: 1 if the group is public, 0 otherwise
5. 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

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:

string "version", string resourceName

Returns: a string, resource version in format of "x.x.x". Integer 0 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