Disallowed movement
#1
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

1
2
3
4
5
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).
Reply
Thanks given by:
#2
Hello and welcome to the forum Smile

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:
1
2
3
if (NewPosition:Equals(Vector3d(-370, 219, 131))) then
   return true
end

Also notice the "end" to mark the end of the if block.
Reply
Thanks given by:
#3
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} )
Reply
Thanks given by: Bobstergaming
#4
Just throwing an example out there, I even had trouble with this at one point:

1
2
3
4
5
6
7
8
9
10
11
12
13
-- 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
Reply
Thanks given by: Bobstergaming
#5
(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
Reply
Thanks given by:
#6
I have almost exactly copied you code:
1
2
3
4
5
6
7
8
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)
Reply
Thanks given by:
#7
You did register the hook using cPluginManager:AddHook right?
Reply
Thanks given by:
#8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
Reply
Thanks given by:
#9
Yes, that looks normal. Perhaps you have defined OnPlayerMoving somewhere else as well?
Reply
Thanks given by:
#10
(11-14-2015, 01:25 AM)Bobstergaming Wrote:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)