Jump to content

Trigger problem .


CapY

Recommended Posts

After 2 hours of trying and figuring out what is wrong , i didn't succed .

On debug it says events are not added , like : Server triggered clientside event , but event is not added on a client side, but it's added , i don't know what is wrong there.

--Client 
function MarkerHit() -- define MarkerHit function for the handler 
    setElementPosition ( getLocalPlayer(), 2143, -2580, 14 ) 
    guiSetVisible ( Window [ 1 ] , false ) 
    showCursor ( false ) 
end 
  
addEvent("marker1", true) 
addEventHandler("marker1", getRootElement(), MarkerHit) 
  
function MarkerHit2() -- define MarkerHit function for the handler 
    setElementPosition ( getLocalPlayer(), -1432, -126, 26 ) 
    guiSetVisible ( Window [ 1 ] , false ) 
    showCursor ( false ) 
end 
  
addEvent("marker2", true) 
addEventHandler("marker2", getRootElement(), MarkerHit2) 
  
function MarkerHit3() -- define MarkerHit function for the handler 
    setElementPosition ( getLocalPlayer(), 1597,1449,34 ) 
    guiSetVisible ( Window [ 1 ] , false ) 
    showCursor ( false ) 
end 
  
addEvent("marker3", true) 
addEventHandler("marker3", getRootElement(), MarkerHit3) 

--Server 
  
function serverRuleGUI() 
triggerClientEvent("ruleOnJoin", getRootElement(), ruleGUI) 
end 
  
function serverMarker() 
triggerClientEvent("marker1", getRootElement(), MarkerHit) 
end 
  
function serverMarker2() 
triggerClientEvent("marker2", getRootElement(), MarkerHit2) 
end 
  
function serverMarker3() 
triggerClientEvent("marker3", getRootElement(), MarkerHit3) 
end 
  
  
addEventHandler("onPlayerJoin", getRootElement(), serverMarker) 
addEventHandler("onPlayerJoin", getRootElement(), serverMarker2) 
addEventHandler("onPlayerJoin", getRootElement(), serverMarker3) 
addEventHandler("onPlayerJoin", getRootElement(), serverRuleGUI) 

Anybody can explain what is wrong ?

Link to comment
(why there are 4 of them anyway).

is it really necesarry? you got onClientResourceStart client event if you want to do client stuff on player join.

PS: i dont see "ruleOnJoin" event added anywhere in the client script.

EDIT:You don't see ruleOnJoin because this is not the full script , this is just a part of it .

Well problem is in that , that camera didn't return to a player , but i have a function of it

function camTarget() 
    setCameraTarget(localPlayer) 
end 

And the gui don't want to hide , but event is added.

EDIT2:Without that 4 events GUI will NOT be displayed.

Link to comment

lol that's just what I'm trying to say..

think about it

when you join, your client files are NOT yet downloaded (or initialized) . So you can't use onPlayerJoin to trigger client events. This is where onClientResourceStart comes in handy. It is fired RIGHT when the files are initialized, so every GUI created onClientResourceStart will work.

about more events and functions.. why not?

function test()

triggerClientEvent(...)

triggerClientEvent(...)

triggerClientEvent(...)

triggerClientEvent(...)

end

Link to comment

Okay i cutted it to a Client side only , the problem was in that when i restarted some resource a rule GUI was displayed always, so i changed handlers from getRootElement() to a getResourceRootElement(getThisResource()).

So cams are not switchable and they don't redirect to a player.

--Client 
  
local resourceRoot = getResourceRootElement(getThisResource()) 
local matrixCams = { 
    {1468.8785400391, -919.25317382813, 100.153465271, 1468.388671875, -918.42474365234, 99.881813049316,0,180},--Vinewood Sign 
    {1614.837, -1301.275, 138.188, 200, 400, 102,0,180}, --LS 
    {-1856.736, 807.699, 115.546, 300, 250,99.98, 70, 90},  --SF 
} 
 local index = 1 
function switchMatrixCams() 
     local positionX,positionY,positionZ,lookAtX,lookAtY,lookAtZ, roll, fov = unpack(matrixCams[index]) 
     if getCameraMatrix() then 
     setCameraMatrix(positionX,positionY,positionZ,lookAtX,lookAtY,lookAtZ, roll, fov) 
     camTimer = setTimer(switchMatrixCams,10000,1) 
     index = index + 1 
     if index > #matrixCams then 
         index = 1 
     end 
    end 
end 
  
function stopCamSwitch () 
killTimer (camTimer) 
cancelEvent () 
end 
  
addEventHandler("onClientResourceStart",getRootElement(),stopCamSwitch) 
  
addEventHandler("onClientResourceStart",resourceRoot, 
    function() 
     -- set the player's camera to a fixed position, looking at a fixed point 
        switchMatrixCams ( ) 
        addEventHandler("onClientGUIClick", Button1[1],camTarget, false ) 
        addEventHandler("onClientGUIClick", Btn2[2],camTarget, false ) 
        addEventHandler("onClientGUIClick", Btn3[3],camTarget, false ) 
        addEventHandler ( "onClientGUIClick", Button1[1], stopCamSwitch, false) 
        addEventHandler ( "onClientGUIClick", Btn2[2], stopCamSwitch, false) 
        addEventHandler ( "onClientGUIClick", Btn3[3], stopCamSwitch, false) 
end 
) 
  
  
addEventHandler("onClientResourceStart",resourceRoot, 
    function() 
  
        GUIEditor_Button = {} 
        GUIEditor_Window = {} 
        GUIEditor_Memo = {} 
  
        GUIEditor_Window[ 1 ] = guiCreateWindow(0.2805,0.2139,0.4172,0.5713,"Rules ",true) 
        guiSetAlpha(GUIEditor_Window[1],0.80000001192093) 
        GUIEditor_Memo[1] = guiCreateMemo(0.03,0.065,0.9382,0.8376,"                                 Here is a list of our rules, respect them.\n\n\n1. Do NOT use any kinds of hacks and cheats. \n\n2. Do NOT argue with staff, our is last.\n\n3. Respect other players , especially members.\n\n4. Dont fight with others.\n\n5. Dont use any outgame modified handlings ( use  handling editor for that, more info on F9 ) \n\n6. Never ask for membership, we will ask you .\n\n7. Dont bother staff .\n\n8. Have a bit of experience .\n\n9. If something you don't understand , just read help on F9 .\n\n10. Don't spam vehicles , dont RAM others.\n\n\nAbove all , have fun !\n\n\n\n\nNote: Every rule break can result as kick / ban or permaban.",true,GUIEditor_Window[1]) 
        GUIEditor_Button[1] = guiCreateButton(0.3951,0.935,0.2397,0.0496,"Accept !",true,GUIEditor_Window[1]) 
        showCursor(true) 
        guiSetVisible(GUIEditor_Window[1],true) 
        addEventHandler("onClientGUIClick",GUIEditor_Button[1], function() 
        guiSetVisible(GUIEditor_Window[1],false) 
        guiSetVisible(Window[ 1 ],true) 
        guiMemoSetReadOnly (GUIEditor_Memo[1], true) 
        guiWindowSetSizable(GUIEditor_Window[1],false) 
        guiWindowSetMovable(GUIEditor_Window[1],false) 
        end,false) 
    end 
  
function camTarget() 
    setCameraTarget(localPlayer) 
end 
  
) 

Can you explain me what is now wrong ?

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