![]() |
Teleport to Spawn if lastBed doesnt exist - 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: Teleport to Spawn if lastBed doesnt exist (/thread-2946.html) Pages:
1
2
|
Teleport to Spawn if lastBed doesnt exist - moiko89 - 05-14-2017 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'. PHP Code: PLUGIN = nil RE: Teleport to Spawn if lastBed doesnt exist - xoft - 05-14-2017 The error message basically says it all. You're calling TeleportToCoords with wrong arguments, it expects a cEntity as its first parameter, but you're giving it a string. Note that in Lua, there are two "calling conventions": obj.fn("a") -- calls obj.fn with param "a" obj:fn("a") -- calls obj.fn with params obj, "a" The second is what Cuberite is using everywhere and is expecting from the plugins. The SpawnX/Y/Z need to be read with a GetValueI() function, so that they are numbers, not strings. RE: Teleport to Spawn if lastBed doesnt exist - xoft - 05-14-2017 One more friendly advice: Use E_BLOCK_BED instead of 26. RE: Teleport to Spawn if lastBed doesnt exist - Seadragon91 - 05-14-2017 A list of block, item ids and more constants can you find here Globals RE: Teleport to Spawn if lastBed doesnt exist - moiko89 - 05-14-2017 If i use PHP Code: local SpawnX = WorldIni:GetValueI("SpawnPosition", "X") i become this msg Code: [20:06:37] LUA: Plugins/Test1/main.lua:27: attempt to call method 'GetValuelI' (a nil value) can you give me an example? RE: Teleport to Spawn if lastBed doesnt exist - Seadragon91 - 05-14-2017 Do you want to read the spawn position from the world ini? If yes you could directly use the functions: GetSpawnX, GetSpawnY and GetSpawnZ from cWorld. if not about world spawn.The error means that WorldIni is not initialized. Post the code where you are initializing WorldIni. Edit: Ah sorry didn't saw the whole code in first post, will look at it. RE: Teleport to Spawn if lastBed doesnt exist - moiko89 - 05-14-2017 (05-14-2017, 04:22 AM)Seadragon91 Wrote: Do you want to read the spawn position from the world ini? Server Start Log Code: [20:41:41] --- Started Log --- Code with GetSpawn PHP Code: local SpawnX = world:GetSpawnX() Error with GetSpawn Code: [20:39:31] WorldSpawnX:-2.1523170155827 WorldSpawnY:65 WorldSpawnZ:-32.89404058136 What i can do? ![]() RE: Teleport to Spawn if lastBed doesnt exist - Seadragon91 - 05-14-2017 Change Player.TeleportToCoords(SpawnX, SpawnY, SpawnZ) to Player:TeleportToCoords(SpawnX, SpawnY, SpawnZ) Has to be a colon : RE: Teleport to Spawn if lastBed doesnt exist - moiko89 - 05-14-2017 (05-14-2017, 04:45 AM)Seadragon91 Wrote: Change Waaah.... now i see the different in xoft's post too..... obj.fn("a") -- calls obj.fn with param "a" obj:fn("a") -- calls obj.fn with params obj, "a" I understand... thanks ![]() RE: Teleport to Spawn if lastBed doesnt exist - xoft - 05-14-2017 I'm quite concerned with the "GetValuelI" not found, even with the INI file not read, the method should be there. |