Machine

Elevator problem with code

Recommended Posts

can someone pls tell me what is wrong here

Client Side- 

GUIEditor_Window = {}
GUIEditor_Button = {}
GUIEditor_Label = {}

GUIEditor_Window[1] = guiCreateWindow(0.3875,0.300,0.50,0.6117,"Elevator",true)
guiWindowSetMovable(GUIEditor_Window[1],false)
GUIEditor_Button[1] = guiCreateButton(15,50,400,50,"Ground floor",false,GUIEditor_Window[1])
GUIEditor_Button[2] = guiCreateButton(14,111,400,50,"Roof floor",false,GUIEditor_Window[1])
guiLabelSetColor(GUIEditor_Label[1],255,255,0)
guiSetFont(GUIEditor_Label[1],"default-bold-small")
GUIEditor_Button[4] = guiCreateButton(17,313,450,41,"Exit",false,GUIEditor_Window[1])
 
guiSetVisible(GUIEditor_Window[1], false)
showCursor(false)
  
local marker = createMarker(270.79998779297, 1879, 16.60000038147, "cylinder", 1.5, 255,0,0,70)

function markerhit (hitPlayer)
    if ( hitPlayer == localPlayer ) then
        guiSetVisible (GUIEditor_Window[1], true)
guiSetEnabled(GUIEditor_Button[1],true)
guiSetEnabled(GUIEditor_Button[2],true)
guiSetEnabled(GUIEditor_Button[3],true)
guiSetEnabled(GUIEditor_Button[4],true)
        showCursor (true)
    end
end
addEventHandler ("onClientMarkerHit", marker, markerhit)

function markerLeave ()
        guiSetVisible (GUIEditor_Window[1], false)
        showCursor (false)
end
addEventHandler ("onClientMarkerLeave", marker, markerLeave)

 
addEventHandler("onClientGUIClick", root,
    function ( )
        if ( source == GUIEditor_Button[1] ) then	
    triggerServerEvent ( "qd", getLocalPlayer() )
        elseif ( source == GUIEditor_Button[2] ) then
   triggerServerEvent ( "qd2", getLocalPlayer() )
           elseif ( source == GUIEditor_Button[3] ) then
   triggerServerEvent ( "qd4", getLocalPlayer() )
        elseif ( source == GUIEditor_Button[4] ) then
            guiSetVisible ( GUIEditor_Window[1], false )
            showCursor ( false )
        end
    end
)

 

Server Side--

function qm ( )
elevatordoor = createObject ( 2634, 267.70001, 1880, 18, 0, 0, 270 )

function VehicleHit(hitElement,matchingDimension) 
if getElementType(hitElement)=="player" then 
   moveObject ( elevatordoor, 3000, -2017, 158.79998779297, 20.39999961853 ) 
end 
end 
        else
            outputChatBox ( "Step inside the elevator", source )
        end
    end
end
setTimer ( VehicleHit, 1000, 1 )
addEvent( "qd", true )
addEventHandler( "onMarkerHit", getRootElement(), qm )



i am trying to make an elevator that work with the gui 
 

Share this post


Link to post

A lot of issues in the serverside code.

  1. VehicleHit is a function defined within a function, which, while legal, doesn't make sense unless you're making a local function.
  2. VehicleHit is called by a timer started outside the qm function, meaning that qm must be called (via hitting a marker)  within 1000 ms of starting the serverside code. Additionally, the timer does not send over any special parameters but your VehicleHit function expects a hitElement parameter and checks that it's a player element. You're sending a nil.
  3. qd event is only declared but never actually used. qd2 and qd4 aren't even declared on the serverside.

Share this post


Link to post

problem is which function should i use in order that when the client hit the button on gui it should trigger server side to move the object 

and qd2 is the floor roof but i didnt write it yet cuz i wanna solve the qd first and qd4 is just to close the gui 

can u tell me what is the right way to write serverside ?

Share this post


Link to post

Serverside code is kinda messy, yes.

addEvent( "qd", true )
addEventHandler( "qd", root, function() 
	elevatordoor = createObject ( 2634, 267.70001, 1880, 18, 0, 0, 270 )
	moveObject ( elevatordoor, 3000, -2017, 158.79998779297, 20.39999961853 ) 
end, true)

That should work.

 

You can't use marker functions without markers. Your markers are on client, so you have to use them there.

Edited by Peti

Share this post


Link to post

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.