GetUserdataType: Difference between revisions
Jump to navigation
Jump to search
m (decaps) |
m (Fixed a markup typo) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server client function}} | {{Server client function}} | ||
{{New feature/item|3. | {{New feature/item|3.0153|1.5.3|9768|This function gets the type of a userdata value, which is not always a [[element]] in the element tree.}} | ||
==Syntax== | ==Syntax== | ||
Line 18: | Line 18: | ||
***''vector4'': a 4D vector, used in the [[Vector/Vector4|Vector4]] class. | ***''vector4'': a 4D vector, used in the [[Vector/Vector4|Vector4]] class. | ||
***''matrix'': a matrix, used in the [[Matrix]] class. | ***''matrix'': a matrix, used in the [[Matrix]] class. | ||
***''request'': a userdata type returned via [[fetchRemote]] (since [https://buildinfo.mtasa.com/?Revision=21436&Branch= r21436]) | |||
***''userdata'': a fallback userdata type return value, when no other type could be found for the object. | ***''userdata'': a fallback userdata type return value, when no other type could be found for the object. | ||
**'''Server only''' | **'''Server only''' |
Latest revision as of 17:53, 2 March 2023
This function gets the type of a userdata value, which is not always a element in the element tree.
Syntax
string getUserdataType ( userdata value )
Required Arguments
- value: A userdata value to get the type of. Userdata types can be:
- Shared
- resource-data: a resource pointer.
- xml-node: a XML node.
- lua-timer: a timer.
- vector2: a 2D vector, used in the Vector2 class.
- vector3: a 3D vector, used in the Vector3 class.
- vector4: a 4D vector, used in the Vector4 class.
- matrix: a matrix, used in the Matrix class.
- request: a userdata type returned via fetchRemote (since r21436)
- userdata: a fallback userdata type return value, when no other type could be found for the object.
- Server only
- account: a player account.
- db-query: a database query handle.
- acl: an ACL entry.
- acl-group: an ACL group.
- ban: a player ban.
- text-item: a text display item.
- text-display: a text display item.
- Shared
Returns
Returns a string containing the specified userdata's type, or false plus an error message if the given value is not userdata.
Example
This example shows a function that can be used to work around the impossibility to transfer vectors as arguments when using triggerClientEvent and triggerServerEvent, by converting them into a table which can be used safely.
function safeArgsForTransfer(...) local args = { ... } for index, arg in ipairs(args) do if type(arg) == "userdata" and getUserdataType(arg):match("vector") then -- Transform every kind of vector userdata to a table which can be transfered safely args[index] = { arg:getX(), arg:getY(), arg.getZ and arg:getZ() or nil, arg.getW and arg:getW() or nil, -- Extra field to distinguish from normal tables ["isVectorWorkaround"] = true } end end return unpack(args) end
See Also
- addDebugHook
- base64Decode
- base64Encode
- debugSleep
- decodeString
- encodeString
- fromJSON
- generateKeyPair
- getColorFromString
- getDevelopmentMode
- getDistanceBetweenPoints2D
- getDistanceBetweenPoints3D
- getEasingValue
- getNetworkStats
- getNetworkUsageData
- getPerformanceStats
- getRealTime
- getTickCount
- getTimerDetails
- getTimers
- getFPSLimit
- getUserdataType
- getVersion
- gettok
- isTransferBoxVisible
- setTransferBoxVisible
- hash
- inspect
- interpolateBetween
- iprint
- isOOPEnabled
- isTimer
- killTimer
- md5
- passwordHash
- passwordVerify
- pregFind
- pregMatch
- pregReplace
- removeDebugHook
- resetTimer
- setDevelopmentMode
- setFPSLimit
- setTimer
- ref
- deref
- sha256
- split
- teaDecode
- teaEncode
- toJSON
- tocolor
- getProcessMemoryStats
- utfChar
- utfCode
- utfLen
- utfSeek
- utfSub
- bitAnd
- bitNot
- bitOr
- bitXor
- bitTest
- bitLRotate
- bitRRotate
- bitLShift
- bitRShift
- bitArShift
- bitExtract
- bitReplace