Teleport to Spawn if lastBed doesnt exist
#1
I will teleport the Player to WorldSpawn if they lastBed doesnt exist.
But the Player.TeleportToCoords doesnt work for me, i copy the SpawnTeleport Code from plugins/core/spawn.lua


Code:
19:37:01] LUA: Plugins/Test1/main.lua:49: error in function 'TeleportToCoords'.
     argument #1 is 'string'; 'cEntity' expected.

[19:37:01] Stack trace:
[19:37:01]   [C](-1): TeleportToCoords
[19:37:01]   Plugins/Test1/main.lua(49): (no name)
[19:37:01] Stack trace end
[19:37:01] Error in <attached> calling function <callback>()



PHP Code:
PLUGIN nil

function Initialize(Plugin)
    
Plugin:SetName("Test1")
    
Plugin:SetVersion(1)

    -- 
Hooks
    cPluginManager
.AddHook(cPluginManager.HOOK_PLAYER_SPAWNEDOnPlayerSpawned)
    
PLUGIN Plugin -- NOTEonly needed if you want OnDisable() to use GetName() or something like that

    LOG
("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
    return 
true
end

function OnDisable()
    
LOG(PLUGIN:GetName() .. " is shutting down...")
end

function OnPlayerSpawned(Player) -- See API docs for parameters of all hooks
    local lastBedPos 
Player:GetLastBedPos()
    
local world=Player:GetWorld()
    
local block=world:GetBlock(lastBedPos.xlastBedPos.ylastBedPos.z)

    
local WorldIni cIniFile()
    
WorldIni:ReadFile(Player:GetWorld():GetIniFileName())

    
local SpawnX WorldIni:GetValue("SpawnPosition""X")
    
local SpawnY WorldIni:GetValue("SpawnPosition""Y")
    
local SpawnZ WorldIni:GetValue("SpawnPosition""Z")

    if (
block == 26then
        
-- do stuff
    
else
        
Player.TeleportToCoords(SpawnXSpawnYSpawnZ)
    
end
end 
Reply
Thanks given by:


Messages In This Thread
Teleport to Spawn if lastBed doesnt exist - by moiko89 - 05-14-2017, 03:43 AM



Users browsing this thread: 3 Guest(s)