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_SPAWNED, OnPlayerSpawned) PLUGIN = Plugin -- NOTE: only 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.x, lastBedPos.y, lastBedPos.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 == 26) then -- do stuff else Player.TeleportToCoords(SpawnX, SpawnY, SpawnZ) 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: 1 Guest(s)