e4s-sdk/gamedata/scripts/xr_zones.script
2026-06-17 23:06:51 +03:00

107 lines
No EOL
3.5 KiB
Text

--'------------------------------------------------------------------------------------------------------------------
--' Binder ñêðèïòîâûõ çîí
--' Èñïîëüçóåòñÿ òîëüêî â îäíîì ìåñòå â èãðå, íà àðåíå äëÿ òîãî ÷òîáû óäàëÿòü "îòðàáîòàííûå" ïðåäìåòû.
--'------------------------------------------------------------------------------------------------------------------
function bind(obj)
local ini = obj:spawn_ini()
if not ini then
return
end
if ini:section_exist("arena_zone") then
if alife() then
obj:bind_object(arena_zone_binder(obj))
end
end
end
--'--------------------------------------------------------------------------------------------------------------------
--' êëàññ arena_zone_binder. Îí êîíòðîëèðóåò ñêðèïòîâóþ çîíó äëÿ smart terrain
--'--------------------------------------------------------------------------------------------------------------------
local arena_zones = {}
class "arena_zone_binder" (object_binder)
function arena_zone_binder:__init(obj) super(obj)
self.saved_obj = {}
arena_zones[obj:name()] = self
end
function arena_zone_binder:net_spawn(server_object)
if not object_binder.net_spawn(self, server_object) then
return false
end
self.object:set_callback(callback.zone_enter, self.on_enter, self)
self.object:set_callback(callback.zone_exit, self.on_exit, self)
return true
end
function arena_zone_binder:net_destroy()
self.object:set_callback(callback.zone_enter, nil)
self.object:set_callback(callback.zone_exit, nil)
object_binder.net_destroy(self)
end
function arena_zone_binder:purge_items()
local alife = alife()
for k,v in pairs(self.saved_obj) do
local obj = alife:object(k)
printf("release object %s, id %s", obj:name(), k)
alife:release(obj, true)
end
end
--' Ñîõðàíåíèå ñïèñêà çàðåãèñòðåííûõ îáúåêòîâ
function arena_zone_binder:save(packet)
printf("ARENA ZONE SAVE")
object_binder.save(self, packet)
set_save_marker(packet, "save", false, "arena_zone_binder")
local num = #self.saved_obj
packet:w_u8(num)
for k,v in pairs(self.saved_obj) do
packet:w_u16(k)
end
set_save_marker(packet, "save", true, "arena_zone_binder")
end
--' Çàãðóçêà ñïèñêà çàðåãèñòðåííûõ îáúåêòîâ
function arena_zone_binder:load(packet)
printf("ARENA ZONE LOAD")
object_binder.load(self, packet)
set_save_marker(packet, "load", false, "arena_zone_binder")
local num = packet:r_u8()
for i=1,num do
self.saved_obj[packet:r_u16()] = true
end
set_save_marker(packet, "load", true, "arena_zone_binder")
end
--' callback íà âõîä â çîíó. Íóæíî ðåãèñòðèòü âñå îáúåêòû, êðîìå èãðîêà.
--' Òàê êàê åñòü ãëþê, òî ýòîò êîëëáåê âûçûâàåòñÿ è íà âõîä è íà âûõîä èç ñêðèïòîâîé çîíû
function arena_zone_binder:on_enter(zone, obj)
if obj:id() == db.actor:id() or obj:clsid() == clsid.obj_physic
or obj:clsid() == clsid.hanging_lamp or obj:clsid() == clsid.obj_phys_destroyable then
return
end
printf("[zone %s] on_enter obj=%s, clsid=%s", zone:name(), obj:name(), obj:clsid())
self.saved_obj[obj:id()] = true
end
function arena_zone_binder:on_exit(zone, obj)
if obj:id() == db.actor:id() or obj:clsid() == clsid.obj_physic
or obj:clsid() == clsid.hanging_lamp or obj:clsid() == clsid.obj_phys_destroyable then
return
end
printf("[zone %s] on_exit obj=%s, clsid=%s", zone:name(), obj:name(), obj:clsid())
self.saved_obj[obj:id()] = nil
end
function purge_arena_items(name)
local arena_zone = arena_zones[name]
if arena_zone then
arena_zone:purge_items()
end
end