实体 Handle
网络池 ID 可以复用,因此插件通过以下完整身份识别实体:
text
sessionId + entityType + entityId + streamGeneration不能缓存 Native 指针,也不能假设相同 ID 以后仍代表同一个实体。
lua
local function inspect_entity(event)
local entity = samp.entity.get(
event.entityType,
event.entityId,
event.streamGeneration
)
if entity == nil or not entity:is_valid() then
return
end
local position = entity:position()
samp.log.info(
entity.type .. "#" ..
samp.format.number(entity.poolId, 0) ..
" at " ..
samp.format.number(position.x, 1) .. ", " ..
samp.format.number(position.y, 1) .. ", " ..
samp.format.number(position.z, 1)
)
end
samp.events.on("entity.streamed_in", inspect_entity)实体类型
| 类型 | 主要方法 |
|---|---|
player | name()、npc()、state()、health()、armor()、vehicle_id() |
vehicle | model()、health()、velocity()、heading() |
object | model()、rotation()、moving()、attachment() |
actor | model()、health()、invulnerable()、heading() |
pickup | model()、pickup_type() |
text_label | text()、color()、draw_distance()、test_los()、attachment() |
所有 Handle 都有身份字段、is_valid() 和 position()。附着文本标签的坐标是服务器配置的偏移。
运行中启用插件时,应使用 samp.entity.list(type, startId, limit) 分页建立当前实体基线。分页结果使用前仍要检查 is_valid()。