Jump to content

[Question] Destroy vehicle onMouseClick


kieran

Recommended Posts

I am trying to make a script for admins so they can destroy vehicles with mouse click, just in case they can not enter vehicle as it might be close to walls either side, the problems I am having are one, the vehicle does not get removed, and 2, I get an error when I try it as admin.

 

function AdminCarRemoval ( button, state, player ) 
    if isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ( "admin" ) ) then
		if getElementType == "vehicle" then 
			if button == "left" and state == "down" then
				destroyElement ()
			end
		end
	end
end
addEventHandler( "onElementClicked", getRootElement( ), AdminCarRemoval ) 

^Yes, I have set it server side^

 

Error: test\destroy_veh.lua:2: attempt to concatenate global 'accountname' (a nil value)

Edited by kieran
Link to comment
17 minutes ago, pa3ck said:

The error kinda explains itself, where is accountname defined? You forgot the line 


local accountname = getAccountName(getPlayerAccount(player))

 

It still says [2017-06-20 23:32:27] WARNING: test\destroy_veh.lua:3: Bad argument @ 'isObjectInACLGroup' [Expected acl-group at argument 2, got Booleani

 

	local accountname = getAccountName(getPlayerAccount(player)) 
	if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "admin" ) ) then --is now line 3. 

 There's still however the small issue of actually deleting the element xD even without the admin part it does not see the element being clicked, just the mouse click itself... :/ 

Link to comment
function AdminCarRemoval ( button, state, player ) 
	if ( button == "left" and state == "down" ) then
		if ( isElement(source) ) and ( getElementType(source) == "vehicle" ) then 
			if ( isGuestAccount(getPlayerAccount(player)) ) then return end
			if ( aclGetGroup ( "Admin" ) ) and ( isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(player)), aclGetGroup ( "Admin" ) ) ) then
				destroyElement (source)
				outputChatBox('Successfully destroyed the vehicle.',player,255,255,0,true)
			end
		end
	end
end
addEventHandler( "onElementClicked", getRootElement( ), AdminCarRemoval ) 

 

Make sure the first letter of the group name must be capital. ( usually its capital letter )

Edited by !#NssoR_)
  • Like 1
Link to comment

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...