Jump to content

Gate automatic open


Recommended Posts

Hey!

I have looked in the wiki, but I don't know what to do...

I am a beginning scripter, and I am editting scripts...

I have a question, maybe someone can do it for me...

This is one gate:

function onstartup () 
   gate = createObject ( 975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) 
end 
addEventHandler ( "onResourceStart", getRootElement(), onstartup ) 
  
function move () 
  moveObject ( gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) 
end 
addCommandHandler("1", move) 
  
function move () 
  moveObject ( gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) 
end 
addCommandHandler("2", move) 
  
s1 = createMarker( -1529, 490, 7, "cylinder", 13.5, 255, 255, 255, 0) 
s2 = createBlip( 1438.7745361328, -2938.0595703125, 2.8496370315552,62) 
  
  

Now i want that the gate automatic open if there is a player, and automatic close if the player is leaving...

Now its open by /1

And closing by /2

Maybe someone can do this, and explain what he have done so I can do it the next time by myself...

Regards,

Nick

Link to comment
local gate = createObject ( 975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) 
local marker = createMarker(1438.1025390625, -2879.2116699219, 2.5887410640717, "cylinder", 6, 255, 255, 255, 0) 
  
function moveGate(hitPlayer, matchingDimension) 
    if hasObjectPermissionTo(hitPlayer, "function.kickPlayer") then 
        moveObject ( gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) 
        setTimer(moveBack, 2000, 1) 
    end 
end 
addEventHandler("onMarkerHit", marker, moveGate) 
  
function moveBack() 
    moveObject ( gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) 
end 
   
    s1 = createMarker( -1529, 490, 7, "cylinder", 13.5, 255, 255, 255, 0) 
    s2 = createBlip( 1438.7745361328, -2938.0595703125, 2.8496370315552,62) 
      
      

Problem, if he open, he closed after 0.5 seconds...

(I had look at a other script, and so I edit c:)

The problem is...

I can edit the timer, but I want that he close if the player is away...

EDIT:

I have now this:

local gate = createObject ( 975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) 
local marker = createMarker(1438.1025390625, -2865.44531, 2.5887410640717, "cylinder", 6, 255, 255, 255, 0) 
  
function moveGate(hitPlayer, matchingDimension) 
    if hasObjectPermissionTo(hitPlayer, "function.kickPlayer") then 
        moveObject ( gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) 
        setTimer(moveBack, 4000, 1) 
    end 
end 
addEventHandler("onMarkerHit", marker, moveGate) 
  
function moveBack() 
    moveObject ( gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) 
end 
   
    s1 = createMarker( -1529, 490, 7, "cylinder", 13.5, 255, 255, 255, 0) 
    s2 = createBlip( 1438.7745361328, -2938.0595703125, 2.8496370315552,62) 
      
      

But the second problem...

I can't go out anymore, because there isn't a marker xD...

Link to comment
local gate = createObject ( 975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) 
local marker = createMarker(1438.1025390625, -2865.44531, 2.5887410640717, "cylinder", 6, 255, 255, 255, 0) 
local marker2 = createMarker(1438.1025390625, -2886.79980, 2.5887410640717, "cylinder", 6, 255, 255, 255, 0) 
  
function moveGate(hitPlayer, matchingDimension) 
    if hasObjectPermissionTo(hitPlayer, "function.kickPlayer") then 
        moveObject ( gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) 
        setTimer(moveBack, 4000, 1) -- the gate will closes in 4 seconds 
    end 
end 
addEventHandler("onMarkerHit", marker, moveGate) 
addEventHandler("onMarkerHit", marker2, moveGate) 
  
    function moveBack() 
        moveObject ( gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) 
    end 
  
  
    s1 = createMarker( -1529, 490, 7, "cylinder", 13.5, 255, 255, 255, 0) 
    s2 = createBlip( 1438.7745361328, -2938.0595703125, 2.8496370315552,62) 
      

Edited by Guest
Link to comment

I have now this, thanks to Stuvi:

local gate = createObject ( 975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) 
local marker = createMarker(1438.1025390625, -2865.44531, 2.5887410640717, "cylinder", 6, 255, 255, 255, 0) 
local marker2 = createMarker(1438.1025390625, -2886.79980, 2.5887410640717, "cylinder", 6, 255, 255, 255, 0) 
  
function moveGate(hitPlayer, matchingDimension) 
    if hasObjectPermissionTo(hitPlayer, "function.kickPlayer") then 
        moveObject ( gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) 
    end 
end 
addEventHandler("onMarkerHit", marker, moveGate) 
addEventHandler("onMarkerHit", marker2, moveGate) 
  
    function moveBack() 
        moveObject ( gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) -- move back when the player leaves the marck 
    end 
    addEventHandler("onMarkerLeave", marker, moveBack) 
addEventHandler("onMarkerLeave", marker2, moveBack) 
   
    s1 = createMarker( -1529, 490, 7, "cylinder", 13.5, 255, 255, 255, 0) 
    s2 = createBlip( 1438.7745361328, -2938.0595703125, 2.8496370315552,62) 
      

But the marker is little bit away from the gate...

But now is the problem, the gate closed to early...

So i can't ride thougt the gate, because he is already closing :')

Link to comment
Copy my code again, about the marker you can change the position to near the gate

I know, but i want that the marker a little bit away from the gate (see my script) so the gate is opening...

But if you leave the marker is closing :P

Link to comment

I think this is the best option:

  
local gate = createObject ( 975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) 
    local marker = createMarker(1438.1025390625, -2874.20654, 2.5887410640717, "cylinder", 6, 255, 255, 255, 0) 
     setMarkerSize ( marker, 11.5 ) 
      
    function moveGate(hitPlayer, matchingDimension) 
        if hasObjectPermissionTo(hitPlayer, "function.kickPlayer") then 
            moveObject ( gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) 
        end 
    end 
    addEventHandler("onMarkerHit", marker, moveGate) 
      
    function moveBack() 
        moveObject ( gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) 
    end 
    addEventHandler("onMarkerLeave", marker, moveBack) 
      
        s1 = createMarker( -1529, 490, 7, "cylinder", 13.5, 255, 255, 255, 0) 
        s2 = createBlip( 1438.7745361328, -2938.0595703125, 2.8496370315552,62) 
          
          

Link to comment

Hold on, it's better to have it fully functioning without bugs, use this code.

local gate = createObject(975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) 
local marker = createMarker(1438.1025390625, -2874.20654, 2.5887410640717, "cylinder", 11.5, 255, 255, 255, 0) 
local s2 = createBlip(1438.7745361328, -2938.0595703125, 2.8496370315552, 62) 
local moving = false 
  
addEventHandler("onMarkerHit", marker, 
    function moveGate(hitElement, matchingDimension) 
        if getElementType(hitElement) == "player" and matchingDimension then 
            if hasObjectPermissionTo(hitElement, "function.kickPlayer") then 
                if moving ~= true then 
                    moveObject(gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) 
                    moving = true 
                end 
            end 
        end 
    end 
) 
  
addEventHandler("onMarkerLeave", marker, 
    function moveBack(leaveElement, matchingDimension) 
        if moving ~= false then 
            if matchingDimension then 
                moveObject(gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) 
                moving = false 
            end 
        end 
    end 
) 

Link to comment

Now i have:

[2012-06-09 20:36:20] Starting night_club

[2012-06-09 20:36:20] SCRIPT ERROR: night_club\gate.lua:7: '(' expected near 'moveGate'

[2012-06-09 20:36:20] WARNING: Loading script failed: night_club\gate.lua:7: '(' expected near 'moveGate'

[2012-06-09 20:36:20] night_club restarted successfully

Link to comment

Not exactly. Function names aren't allowed when the function is made inside an event.

local gate = createObject(975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) 
local marker = createMarker(1438.1025390625, -2874.20654, 2.5887410640717, "cylinder", 11.5, 255, 255, 255, 0) 
local s2 = createBlip(1438.7745361328, -2938.0595703125, 2.8496370315552, 62) 
local moving = false 
  
addEventHandler("onMarkerHit", marker, 
    function(hitElement, matchingDimension) 
        if getElementType(hitElement) == "player" and matchingDimension then 
            if hasObjectPermissionTo(hitElement, "function.kickPlayer") then 
                if moving ~= true then 
                    moveObject(gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) 
                    moving = true 
                end 
            end 
        end 
    end 
) 
  
addEventHandler("onMarkerLeave", marker, 
    function(leaveElement, matchingDimension) 
        if moving ~= false then 
            if matchingDimension then 
                moveObject(gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) 
                moving = false 
            end 
        end 
    end 
) 

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