update entity.spawn(...): now returns an Entity instead of id
This commit is contained in:
parent
fc3994446a
commit
d22948f45c
@ -4,4 +4,5 @@ end
|
|||||||
|
|
||||||
function on_grounded()
|
function on_grounded()
|
||||||
entity.transform:set_rot(mat4.rotate({0, 1, 0}, math.random()*360))
|
entity.transform:set_rot(mat4.rotate({0, 1, 0}, math.random()*360))
|
||||||
|
entity:despawn()
|
||||||
end
|
end
|
||||||
|
|||||||
@ -6,11 +6,11 @@ function on_hud_open()
|
|||||||
local pid = hud.get_player()
|
local pid = hud.get_player()
|
||||||
local pvel = {player.get_vel(pid)}
|
local pvel = {player.get_vel(pid)}
|
||||||
local ppos = vec3.add({player.get_pos(pid)}, {0, 0.7, 0})
|
local ppos = vec3.add({player.get_pos(pid)}, {0, 0.7, 0})
|
||||||
local eid = entity.spawn("base:drop", ppos)
|
|
||||||
local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE)
|
local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE)
|
||||||
__rigidbody.set_vel(eid, vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL)))
|
|
||||||
__transform.set_rot(eid,
|
local drop = entity.spawn("base:drop", ppos)
|
||||||
mat4.rotate(mat4.rotate(mat4.rotate({0, 1, 0}, math.random() * 360),
|
drop.rigidbody:set_vel(vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL)))
|
||||||
|
drop.transform:set_rot(mat4.rotate(mat4.rotate(mat4.rotate({0, 1, 0}, math.random() * 360),
|
||||||
{1, 0, 0}, math.random() * 360), {0, 0, 1}, math.random() * 360))
|
{1, 0, 0}, math.random() * 360), {0, 0, 1}, math.random() * 360))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -31,8 +31,8 @@ static int l_spawn(lua::State* L) {
|
|||||||
auto defname = lua::tostring(L, 1);
|
auto defname = lua::tostring(L, 1);
|
||||||
auto& def = content->entities.require(defname);
|
auto& def = content->entities.require(defname);
|
||||||
auto pos = lua::tovec3(L, 2);
|
auto pos = lua::tovec3(L, 2);
|
||||||
auto id = level->entities->spawn(def, pos);
|
level->entities->spawn(def, pos);
|
||||||
return lua::pushinteger(L, id);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_despawn(lua::State* L) {
|
static int l_despawn(lua::State* L) {
|
||||||
|
|||||||
@ -271,6 +271,7 @@ scriptenv scripting::on_entity_spawn(const EntityDef& def, entityid_t eid, entit
|
|||||||
lua::pushenv(L, *entityenv);
|
lua::pushenv(L, *entityenv);
|
||||||
funcsset.on_grounded = lua::hasfield(L, "on_grounded");
|
funcsset.on_grounded = lua::hasfield(L, "on_grounded");
|
||||||
funcsset.on_despawn = lua::hasfield(L, "on_despawn");
|
funcsset.on_despawn = lua::hasfield(L, "on_despawn");
|
||||||
|
lua::pop(L, 2);
|
||||||
return entityenv;
|
return entityenv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user