Jump to content

Some error in barriers and marker, please help


jingzhi

Recommended Posts

local barrier = createObject(2920,1544.5996,-1623.9502,13.1,90,0,0) 
local barriermarker = createMarker(1544.88757,-1627.26501,12.7,"cylinder",8,_,_,_,255) 
  
  
function opengate(barriermarker) 
  
         
  
       moveObject(barrier,3000,1544.5996,-1623.9502,13.2,-90) 
              outputChatBox("true") 
            destroyElement(barriermarker) 
           setTimer(moveObject,7500,1,barrier,2600,1544.5996,-1623.9502,13.1,90) 
             local barriermarker = setTimer(createMarker,11000,1,1544.88757,-1627.26501,12.7,"cylinder",8,_,_,_,0) 
  
     
      end 
      addEventHandler("onPlayerMarkerHit",resourceRoot,opengate) 
  
      function barriernotbreakable() 
      triggerClientEvent("setbarriernotbreakable",resourceRoot,barrier) 
      end 
  
      addEventHandler("onResourceStart",getRootElement(),barriernotbreakable) 
  

Client

addEvent("setbarriernotbreakable",true) 
function setbarriernotbreakable() 
setObjectBreakable(barrier,false) 
end 
  
addEventHandler("setbarriernotbreakable",resourceRoot,setbarriernotbreakable) 

If i set the element attached of the eventhandler is getRootElement(), player hit any marker will start this function. If i set the element attached to marker it self, when i hit barrier marker nothing happens. please help :)

Link to comment

The first argument should be the marker that the player hit, so you need to check if the marker hit by the player is the barriermarker. Your code simply "masks" the global barriermarker with a local one that refers to the marker hit by the player.

So you need to change "barriermarker" in "opengate" function to "marker" (or any other name but not "barriermarker") and then comparing it to "barriermarker"

local barrier = createObject(2920,1544.5996,-1623.9502,13.1,90,0,0) 
local barriermarker = createMarker(1544.88757,-1627.26501,12.7,"cylinder",8,_,_,_,255) 
  
  
function opengate(marker) 
 if (not isElement(marker) or marker ~= barriermarker) then return end 
        
  
       moveObject(barrier,3000,1544.5996,-1623.9502,13.2,-90) 
              outputChatBox("true") 
            destroyElement(barriermarker) 
           setTimer(moveObject,7500,1,barrier,2600,1544.5996,-1623.9502,13.1,90) 
             local barriermarker = setTimer(createMarker,11000,1,1544.88757,-1627.26501,12.7,"cylinder",8,_,_,_,0) 
  
    
      end 
      addEventHandler("onPlayerMarkerHit",resourceRoot,opengate) 
  
      function barriernotbreakable() 
      triggerClientEvent("setbarriernotbreakable",resourceRoot,barrier) 
      end 
  
      addEventHandler("onResourceStart",getRootElement(),barriernotbreakable) 
  

Link to comment
The first argument should be the marker that the player hit, so you need to check if the marker hit by the player is the barriermarker. Your code simply "masks" the global barriermarker with a local one that refers to the marker hit by the player.

So you need to change "barriermarker" in "opengate" function to "marker" (or any other name but not "barriermarker") and then comparing it to "barriermarker"

local barrier = createObject(2920,1544.5996,-1623.9502,13.1,90,0,0) 
local barriermarker = createMarker(1544.88757,-1627.26501,12.7,"cylinder",8,_,_,_,255) 
  
  
function opengate(marker) 
 if (not isElement(marker) or marker ~= barriermarker) then return end 
        
  
       moveObject(barrier,3000,1544.5996,-1623.9502,13.2,-90) 
              outputChatBox("true") 
            destroyElement(barriermarker) 
           setTimer(moveObject,7500,1,barrier,2600,1544.5996,-1623.9502,13.1,90) 
             local barriermarker = setTimer(createMarker,11000,1,1544.88757,-1627.26501,12.7,"cylinder",8,_,_,_,0) 
  
    
      end 
      addEventHandler("onPlayerMarkerHit",resourceRoot,opengate) 
  
      function barriernotbreakable() 
      triggerClientEvent("setbarriernotbreakable",resourceRoot,barrier) 
      end 
  
      addEventHandler("onResourceStart",getRootElement(),barriernotbreakable) 
  

Again, thank you very much for fixing, your explaination was also helpful :)

Link to comment
The first argument should be the marker that the player hit, so you need to check if the marker hit by the player is the barriermarker. Your code simply "masks" the global barriermarker with a local one that refers to the marker hit by the player.

So you need to change "barriermarker" in "opengate" function to "marker" (or any other name but not "barriermarker") and then comparing it to "barriermarker"

local barrier = createObject(2920,1544.5996,-1623.9502,13.1,90,0,0) 
local barriermarker = createMarker(1544.88757,-1627.26501,12.7,"cylinder",8,_,_,_,255) 
  
  
function opengate(marker) 
 if (not isElement(marker) or marker ~= barriermarker) then return end 
        
  
       moveObject(barrier,3000,1544.5996,-1623.9502,13.2,-90) 
              outputChatBox("true") 
            destroyElement(barriermarker) 
           setTimer(moveObject,7500,1,barrier,2600,1544.5996,-1623.9502,13.1,90) 
             local barriermarker = setTimer(createMarker,11000,1,1544.88757,-1627.26501,12.7,"cylinder",8,_,_,_,0) 
  
    
      end 
      addEventHandler("onPlayerMarkerHit",resourceRoot,opengate) 
  
      function barriernotbreakable() 
      triggerClientEvent("setbarriernotbreakable",resourceRoot,barrier) 
      end 
  
      addEventHandler("onResourceStart",getRootElement(),barriernotbreakable) 
  

But I got one more problem, I want to set the barrier not breakable using setObejectBreakable(), but its not working, can you help me with this? :D

Server side

function barriernotbreakable() 
triggerClientEvent("setbarriernotbreakable",resourceRoot,barrier) 
end 
  
addEventHandler("onResourceStart",getRootElement(),barriernotbreakable) 
  

Client

addEvent("setbarriernotbreakable",true) 
function setbarriernotbreakable(barrier) 
setObjectBreakable(barrier,false) 
end 
  
addEventHandler("setbarriernotbreakable",getRootElement(),setbarriernotbreakable) 

Link to comment

One possible problem you have is that you use triggerClientEvent when the resource starts, this means that the event will not be triggered for whoever joins after the resource started. Also, it's wrong to send 'resourceRoot' as the baseElement for triggerClientEvent. It's recommended that you just use 'root'

Also, you have attached the 'onResourceStart' event to 'getRootElement()', this means that any resource that starts will trigger the function. By replacing 'getRootElement()' with 'resourceRoot', the event will only be triggered when the actual resource starts.

function barriernotbreakable() 
triggerClientEvent("setbarriernotbreakable",root,barrier) 
end 
  
addEventHandler("onResourceStart",resourceRoot,barriernotbreakable) 
  
function barriernotbrekableOnJoin() 
triggerClientEvent(source, "setbarriernotbreakable", root, barrier) 
end 
addEventHandler("onPlayerJoin", barriernotbreakableOnJoin) 

Link to comment
One possible problem you have is that you use triggerClientEvent when the resource starts, this means that the event will not be triggered for whoever joins after the resource started. Also, it's wrong to send 'resourceRoot' as the baseElement for triggerClientEvent. It's recommended that you just use 'root'

Also, you have attached the 'onResourceStart' event to 'getRootElement()', this means that any resource that starts will trigger the function. By replacing 'getRootElement()' with 'resourceRoot', the event will only be triggered when the actual resource starts.

function barriernotbreakable() 
triggerClientEvent("setbarriernotbreakable",root,barrier) 
end 
  
addEventHandler("onResourceStart",resourceRoot,barriernotbreakable) 
  
function barriernotbrekableOnJoin() 
triggerClientEvent(source, "setbarriernotbreakable", root, barrier) 
end 
addEventHandler("onPlayerJoin", barriernotbreakableOnJoin) 

function barriernotbreakable() 
triggerClientEvent("setbarriernotbreakable",root,barrier) 
end 
  
addEventHandler("onResourceStart",resourceRoot,barriernotbreakable) 
  
function barriernotbreakableOnJoin() 
triggerClientEvent(source, "setbarriernotbreakable", root, barrier) 
end 
addEventHandler("onPlayerJoin",getRootElement(),barriernotbreakableOnJoin) 

Thank you very much again :) , but I did it as you said, but still not working :|

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