Player:SetPosition() with SpawnHook in other World
#1
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
Reply
Thanks given by:
#2
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... damnBig Grin

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?Confused
Reply
Thanks given by:
#3
Anyone can help me?
Reply
Thanks given by:
#4
It seems a plugin can't override OnPlayerSpawned. You could try OnKilling instead.
Reply
Thanks given by:
#5
Hm. The Event OnKilling is before OnPlayerSpawned. Therefore, OnPlayerSpawned is triggered after my code and undoes everything.
Reply
Thanks given by:
#6
Now i will try it to implement the KILLED Hook, but how i become the Player Object from "Victim" / cEntity?
Reply
Thanks given by:
#7
Code:
function MyOnKilled(Victim, TDI, DeathMessage)
    if Victim:IsPlayer() then
        LOG(Victim:GetName() .. " has been killed, printed by hook.")
    end
end

Check if it's a player then call the functions you want.
Reply
Thanks given by:
#8
(05-24-2017, 02:45 AM)Seadragon91 Wrote:
Code:
function MyOnKilled(Victim, TDI, DeathMessage)
    if Victim:IsPlayer() then
        LOG(Victim:GetName() .. " has been killed, printed by hook.")
    end
end

Check if it's a player then call the functions you want.

Hi,
i need a function for return the player object to do later setLastBedPos()
Reply
Thanks given by:
#9
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);
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)