Jump to content

[HELP] Frozen door

Recommended Posts

Well, could someone help me make a script to leave a frozen door preventing it from being opened and making it defrost by a bind.
Only people who are in the Group / ACL would be able to open and close the door. If anyone can help me...

Link to post
-- to set the door frozen, you can use setElementFrozen.

local object = createObject(1499, 20, 30, 2.1)

function freezeDoor()
	setElementFrozen(object, true)

-- you can use bindKey() to toggle it.
-- https://wiki.multitheftauto.com/wiki/BindKey

-- you can use if statement for hasObjectPermissionTo() and create a colshape if the player is in distance to check if he has permission to open the door or not.
-- https://wiki.multitheftauto.com/wiki/HasObjectPermissionTo


Link to post


This is server side and it's never been tested. It's a frame work you can build off of. If you need help feel free to ask

Also please put <oop>true</oop> in the meta.xml file


local distanceFromDoor = 20
local key = 'L'

local Doors = {}
Doors.__index = Doors

local collection = {}

function Door.new(objectid, x, y, z, rx, ry, rz, locked)
    if objectid and x and y and z then
        local self = setmetatable({},Door)
		self.id = objectid
		self.position =  Vector3( x, y, z )
		self.rotation = Vector3 ( rx, ry, rz ) or Vector3 ( 0, 0, 0 )
		self.locked = locked or false
		self.obj = Object( self.id, self.position, self.rotation )
		collection[#collection+1] = self
		return self

function doorToggle(door)
	door.locked = not door.locked

	for i=1,#collection do 
	    if collection[i].locked then
		for e, plr in pairs(getElementsByType('player')) do 
			local distance = getDistanceBetweenPoints3D(plr.position, collection[i].position)
			if distance < distanceFromDoor then
			    bindKey(plr, key, 'down', doorToggle, collection[i])
				unbindKey(plr, key, 'down' doorToggle, collection[i])
end, 50, 0)




local mydoor = Door.new( 1499,0 , 0, 3 )-- create the door
mydoor.locked = true-- lock the door
mydoor.locked = false-- unlock the door


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...