Talk:Useful Functions: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(17 intermediate revisions by 5 users not shown)
Line 1: Line 1:
there i wrote isElementInPhotograph()
== Pending functions ==
enjoy
Here are some functions that were developed as part of the MTA forums scripting section but have not yet been added to the list. Those could be useful to advanced resource crafters.
[[User:Drline|Drline]] 04:44, 30 October 2012 (UTC)


== addAccountToConsole ==
* https://forum.mtasa.com/topic/122958-getworldfrommapposition/ - calculating the world position on a map image
* https://forum.mtasa.com/topic/122823-help-getscreenfromworldposition/ - more powerful screen coordinate function with border support


{{Useful Function}}
--[[User:Quiret|Quiret]] ([[User talk:Quiret|talk]]) 18:58, 17 March 2020 (UTC)
__NOTOC__
This function center the window in any resolution.<br>
* '''NOTE:''' This is made to be used clientside!.
 
==Syntax==
<syntaxhighlight lang="lua">* accName addAccountToConsole ( thePlayer, accountName )</syntaxhighlight>
 
===Required Arguments===
* '''theElement''': The element you want to center it.
 
==Code==
<section name="Clientside script" class="client" show="true">
<syntaxhighlight lang="lua">
function centerWindow (center_window)
    local screenW, screenH = guiGetScreenSize()
    local windowW, windowH = guiGetSize(center_window, false)
    local x, y = (screenW - windowW) /2,(screenH - windowH) /2
    guiSetPosition(center_window, x, y, false)
end
</syntaxhighlight>
</section>
 
==Example==
This example center the window.
<syntaxhighlight lang="lua">
    addAccountToConsole = function ( plr , name )
        if name and tostring ( name ) and plr and isElement ( plr ) and getElementType ( plr ) == 'player' then
            local acc = getPlayerAccount ( plr )
                if not acc or isGuestAccount ( acc ) then return end
                    if isObjectInACLGroup ( 'user.'.. getAccountName ( acc ) , aclGetGroup ( 'Console' ) ) then
                        if not isObjectInACLGroup ( 'user.'.. name , aclGetGroup ( 'Console' ) ) then
                            aclGroupAddObject ( aclGetGroup( 'Console' ), 'user.' .. name )
                else
                    return false
                end
            else 
                    return false
                end
        else
                return false
            end
        return name or false
    end
   
    addCommandHandler ( 'add_', function ( plr , _, name )
        local name = addAccountToConsole ( plr, name )
            if not name then return false end
                outputChatBox ( 'Warning ! the account : '.. name .. ' was added to console group !', root )
        end
    )</syntaxhighlight>
 
 
Author: The Best
 
==See Also==
{{Useful_Functions}}

Latest revision as of 18:59, 17 March 2020

Pending functions

Here are some functions that were developed as part of the MTA forums scripting section but have not yet been added to the list. Those could be useful to advanced resource crafters.

--Quiret (talk) 18:58, 17 March 2020 (UTC)