Changed SetRoomIndex() to SetRoom()
This commit is contained in:
@@ -54,13 +54,13 @@ function createTrigger(handle, room, x, y, script)
|
||||
)
|
||||
end
|
||||
|
||||
function createDoorPair(handle, roomOne, roomOneUID, Xone, Yone, roomTwo, roomTwoUID, Xtwo, Ytwo)
|
||||
function createDoorPair(handle, roomOne, Xone, Yone, roomTwo, Xtwo, Ytwo)
|
||||
--create the scripts
|
||||
local function scriptOne(entity)
|
||||
if entityAPI.GetType(entity) ~= "character" then return end
|
||||
|
||||
--move the character
|
||||
characterAPI.SetRoomIndex(entity, roomTwoUID)
|
||||
characterAPI.SetRoom(entity, roomTwo)
|
||||
characterAPI.SetOrigin(entity, Xtwo, Ytwo-16)
|
||||
networkAPI.PumpCharacterUpdate(entity)
|
||||
|
||||
@@ -73,7 +73,7 @@ function createDoorPair(handle, roomOne, roomOneUID, Xone, Yone, roomTwo, roomTw
|
||||
if entityAPI.GetType(entity) ~= "character" then return end
|
||||
|
||||
--move the character
|
||||
characterAPI.SetRoomIndex(entity, roomOneUID)
|
||||
characterAPI.SetRoom(entity, roomOne)
|
||||
characterAPI.SetOrigin(entity, Xone, Yone-16) --NOTE: the 16 pixel margin for presentation
|
||||
networkAPI.PumpCharacterUpdate(entity)
|
||||
|
||||
@@ -88,9 +88,9 @@ function createDoorPair(handle, roomOne, roomOneUID, Xone, Yone, roomTwo, roomTw
|
||||
end
|
||||
|
||||
--call the monstrosity
|
||||
createDoorPair("pair 1", overworld, uidOne, 0, -64, underworld, uidTwo, 0, 0)
|
||||
createDoorPair("pair 2", overworld, uidOne, 64, -64, underworld, uidTwo, 64, 0)
|
||||
createDoorPair("pair 3", overworld, uidOne, 128, -64, underworld, uidTwo, 128, 0)
|
||||
createDoorPair("pair 1", overworld, 0, -64, underworld, 0, 0)
|
||||
createDoorPair("pair 2", overworld, 64, -64, underworld, 64, 0)
|
||||
createDoorPair("pair 3", overworld, 128, -64, underworld, 128, 0)
|
||||
|
||||
--[[
|
||||
--simple door pair
|
||||
@@ -100,7 +100,7 @@ createTrigger("door 1", overworld, 128, -128, function(entity)
|
||||
end
|
||||
|
||||
--move the character
|
||||
characterAPI.SetRoomIndex(entity, uidTwo)
|
||||
characterAPI.SetRoom(entity, uidTwo)
|
||||
characterAPI.SetOrigin(entity, 0, 0)
|
||||
networkAPI.PumpCharacterUpdate(entity)
|
||||
end)
|
||||
@@ -111,7 +111,7 @@ createTrigger("door 1", underworld, 128, -128, function(entity)
|
||||
end
|
||||
|
||||
--move the character
|
||||
characterAPI.SetRoomIndex(entity, uidOne)
|
||||
characterAPI.SetRoom(entity, uidOne)
|
||||
characterAPI.SetOrigin(entity, 0, 0)
|
||||
networkAPI.PumpCharacterUpdate(entity)
|
||||
end)
|
||||
|
||||
@@ -29,15 +29,10 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
static int setRoomIndex(lua_State* L) { //TODO: (0) take the room userdata as a parameter
|
||||
//NOTE: type-dependant calls to various API functions, see bug #43
|
||||
|
||||
static int setRoom(lua_State* L) {
|
||||
//reverse engineer the character index
|
||||
int characterIndex = -1;
|
||||
CharacterData* character = static_cast<CharacterData*>(lua_touserdata(L, 1));
|
||||
int roomIndex = lua_tointeger(L, 2);
|
||||
RoomData* roomData = RoomManager::GetSingleton().Get(roomIndex);
|
||||
|
||||
CharacterManager& characterMgr = CharacterManager::GetSingleton();
|
||||
|
||||
for (auto& it : *characterMgr.GetContainer()) {
|
||||
@@ -52,8 +47,31 @@ static int setRoomIndex(lua_State* L) { //TODO: (0) take the room userdata as a
|
||||
throw(std::runtime_error("Lua Error: Failed to find character index by reference"));
|
||||
}
|
||||
|
||||
//get the room index, depending on the parameter type
|
||||
int roomIndex = -1;
|
||||
RoomManager& roomMgr = RoomManager::GetSingleton();
|
||||
switch(lua_type(L, 2)) {
|
||||
case LUA_TNUMBER:
|
||||
roomIndex = lua_tointeger(L, 2);
|
||||
break;
|
||||
case LUA_TLIGHTUSERDATA:
|
||||
//reverse engineer the room index
|
||||
for (auto& it : *roomMgr.GetContainer()) {
|
||||
if (lua_touserdata(L, 2) == &it.second) {
|
||||
roomIndex = it.first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//error checking
|
||||
if (roomIndex == -1) {
|
||||
throw(std::runtime_error("Lua Error: Failed to find room index by reference"));
|
||||
}
|
||||
|
||||
//send the delete & create messages
|
||||
pumpAndChangeRooms(character, lua_tointeger(L, 2), characterIndex);
|
||||
pumpAndChangeRooms(character, roomIndex, characterIndex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -76,7 +94,7 @@ static int getAvatar(lua_State* L) {
|
||||
}
|
||||
|
||||
static const luaL_Reg characterLib[] = {
|
||||
{"SetRoomIndex", setRoomIndex},
|
||||
{"SetRoom", setRoom},
|
||||
// {"GetOwner", getOwner}, //unusable without account API
|
||||
{"GetHandle", getHandle},
|
||||
{"GetAvatar", getAvatar},
|
||||
|
||||
Reference in New Issue
Block a user