game
Client
modkit.game reads the dinosaurs the client knows about and changes how they look on this client only. Nothing here is sent to the server or to other players.
The character table
| Field | Type | Description |
|---|---|---|
id |
integer | handle of the character on this client. It changes with every spawn and means nothing on the server. |
isLocal |
boolean | this is the player's own dinosaur |
name |
string | player name, "" for AI |
species |
string | class name without BP_ and _C |
alive |
boolean | |
female |
boolean | result of the game's IsFemale() |
growth |
number | 0.0 to 1.0 |
health, maxHealth |
number | |
hunger, maxHunger, thirst, maxThirst, stamina, maxStamina |
number | |
x, y, z |
number | position in Unreal units |
yaw |
number | heading in degrees |
The stat fields are what this client knows. For the local player that is the real state. For other characters the client only has what the game replicates to it, so stats of other players can be zero or old.
Several functions take a char argument. It can be a character table, an id, or nil for the local player. Passing a table or an id makes the client search all game objects for that handle, which is slow. Do not do it every tick for many characters.
modkit.game.localPlayer
modkit.game.localPlayer()
Returns: the character table of the player's own dinosaur, or nil while the player has none (menu, select screen, dead).
modkit.keys.on("F6", function(down)
if not down then return end
local me = modkit.game.localPlayer()
if me then print(me.species, me.growth, me.hunger .. "/" .. me.maxHunger) end
end)
modkit.game.characters
modkit.game.characters()
Returns: array of character tables for every character object on this client. That includes other players, AI and animals that are loaded near the player.
The call walks through all game objects. Use it on a timer of a few seconds, not every tick.
modkit.setInterval(3000, function()
local n = 0
for _, c in ipairs(modkit.game.characters()) do
if not c.isLocal and c.name ~= "" then n = n + 1 end
end
print(n .. " other players in range")
end)
modkit.game.camera
modkit.game.camera()
Returns: a table with the camera of the local player, or nil before the player is in the game.
| Field | Type | Description |
|---|---|---|
x, y, z |
number | camera position |
pitch, yaw, roll |
number | camera rotation in degrees |
fov |
number | field of view in degrees |
local cam = modkit.game.camera()
if cam then print(cam.x, cam.y, cam.z, cam.yaw) end
modkit.game.worldToScreen
modkit.game.worldToScreen(x, y, z)
Projects a world position onto the screen with the engine's ProjectWorldLocationToScreen.
Returns: screenX, screenY in pixels, or nil when the point is behind the camera or the player is not in the game. Use it to place an element of a browser page over a world position.
local sx, sy = modkit.game.worldToScreen(target.x, target.y, target.z + 200)
if sx then page:call("moveMarker", sx, sy) end
modkit.game.screenSize
modkit.game.screenSize()
Returns: width and height of the game viewport in pixels, or nil.
modkit.game.materialCount
modkit.game.materialCount([char])
Returns: number of material slots on the character's mesh, 0 when the character is gone.
print(modkit.game.materialCount())
modkit.game.materialParams
modkit.game.materialParams([char [, slot]])
Lists the parameters that the material instances of one slot override, walking up the parent chain.
| Parameter | Type | Description |
|---|---|---|
| char | table, integer, nil | character, default local player |
| slot | integer | material slot, default 0 |
Returns: array of { type, name, value }. type is "instance" (name of a material instance in the chain), "scalar", "vector", "texture" or "material" (the base material at the end). value is always a string.
Parameters that exist in the master material but are not overridden by an instance do not show up.
for _, p in ipairs(modkit.game.materialParams(nil, 0)) do
print(p.type, p.name, p.value)
end
modkit.game.setMaterialColor
modkit.game.setMaterialColor(char, slot, param, r, g, b [, a])
Sets a vector parameter. The first call on a slot creates a dynamic material instance for it.
| Parameter | Type | Description |
|---|---|---|
| char | table, integer, nil | character, nil for the local player |
| slot | integer | material slot |
| param | string | parameter name, for example "Color1_RedLayer" |
| r, g, b | number | linear color, values above 1.0 are allowed |
| a | number | alpha, default 1.0 |
Returns: true when the character and the material were found.
modkit.game.setMaterialColor(nil, 0, "Color1_RedLayer", 0.0, 4.0, 4.0)
modkit.game.setMaterialScalar
modkit.game.setMaterialScalar(char, slot, param, value)
| Parameter | Type | Description |
|---|---|---|
| char | table, integer, nil | character, nil for the local player |
| slot | integer | material slot |
| param | string | parameter name, for example "Detail_Scale" |
| value | number | new value |
Returns: true when the character and the material were found.
modkit.game.setMaterialScalar(nil, 0, "Detail_Scale", 12)
modkit.game.setMaterialTexture
modkit.game.setMaterialTexture(char, slot, param, file)
Loads an image from your resource and sets it as a texture parameter. The image is decoded once per file and then reused.
| Parameter | Type | Description |
|---|---|---|
| char | table, integer, nil | character, nil for the local player |
| slot | integer | material slot |
| param | string | parameter name, for example "Adult_Base_ColorOverlay" |
| file | string | path inside your resource, for example "textures/pattern.png". It has to be listed under files in the manifest. |
Returns: true on success, false when the character, the material or the image import failed. A file that is not part of the resource raises a Lua error.
modkit.game.setMaterialTexture(nil, 0, "Adult_Base_ColorOverlay", "textures/pattern.png")
Known parameters of the dinosaur skin material
Taken from MI_Tyrannosaurus_Body (master material M_MasterSkin_Dinosaur).
| Kind | Names |
|---|---|
| Vectors | Color1_RedLayer to Color6_YellowLayer, MouthColor, Detail_Normal_Intensity |
| Textures | Adult_Base_ColorOverlay, Juvenile_Base_ColorOverlay, Hatchling_Base_ColorOverlay, Base_Mask, Base_NormalMap, Base_RoughAlbedoCavityMap, Detail_NormalMap, Base_VFX_Mask |
| Scalars | GrowthAmount, Detail_Scale, RefractionDepthBias |