![]() |
|
Player:SetPosition() with SpawnHook in other World - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Plugins (https://forum.cuberite.org/forum-1.html) +--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html) +--- Thread: Player:SetPosition() with SpawnHook in other World (/thread-2958.html) |
Player:SetPosition() with SpawnHook in other World - moiko89 - 05-21-2017 Hi, i used Player:SetPosition() with HOOK_PLAYER_SPAWED Event. But if the player died in WorldX and i used with spawn the Player:SetPosition() command then spawn the player in DefaultWorld and not in WorldX. Why? I used "return true" after Player:SetPosition().
function PlayerSpawned(Player)
local PlayersUUID = Player:GetUUID()
local PlayersCurrentWorld = Player:GetWorld()
local CurrentWorldSettings = WorldBedSetting:getWorldSet(PlayersCurrentWorld)
print("CurrentWorldSettings:", PlayersCurrentWorld:GetName(), CurrentWorldSettings)
local SpawnWorld = cRoot:Get():GetWorld(CurrentWorldSettings.SpawnWorld)
local SpawnWorldSettings = WorldBedSetting:getWorldSet(SpawnWorld)
if (CurrentWorldSettings.BedAllow and PlayersPositions:IsBedActive(Player, PlayersCurrentWorld)) then
print("Bed CurrentWorld: Bed erlaubt & Bed Existiert")
-- if bed esist in this world > Port To Bed
local BedPos = PlayersPositions:GetBed(Player, PlayersCurrentWorld)
print("Bedposition in :" .. PlayersCurrentWorld:GetName(),BedPos.BedPosX, BedPos.BedPosY, BedPos.BedPosZ)
Player:SetPosition(BedPos.BedPosX, BedPos.BedPosY, BedPos.BedPosZ)
return true
elseif (SpawnWorldSettings.BedAllow and PlayersPositions:IsBedActive(Player, SpawnWorld)) then
print("Bed SpawnWorld: Bed erlaubt & Bed Existiert")
-- if bed exist in SpawnWorld > Port to Bed in SpawnWorld
local BedPos = PlayersPositions:GetBed(Player, SpawnWorld)
local spawnpos3d = Vector3d(BedPos.BedPosX, BedPos.BedPosY, BedPos.BedPosZ)
Player:ScheduleMoveToWorld(SpawnWorld,spawnpos3d,false)
return true
else
-- whats spawn method in SpawnWorld
if (SpawnWorldSettings.RandomSpawn == true) then
print("RandomSpawn")
PortToRandomPos(Player,SpawnWorld,PlayersCurrentWorld)
return true
else
print("MapSpawn")
PortToMapSpawn(Player, SpawnWorld, PlayersCurrentWorld)
return true
end
end
return true
end
RE: Player:SetPosition() with SpawnHook in other World - moiko89 - 05-21-2017 Hi i checked the problem. HOOK_PLAYER_SPAWED is after spawn and if exist an active bed in other world, then player was teleport to this world. When i set the players position, i set it on the other world... damn ![]() Can i deactivate the spawn logic from core? [Edit] Ah Stop, if i save the players world at the start from plugin (myworld = Player:GetWorld) and check at the end of the code myworld == Player:GetWorld then i become false. Is my code to slow?
RE: Player:SetPosition() with SpawnHook in other World - moiko89 - 05-23-2017 Anyone can help me? RE: Player:SetPosition() with SpawnHook in other World - NiLSPACE - 05-23-2017 It seems a plugin can't override OnPlayerSpawned. You could try OnKilling instead. RE: Player:SetPosition() with SpawnHook in other World - moiko89 - 05-23-2017 Hm. The Event OnKilling is before OnPlayerSpawned. Therefore, OnPlayerSpawned is triggered after my code and undoes everything. RE: Player:SetPosition() with SpawnHook in other World - moiko89 - 05-24-2017 Now i will try it to implement the KILLED Hook, but how i become the Player Object from "Victim" / cEntity? RE: Player:SetPosition() with SpawnHook in other World - Seadragon91 - 05-24-2017 Code: function MyOnKilled(Victim, TDI, DeathMessage)Check if it's a player then call the functions you want. RE: Player:SetPosition() with SpawnHook in other World - moiko89 - 05-24-2017 (05-24-2017, 02:45 AM)Seadragon91 Wrote: Hi, i need a function for return the player object to do later setLastBedPos() RE: Player:SetPosition() with SpawnHook in other World - NiLSPACE - 05-24-2017 You can save the UUID of the player using Victim:GetUUID(). Later on you can use cRoot:Get():DoWithPlayerByUUID(uuid, function(player) -- use SetLastBedPos here. end); |