Template:Shared function: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Undo revision 45075 by Ahemnassar (talk))
Line 1: Line 1:
These useful client side functions make a GridList have a players names
<pageclass class="both" subcaption="Shared function"></pageclass>
 
<lowercasetitle></lowercasetitle>
==Syntax==
<includeonly>[[Category:Server functions]][[Category:Client functions]]</includeonly>
<syntaxhighlight lang="lua">element guiCreateGridListPlayers ( element gridListName, element columnName, element rowName, float x, float y, float width, float height, bool relative, float columnWidth, [ element parent = nil ] )</syntaxhighlight>
 
===Required Arguments===
*'''gridListName:''' This element is name for GUI gridlist. This name help you to control in GUI GridList for other function.
*'''columnName:''' This element is name for GUI GridList Column. This name help you to control in GUI GridList Column for other function.
*'''rowName:''' This element is name for GUI GridList Row. This name help you to control in GUI GridList Row for other function.
*'''x:''' A float of the 2D x position of the GUI gridlist on a player's screen.  This is affected by the ''relative'' argument.
*'''y:''' A float of the 2D y position of the GUI gridlist on a player's screen. This is affected by the ''relative'' argument.
*'''width:''' A float of the width of the GUI gridlist. This is affected by the ''relative'' argument.
*'''height:''' A float of the height of the GUI gridlist. This is affected by the ''relative'' argument.
*'''relative:''' This is whether sizes and positioning are relative.  If this is ''true'', then all x,y,width,height floats must be between 0 and 1, representing sizes relative to the parent.
*'''columnWidth:''' A float of the column width, relative to the grid list width.
 
 
===Optional Arguments===
{{OptionalArg}}
*'''parent:''' This is the parent that the gui gridlist is attached to.  If the ''relative'' argument is true, sizes and positioning will be made relative to this parent. If the ''relative'' argument is false, positioning will be the number of offset pixels from the parent's origin. If no parent is passed, the parent will become the screen - causing positioning and sizing according to screen positioning.
 
===Returns===
Returns an element of the created GridList if it was successfully created, false otherwise.
 
 
==Function source==
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
function guiCreateGridListPlayers( gridListName, columnName, rowName, x, y, width, height, relative, columnSize, parent )
if (type(gridListName) ~= "number") and (type(columnName) ~= "number") and (type(rowName) ~= "number") and (type(x) == "number") and (type(y == "number")) and (type(width == "number")) and (type(height == "number")) and (type(relative) == "boolean" ) and (type(columnSize == "number")) then
if (type(parent) ~= "number") then
gridListName = guiCreateGridList ( x, y, width, height, relative, parent )
playersColumnName = guiGridListAddColumn(gridListName, "Players", columnSize)
local players = getElementsByType("player")
for k,v in ipairs(players) do
local rowName = guiGridListAddRow(gridListName)
local PlayersName = getPlayerName(v)
guiGridListSetItemText(gridListName,rowName,playersColumnName, PlayersName, false, false)
end
else
gridListName = guiCreateGridList ( x, y, width, height, relative )
playersColumnName = guiGridListAddColumn(gridListName, "Players", columnSize)
local players = getElementsByType("player")
for k,v in ipairs(players) do
local rowName = guiGridListAddRow(gridListName)
local PlayersName = getPlayerName(v)
guiGridListSetItemText(gridListName,rowName,playersColumnName, PlayersName, false, false)
end
end
else
return
end
end
</syntaxhighlight>
</section>
<br />'''Original author:''' [MSN]MHMD.
<br />
 
==Examples==
<section name="Client" class="client" show="true">
Example 1
This example create a players GridList.
<syntaxhighlight lang="lua">
addEventHandler("onClientResourceStart",resourceRoot,
function ()
 
local ScreenWidth,ScreenHeight = guiGetScreenSize()
guiCreateGridListPlayers( TestGrid, TestColumon, TestRow, 300, 200, ScreenWidth/4, ScreenHeight/4 , false, 0.9 )
end
)
</syntaxhighlight>
</section>
 
<section name="Client" class="client" show="true">
Example 2
This example create a players GridList in GUI Window.
<syntaxhighlight lang="lua">
addEventHandler("onClientResourceStart",resourceRoot,
function ()
 
local ScreenWidth,ScreenHeight = guiGetScreenSize()
TestWindow = guiCreateWindow( 200, 100, ScreenWidth/2, ScreenHeight/2, "Test", false )
guiCreateGridListPlayers( TestGrid, TestColumon, TestRow, 100, 80, ScreenWidth/4, ScreenHeight/4 , false, 0.9, TestWindow )
end
)
</syntaxhighlight>
</section>
 
==See Also==
{{Useful_Functions}}

Revision as of 16:13, 28 April 2015