Globals::invoke: Difference between revisions
No edit summary |
(GET_POSIX_TIME invoke example fix) |
||
| (6 intermediate revisions by 4 users not shown) | |||
| Line 6: | Line 6: | ||
==Syntax== | ==Syntax== | ||
< | <pre> | ||
mp.game.invoke(hash, [, ...args]) | mp.game.invoke(hash, [, ...args]) | ||
</ | </pre> | ||
==Example== | ==Example== | ||
< | {{ClientsideCode| | ||
<pre> | |||
// Normal invoke void | |||
mp.game.invoke(' | mp.game.invoke('0x428CA6DBD1094446', mp.players.local.handle, true); // FREEZE_ENTITY_POSITION | ||
</ | // You should use arrays with one element of required type to pass variable as a reference | ||
let posixTime = { year: [0], month: [0], day: [0], hour: [0], minute: [0], second: [0] }; | |||
mp.game.invoke('0xDA488F299A5B164E', posixTime.year, posixTime.month, posixTime.day, posixTime.hour, posixTime.minute, posixTime.second); | |||
mp.gui.chat.push(`Year: ${posixTime.year[0]}`); | |||
// that works for all types | |||
let matrix = { r: [[0, 0, 0]], f: [[0, 0, 0]], u: [[0, 0, 0]], p: [[0, 0, 0]] }; | |||
mp.game.invoke('0xECB2FC7235A7D137', handle, matrix.r, matrix.f, matrix.u, matrix.p); | |||
// ArrayBuffers could be used too | |||
let outDataBuffer = [new ArrayBuffer(256)]; | |||
mp.game.invoke('0x79923CD21BECE14E', 0, outDataBuffer); | |||
// If you are dealing with hashes, you might have some problems since JavaScript might try to convert it to float in some cases. | |||
// To avoid that, always append >> 0 to the hash | |||
mp.game.invoke('0x015A522136D7F951', mp.players.local.handle, mp.game.joaat('weapon_specialcarbine') >> 0) // GET_AMMO_IN_PED_WEAPON | |||
// This example would not work otherwise | |||
</pre> | |||
}} | |||
== See Also == | |||
{{GameGlobals}} | |||
[[Category:Clientside API]] | |||
Latest revision as of 20:12, 7 April 2021
Invokes specified native function
Parameters
- hash: String
- args: Any
Syntax
mp.game.invoke(hash, [, ...args])
Example
Client-Side
// Normal invoke void
mp.game.invoke('0x428CA6DBD1094446', mp.players.local.handle, true); // FREEZE_ENTITY_POSITION
// You should use arrays with one element of required type to pass variable as a reference
let posixTime = { year: [0], month: [0], day: [0], hour: [0], minute: [0], second: [0] };
mp.game.invoke('0xDA488F299A5B164E', posixTime.year, posixTime.month, posixTime.day, posixTime.hour, posixTime.minute, posixTime.second);
mp.gui.chat.push(`Year: ${posixTime.year[0]}`);
// that works for all types
let matrix = { r: [[0, 0, 0]], f: [[0, 0, 0]], u: [[0, 0, 0]], p: [[0, 0, 0]] };
mp.game.invoke('0xECB2FC7235A7D137', handle, matrix.r, matrix.f, matrix.u, matrix.p);
// ArrayBuffers could be used too
let outDataBuffer = [new ArrayBuffer(256)];
mp.game.invoke('0x79923CD21BECE14E', 0, outDataBuffer);
// If you are dealing with hashes, you might have some problems since JavaScript might try to convert it to float in some cases.
// To avoid that, always append >> 0 to the hash
mp.game.invoke('0x015A522136D7F951', mp.players.local.handle, mp.game.joaat('weapon_specialcarbine') >> 0) // GET_AMMO_IN_PED_WEAPON
// This example would not work otherwise