Jump to content

Server side problems


Recommended Posts

Hello guys, I have a little problem that I can't fix. I want to create a parachuting script, I made the GUI for it and I made a bit of the server side. My problem is that I don't know how to trigger the GUI for the player who goes into the marker, and also it outputs 'test' for everyone, not for the hitElement. What could be the problem? I would be grateful if someone could help me!

Client side:

  
function drawGui() 
    window = guiCreateWindow(697, 440, 511, 205, "parachute", false) 
    guiWindowSetSizable(window, false) 
    yesBtn = guiCreateButton(110, 87, 89, 88, "yes", false, window) 
    guiSetProperty(yesBtn, "NormalTextColour", "FFAAAAAA") 
    noBtn = guiCreateButton(309, 87, 89, 88, "no", false, window) 
    guiSetProperty(noBtn, "NormalTextColour", "FFAAAAAA") 
    lbl = guiCreateLabel(74, 28, 350, 49, "?", false, window) 
    guiLabelSetHorizontalAlign(lbl, "center", false) 
    guiLabelSetVerticalAlign(lbl, "center") 
end 
addEvent("showParachuteGUI", true) 
addEventHandler("showParachuteGUI", getRootElement(), drawGui) 
  
function removeGui() 
    if (guiGetVisible(window) == true) then 
        destroyElement(window) 
    end 
end 
  

Server side:

  
parachuteMarker = createMarker(1948.7705078125, -2225.1472167969, 13, "cylinder", 1.5, 255, 255, 0, 125) 
  
function markerHit() 
    if (source == parachuteMarker) then 
        outputChatBox("test", hitElement) 
        triggerClientEvent("showParachuteGUI", hitElement) 
    end 
end 
addEventHandler("onMarkerHit", parachuteMarker, markerHit) 
  

Thanks in advance!

Link to comment

"triggerClientEvent ( [table/element sendTo=getRootElement()], string name, element sourceElement, [arguments...] )"

You never defined the "sendTo" element, it takes root as default.

triggerClientEvent(hitElement,"showParachuteGUI", hitElement) 

Link to comment
parachuteMarker = createMarker(1948.7705078125, -2225.1472167969, 13, "cylinder", 1.5, 255, 255, 0, 125) 
function markerHit(hitElement) 
    if (getElementType(hitElement) == 'player' ) then 
    outputChatBox("it's Working Yeaaah !", hitElement, getRootElement(), 255, 0, 0) 
    triggerClientEvent(hitElement, "showParachuteGUI", hitElement) 
    end 
end 
addEventHandler("onMarkerHit", parachuteMarker, markerHit) 

Edited by Guest
Link to comment
parachuteMarker = createMarker(1948.7705078125, -2225.1472167969, 13, "cylinder", 1.5, 255, 255, 0, 125) 
  
function markerHit(hitElement) 
    if (hitElement == parachuteMarker) then 
    outputChatBox("it's Working Yeaaah !", hitElement, getRootElement(), 255, 0, 0) 
    triggerClientEvent(hitElement, "showParachuteGUI", hitElement) 
    end 
end 
addEventHandler("onMarkerHit", parachuteMarker, markerHit) 

if (hitElement == parachuteMarker) then ? Whats this ?

Link to comment
parachuteMarker = createMarker(1948.7705078125, -2225.1472167969, 13, "cylinder", 1.5, 255, 255, 0, 125) 
  
function markerHit(hitElement) 
    if (hitElement == parachuteMarker) then 
    outputChatBox("it's Working Yeaaah !", hitElement, getRootElement(), 255, 0, 0) 
    triggerClientEvent(hitElement, "showParachuteGUI", hitElement) 
    end 
end 
addEventHandler("onMarkerHit", parachuteMarker, markerHit) 

if (hitElement == parachuteMarker) then ? Whats this ?

HeHe, i was in hurry didn't have time to think about it ,

fixed , thanks

Link to comment

Umm, now I have another problem. I tried to trigger again, but I don't understand it. Someone could explain it for me? I have this in client side:

  
function acceptParachute() 
    triggerServerEvent("giveParachuteForPlayer", getLocalPlayer()) 
end 
  

And this in server side:

  
function parachute(hitElement) 
    giveWeapon(hitElement, 46, 1) 
    setElementPosition(hitElement, 1954.33984375, -2224.9919433594, 16.678098678589) 
end 
addEvent("giveParachuteForPlayer", true) 
addEventHandler("giveParachuteForPlayer", getRootElement(), parachute) 
  

It should give me a parachute and set my position to the given coordinates when I click on Yes, but noting happens. Why?

Link to comment
----ClientSide 
function drawGui() 
    window = guiCreateWindow(697, 440, 511, 205, "parachute", false) 
    guiWindowSetSizable(window, false) 
    yesBtn = guiCreateButton(110, 87, 89, 88, "yes", false, window) 
    guiSetProperty(yesBtn, "NormalTextColour", "FFAAAAAA") 
    noBtn = guiCreateButton(309, 87, 89, 88, "no", false, window) 
    guiSetProperty(noBtn, "NormalTextColour", "FFAAAAAA") 
    lbl = guiCreateLabel(74, 28, 350, 49, "?", false, window) 
    guiLabelSetHorizontalAlign(lbl, "center", false) 
    guiLabelSetVerticalAlign(lbl, "center") 
end 
addEvent("showParachuteGUI", true) 
addEventHandler("showParachuteGUI", getRootElement(), drawGui) 
  
function removeGui() 
    if (guiGetVisible(window) == true) then 
        destroyElement(window) 
    end 
end 
  
addEventHandler ("onClientGUIClick", getRootElement(), 
function () 
if  ( source == yesBtn ) then 
triggerServerEvent('giveParachuteForPlayer', localPlayer) 
elseif (source == noBtn ) then 
      guiSetVisible ( window ,false ) 
  end 
 end 
 ) 
----ServerSide 
parachuteMarker = createMarker(1948.7705078125, -2225.1472167969, 13, "cylinder", 1.5, 255, 255, 0, 125) 
function markerHit(hitElement) 
    if (getElementType(hitElement) == 'player' ) then 
    outputChatBox("it's Working Yeaaah !", hitElement, getRootElement(), 255, 0, 0) 
    triggerClientEvent(hitElement, "showParachuteGUI", hitElement) 
    end 
end 
addEventHandler("onMarkerHit", parachuteMarker, markerHit) 
  
addEvent('giveParachuteForPlayer', true) 
addEventHandler('giveParachuteForPlayer', root, 
function() 
giveWeapon(source, 46, 1) 
setElementPosition(source, 1954.33984375, -2224.9919433594, 16.678098678589) 
outputChatBox('You got a Parachute, go and fall from the sky', source, getRootElement(), 255, 255, 0) 
 end 
 ) 
  
  

Link to comment

I have another question. How can I make a plane, make the camera attached to it and make it fly, but without driver or with an NPC? I just want to create a little scene where a plane goes up, but my code don't seems to work.

I created this in client side, but it only creates the Dodo plane and sets the camera attached to it, but it's engine is off and it's not going forward or up. How can I fix it?

  
function airplane() 
    cam = getCamera() 
    setElementPosition(cam, 0, 0, 0) 
    plane = createVehicle(593, 1980.15234375, -2493.7978515625, 13.53911781311) 
    attachElements( cam, plane, 0,-4,2, -20,0,0 ) 
    setControlState ( "accelerate", true ) 
    setVehicleEngineState ( plane, true ) 
end 
  

Link to comment

Okay, I made it thanks! But I still have questions. How can I check if the player if already landed in a marker? I made a function but it doesn't seems to work. What could be the problem?

  
function landingMarker() 
    parachuteLandMarker = createMarker(1978.2177734375, -2352.3857421875, 13, "cylinder", 10, 255, 0, 0, 255) 
    if isPlayerOnGround (localPlayer) then 
        if isElementWithinMarker(localPlayer, parachuteLandMarker) then 
            outputChatBox("succes") 
        else 
            outputChatBox("failure") 
        end 
    end 
end 
addEventHandler("onClientMarkerHit", parachuteLandMarker, landingMarker) 
  

Link to comment

parachuteLandMarker was defined and created in the function landingMarker, which is triggered when parachuteLandMarker is hit. So how can the event onClientMarkerHit be triggered for parachuteLandMarker when it isn't created yet?

Use the following:

  
local parachuteLandMarker = createMarker(1978.2177734375, -2352.3857421875, 13, "cylinder", 10, 255, 0, 0, 255) 
function landingMarker() 
    
    if isPlayerOnGround (localPlayer) then 
        if isElementWithinMarker(localPlayer, parachuteLandMarker) then 
            outputChatBox("succes") 
        else 
            outputChatBox("failure") 
        end 
    end 
end 
addEventHandler("onClientMarkerHit", parachuteLandMarker, landingMarker) 
  

Your logic MAY be flawed, because I don't think the player will be on the ground the second he hits the marker if he's parachuting in on it; It might be worth testing/checking it out. isElementWithinMarker should ALWAYS return true because the player just triggered onClientMarkerHit when he hit the marker, which in turns instantly calls the function landingMarker; I'm not 100% sure about that though.

Link to comment

Well, how could I make a marker or something like that to check if the player is already landed, and if the player is landed then how can I check if he's landed in the correct position, else if he isn't at the right place then output a text or something? Is this possible somehow?

P.S.: Sorry for the bad English!

Link to comment

Okay, I will try that, but how can I check if the player is in the ground but not in the marker? With the last posted script it wasn't output "failure", just "succes" when I walked into the marker. So how can I check if the player is not in the marker but on the ground?

Link to comment

The player is always going to be in the marker when that event is triggered, because he just entered it. You CAN use a timer to check if the player is still in the marker after a certain time; However, You need to take care and not duplicate the timers, because the player can enter the marker over and over again, in turn creating new timers each hit. So if you are going to use timers, check if one already exists or not.

Link to comment

Okay, thanks! I have an idea how to do this. I'm going to freeze the player after five seconds when be hit the marker, after five seconds if he's still in the marker it will be succes, else if he's outside it will be a failure. I Think it's gonna work, thank you! Will try jt or something like that.

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