Jump to content

simple gate script + account feature


Deep thinker

Recommended Posts

hi ,i have scripted a gate depending on account name , but i have started it ,it creates the marker and the object but the object isn't moving 

door = createObject ( 3089, 2004.5 , -1280 , 36.900001525879 , 0, 0, 0 )
marker = createMarker ( 2005.5 , -1280 , 35.900001525879 , 'cylinder', 1, 0, 0, 0, 255 )
-- after creating
function openForProMax()
   local thePlayer = getAccountPlayer ( promax )       -- get the client attached to the account
   if ( getElementType ( thePlayer ) == "player" ) then   
    moveObject ( door,2000, 2004.5 , -1280 , 30.900001525879, 0, 0, 0 )
	else
	return
    end
end    
addEventHandler ( 'onMarkerHit', marker, openForProMax )
 
function closeAfterProMax()
moveObject ( door,2000, 2004.5 , -1280 , 36.900001525879, 0, 0, 0 )
end
addEventHandler ( 'onMarkerLeave', marker, closeAfterProMax )

 

Link to comment
1 hour ago, ProMax said:

local thePlayer = getAccountPlayer ( promax )

promax isn't a defined variable also you're trying to get the account not the name.

I think you're looking for this;

door = createObject (3089, 2004.5 , -1280 , 36.9 , 0, 0, 0)
marker = createMarker ( 2005.5 , -1280 , 35.9 , 'cylinder', 1, 0, 0, 0, 255)
-- after creating
function moveGate(hitElement, time, targetX, targetY, targetZ, moveRX, moveRY, moveRZ)
	if (getElementType(hitElement) == "player") then
    	if (getPlayerName(hitElement) == "promax" then
    		moveObject ( door, time, targetX, targetY , targetZ, moveRX, moveRY, moveRZ)
        else return end
	else return end
end

addEventHandler ( 'onMarkerHit', marker, function(hitElement)
	moveGate(hitElement, 2000, 2004.5 , -1280 , 30.9, 0, 0, 0)
end)

addEventHandler ( 'onMarkerLeave', marker, function(hitElement)
	moveGate(hitElement ,2000, 2004.5 , -1280 , 36.9, 0, 0, 0)
end)

I changed the use of 2 function which do the same and made them use parameters, first you check if the hitelement is a player then you check if the name is equal to the string.

i've also cleaned up the long coordinates btw xxx.9000000000xx doesn't matter, just make it xxx.9

 

(Not tested, just written) Kind regards

Link to comment
door = createObject ( 3089, 2004.5 , -1280 , 36.900001525879 , 0, 0, 0 )
marker = createMarker ( 2005.5 , -1280 , 35.900001525879 , 'cylinder', 1, 0, 0, 0, 255 )
-- after creating
function openForProMax(thePlayer)
   local account = getPlayerAccount(thePlayer)
   if ( getElementType ( thePlayer ) == "player" ) then   
      if account == "promax" then
         moveObject ( door,2000, 2004.5 , -1280 , 30.900001525879, 0, 0, 0 )
	 else
	    return
     end
   end
end    
addEventHandler ( 'onMarkerHit', marker, openForProMax )
 
function closeAfterProMax()
moveObject ( door,2000, 2004.5 , -1280 , 36.900001525879, 0, 0, 0 )
end
addEventHandler ( 'onMarkerLeave', marker, closeAfterProMax )

 

Edited by Dimos7
Link to comment
38 minutes ago, Dimos7 said:

door = createObject ( 3089, 2004.5 , -1280 , 36.900001525879 , 0, 0, 0 )
marker = createMarker ( 2005.5 , -1280 , 35.900001525879 , 'cylinder', 1, 0, 0, 0, 255 )
-- after creating
function openForProMax(thePlayer)
   local account = getPlayerAccount(thePlayer)
   if ( getElementType ( thePlayer ) == "player" ) then   
      if account == "promax" then
         moveObject ( door,2000, 2004.5 , -1280 , 30.900001525879, 0, 0, 0 )
	 else
	    return
     end
   end
end    
addEventHandler ( 'onMarkerHit', marker, openForProMax )
 
function closeAfterProMax()
moveObject ( door,2000, 2004.5 , -1280 , 36.900001525879, 0, 0, 0 )
end
addEventHandler ( 'onMarkerLeave', marker, closeAfterProMax )

 

That won't work, I can see an error without trying "attempting to compare player data with string" 

 

getPlayerAccount

Returns the player's account object, or false if the player passed to the function is invalid.

Link to comment
door = createObject ( 3089, 2004.5 , -1280 , 36.900001525879 , 0, 0, 0 )
marker = createMarker ( 2005.5 , -1280 , 35.900001525879 , 'cylinder', 1, 0, 0, 0, 255 )
-- after creating
function openForProMax(thePlayer)
   local account = getPlayerAccount(thePlayer)
   if ( getElementType ( thePlayer ) == "player" ) then   
      if getAccountName(account) == "promax" then
         moveObject ( door,2000, 2004.5 , -1280 , 30.900001525879, 0, 0, 0 )
	 else
	    return
     end
   end
end    
addEventHandler ( 'onMarkerHit', marker, openForProMax )
 
function closeAfterProMax()
moveObject ( door,2000, 2004.5 , -1280 , 36.900001525879, 0, 0, 0 )
end
addEventHandler ( 'onMarkerLeave', marker, closeAfterProMax )

yes i forget that sorry fast type mistake

Link to comment

So I tested my code (changed to work with account name now) and it does work, but I hope it's ment to be a door in the air.

Else check your coordinates.

Clipboardimage2016-12-03133208.png

 

Spoiler

door = createObject (3089, 2004.5 , -1280 , 36.9 , 0, 0, 0)
marker = createMarker (2005.5, -1280, 35.9, 'cylinder', 1, 0, 0, 0, 255)
-- after creating
function moveGate(hitElement, time, targetX, targetY, targetZ, moveRX, moveRY, moveRZ)
	if (getElementType(hitElement) == "player") then
      local thePlayer = getPlayerAccount(hitElement)
    	if (thePlayer and getAccountName(thePlayer) == "NAMEHERE") then
    		moveObject ( door, time, targetX, targetY , targetZ, moveRX, moveRY, moveRZ)
      end
	end
end

addEventHandler ( 'onMarkerHit', marker, function(hitElement)
	moveGate(hitElement, 2000, 2004.5 , -1280 , 30.9, 0, 0, 0)
end)

addEventHandler ( 'onMarkerLeave', marker, function(hitElement)
	moveGate(hitElement ,2000, 2004.5 , -1280 , 36.9, 0, 0, 0)
end)

 

 

Link to comment

If i'm right the panel is accessible by F1 press and by typing "/fr"

In fr_client.lua@Line1620 there's the function that shows (and hide) the panel. Insert the needed checks here.

Another solution would be adding an handler on both keypress and on the chat event (i don't remember the name... onPlayerChat maybe) with a very high priority, cancelling the event. But i'm not sure if the event will still be triggered if the other handlers do not check if the event was cancelled

Link to comment
On ٣‏/١٢‏/٢٠١٦ at 9:16 PM, LoPollo said:

If i'm right the panel is accessible by F1 press and by typing "/fr"

In fr_client.lua@Line1620 there's the function that shows (and hide) the panel. Insert the needed checks here.

Another solution would be adding an handler on both keypress and on the chat event (i don't remember the name... onPlayerChat maybe) with a very high priority, cancelling the event. But i'm not sure if the event will still be triggered if the other handlers do not check if the event was cancelled

function toggleFRWindow()
if isPlayerInACL(thePlayer, "Admin") then
    if isWindowOpen(wndMain) then
        showCursor(false)
        hideAllWindows()
        colorPicker.closeSelect()
        else
            showCursor(true)
            showAllWindows()
    end
end
end
addCommandHandler('fr', toggleFRWindow)

failed :3

Link to comment
thePlayer

Is not defined,

isPlayerInACL

Could be defined, but I'm not to sure

https://wiki.multitheftauto.com/wiki/IsPlayerInACL

 

function toggleFRWindow(thePlayer)
local accName = getAccountName ( getPlayerAccount ( thePlayer ) )
if isObjectinACL("user."..accName, "Admin") then
    if isWindowOpen(wndMain) then
        showCursor(false)
        hideAllWindows()
        colorPicker.closeSelect()
        else
            showCursor(true)
            showAllWindows()
    end
end
end
addCommandHandler('fr', toggleFRWindow)
Link to comment

 

isPlayerInACL

Needs the function as well

function isPlayerInACL ( player, acl )
	local account = getPlayerAccount ( player )
	if ( isGuestAccount ( account ) ) then
		return false
	end
        return isObjectInACLGroup ( "user."..getAccountName ( account ), aclGetGroup ( acl ) )
end

which is server sided and the code you have is, I guess, client sided so you need a trigger.

On 3-12-2016 at 8:16 PM, LoPollo said:

 fr_client.lua@Line1620

@CodyL I suppose client sided because of the file name

Link to comment

Did not notice that,

Open = false

function toggleFRWindow(thePlayer)
local accName = getAccountName ( getPlayerAccount ( thePlayer ) )
if isObjectinACL("user."..accName, "Admin") then
    if Open then
	Open = false
        showCursor(thePlayer,false)
        triggerClientEvent ( thePlayer, "OpenOrClose", thePlayer,false)
        colorPicker.closeSelect()
        else
	Open = true
        showCursor(thePlayer,true)
        triggerClientEvent ( thePlayer, "OpenOrClose", thePlayer,true)
    end
end
end
addCommandHandler('fr', toggleFRWindow)

Client -

function OpenOrCloseClient(Open)
if Open then 
showAllWindows()
else
hideAllWindows()
colorPicker.closeSelect()
end
end

addEvent( "OpenOrClose", true )
addEventHandler( "OpenOrClose", localPlayer, OpenOrCloseClient )

 

Not tested, was just a quick thing I made.

Link to comment
13 hours ago, CodyL said:

Did not notice that,


Open = false

function toggleFRWindow(thePlayer)
local accName = getAccountName ( getPlayerAccount ( thePlayer ) )
if isObjectinACL("user."..accName, "Admin") then
    if Open then
	Open = false
        showCursor(thePlayer,false)
        triggerClientEvent ( thePlayer, "OpenOrClose", thePlayer,false)
        colorPicker.closeSelect()
        else
	Open = true
        showCursor(thePlayer,true)
        triggerClientEvent ( thePlayer, "OpenOrClose", thePlayer,true)
    end
end
end
addCommandHandler('fr', toggleFRWindow)

Client -


function OpenOrCloseClient(Open)
if Open then 
showAllWindows()
else
hideAllWindows()
colorPicker.closeSelect()
end
end

addEvent( "OpenOrClose", true )
addEventHandler( "OpenOrClose", localPlayer, OpenOrCloseClient )

 

Not tested, was just a quick thing I made.

 
 
 

 

Mother of indentation.. press "Tab" once a while.

 

http://pastebin.com/Y9ri2wxi

 

Edited by gSub
typo
  • Like 2
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...