#include "vaultscript.h" #include <unordered_map> #include <tuple> using namespace vaultmp; std::unordered_map<String, std::tuple<Cell, Value, Value, Value>> playerPos; Void VAULTSCRIPT OnPlayerDisconnect(ID player, Reason reason) noexcept { // Get player name (the key for the position store) String name = GetName(player); // Clear player position playerPos.erase(name); // Get the player position Value X, Y, Z; GetPos(player, X, Y, Z); // Get the player cell Cell cell = GetCell(player); // Save the player position playerPos.emplace(name, std::make_tuple(cell, X, Y, Z)); } Void VAULTSCRIPT OnSpawn(ID object) noexcept { // Player object Player player(object); if (player) { String name = player.GetName(); // If there is position data for that name, set it if (playerPos.count(name)) { // Using SetCell so it also works for interiors player.SetCell(std::get<0>(playerPos[name]), std::get<1>(playerPos[name]), std::get<2>(playerPos[name]), std::get<3>(playerPos[name])); // Remove the data so it doesn't set the position on any further spawn playerPos.erase(name); } } }
Created by Last edited by , 09-01-2012 at 05:10 PM 0 Comments, 1,633 Views |
, 09-01-2012 at 05:09 PM