Posts: 9
Threads: 2
Joined: Oct 2015
Thanks: 4
Given 0 thank(s) in 0 post(s)
Hi!
I have got a minecraft server, and I wanted to disallow certain people from going to a certain (VIP only) area. I made a mockup of the code so anyone is disallowed to move there, just to try it out.
I am trying to disallow movement to -370, 219, 131
function OnPlayerMoving(Player, OldPosition, NewPosition)
World = Player:GetWorld()
if (NewPosition == -370, 219, 131) then
return false
end
I have called the hook OnplayerMoving.
Can anyone help me, I am a total newb at lua and wanted to try making a plugin.
PS I am writing on top of a plugins called Jobs for now, as it havge things related to what I want to do. (Although I think it needs updating).
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
Hello and welcome to the forum
If you want to stop a player from moving you have to return true, not false.
Also, the NewPosition is a Vector3d variable. What you could do is use this:
if (NewPosition:Equals(Vector3d(-370, 219, 131))) then
return true
end
Also notice the "end" to mark the end of the if block.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
The main problem with this approach is that you're basically blocking access to a single point in space. Normally you would want to restrict an entire area, the cBoundingBox class might help you a lot here: http://apidocs.cuberite.org/cBoundingBox.html
(your code prohibits the player from moving to {-370, 219, 131}, but it doesn't prohibit from moving to {-370, 219.0001, 131} )
Posts: 350
Threads: 18
Joined: Oct 2014
Thanks: 26
Given 54 thank(s) in 47 post(s)
Just throwing an example out there, I even had trouble with this at one point:
-- Lets define a box around 0, 70, 0 thats about 3 cubes big, just for this example.
-- Construct a box using opposite points defined as a min and max Vector3d
local VIPBox = cBoundingBox(Vector3d(-3, 67, -3), Vector3d(3, 73, 3))
-- Lets use the OnPlayerMoving hook to check if they are attempting to enter
function OnPlayerMoving(Player, OldPos, NewPos)
-- Check if the position that will jump to next is inside the box
if VIPBox:IsInside(NewPos) then
-- Tell the server that this plugin has handled the player's movement and do not let the server advance the player
return true
end
end
Posts: 9
Threads: 2
Joined: Oct 2015
Thanks: 4
Given 0 thank(s) in 0 post(s)
(11-09-2015, 08:32 AM)xoft Wrote: The main problem with this approach is that you're basically blocking access to a single point in space. Normally you would want to restrict an entire area, the cBoundingBox class might help you a lot here: http://apidocs.cuberite.org/cBoundingBox.html
(your code prohibits the player from moving to {-370, 219, 131}, but it doesn't prohibit from moving to {-370, 219.0001, 131} )
Thanks, I though that was the issue
Posts: 9
Threads: 2
Joined: Oct 2015
Thanks: 4
Given 0 thank(s) in 0 post(s)
I have almost exactly copied you code:
local bblock = cBoundingBox(Vector3d(-372, 218, 131), Vector3d(-377, 220, 130))
function OnPlayerMoving(Player, OldPosition, NewPosition)
World = Player:GetWorld()
if bblock:IsInside(NewPosition) then
return true
end
end
I don`t really know what the issue is here, nothing happens when I enter the area
(I even tried giving myself default rank)
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
You did register the hook using cPluginManager:AddHook right?
Posts: 9
Threads: 2
Joined: Oct 2015
Thanks: 4
Given 0 thank(s) in 0 post(s)
Job = {}
function Initialize(Plugin)
Plugin:SetName("Jobs")
Plugin:SetVersion(1)
cPluginManager.BindCommand("/jobs", "jobs.jobs", HandleJobsCommand, " - Join, browse or leave jobs.");
cPluginManager.AddHook(cPluginManager.HOOK_BLOCK_TO_PICKUPS, OnBlockToPickups)
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_PLACING_BLOCK, OnPlayerPlacingBlock)
cPluginManager.AddHook(cPluginManager.HOOK_KILLING, OnKilling)
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_BROKEN_BLOCK, OnPlayerBrokenBlock)
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_FISHING, OnPlayerFishing)
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_JOINED, OnPlayerJoined)
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_MOVING, OnPlayerMoving)
PM = cPluginManager
UsersIni = cIniFile()
UsersIni:ReadFile("jobs.ini")
local CheckJob = function(Player)
Job[Player:GetName()] = UsersIni:GetValue(Player:GetUUID(), "Job")
end
cRoot:Get():ForEachPlayer(CheckJob)
LOG("Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
return true
end
I think this is ok
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
Yes, that looks normal. Perhaps you have defined OnPlayerMoving somewhere else as well?
Posts: 350
Threads: 18
Joined: Oct 2014
Thanks: 26
Given 54 thank(s) in 47 post(s)
(11-14-2015, 01:25 AM)Bobstergaming Wrote:
Job = {}
function Initialize(Plugin)
Plugin:SetName("Jobs")
Plugin:SetVersion(1)
cPluginManager.BindCommand("/jobs", "jobs.jobs", HandleJobsCommand, " - Join, browse or leave jobs.");
cPluginManager.AddHook(cPluginManager.HOOK_BLOCK_TO_PICKUPS, OnBlockToPickups)
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_PLACING_BLOCK, OnPlayerPlacingBlock)
cPluginManager.AddHook(cPluginManager.HOOK_KILLING, OnKilling)
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_BROKEN_BLOCK, OnPlayerBrokenBlock)
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_FISHING, OnPlayerFishing)
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_JOINED, OnPlayerJoined)
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_MOVING, OnPlayerMoving)
PM = cPluginManager
UsersIni = cIniFile()
UsersIni:ReadFile("jobs.ini")
local CheckJob = function(Player)
Job[Player:GetName()] = UsersIni:GetValue(Player:GetUUID(), "Job")
end
cRoot:Get():ForEachPlayer(CheckJob)
LOG("Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
return true
end
I think this is ok
Watch out when you call cPluginManager, you should use cPluginManager:AddHook instead of cPluginManager.AddHook, note the colon.
|