Heloo! I’m trying to get a call_handler to work, so I can add items to a world through the console (call…) I think I have put the call handler in the manifest.json fine, but I’m not so sure about the actual lua file, or maybe it is the manifest.json.
Anywho, here are the files:
manifest.json:
{
"info": {
"name": "Command Item Spawner",
"version": 1
},
"functions": {
"create_item_iconic": {
"controller": "file(call_handlers/item_spawn_handler.lua)",
"endpoint": "server"
},
"create_item": {
"controller": "file(call_handlers/item_spawn_handler.lua)",
"endpoint": "server"
},
"create_item_other": {
"controller": "file(call_handlers/item_spawn_handler.lua)",
"endpoint": "server"
}
}
}
call_handlers/item_spawn_handler.lua:
local Point3 = _radiant.csg.Point3
local log = radiant.log.create_logger('item_spawn_call_logger')
local ItemSpawnHandler = class()
function ItemSpawnHandler:create_item_iconic(session, response, item, x, y, z)
local entity = radiant.entities.create_entity(item)
radiant.terrain.place_entity(entity, Point3(x, y, z), {force_iconic = true})
return true
end
function ItemSpawnHandler:create_item(session, response, item, x, y, z)
local entity = radiant.entities.create_entity(item)
radiant.terrain.place_entity(entity, Point3(x, y, z), { })
end
function ItemSpawnHandler:create_item_other(session, response, item, x, y, z, iconic, owner)
local entity = radiant.entities.create_entity(item)
if owner ~= 'none':
entity:add_component('unit_info'):set_player_id(owner)
radiant.terrain.place_entity(entity, Point3(x, y, z), { force_iconic = iconic })
end
return ItemSpawnHandler