Jump to content

ServerSided


#Ivan7

Recommended Posts

Ok So Im doing the TaxiJob and Im almost done only problem is that once I click the button Accept it wont change my skin or spawn me in my car.. this is the server sided

local pickups = { 
[1]={ -2514.2985839844, -19.26721572876, 25.6171875 }, 
[2]={ -2413.8093261719, 314.66299438477, 35.171875 }, 
[3]={ -1980.0808105469, 884.00354003906, 45.203125 }, 
[4]={ -1584.2047119141, 812.43743896484, 6.8203125 }, 
[5]={ -1817.1701660516, 1286.7491455078, 15.492509841919 }, 
[6]={ -2343.4348144531, 983.23840322031, 50.6953125 }, 
[7]={ -2554.942629531,  193.716659548, 6.2031769752502 } 
} 
  
local dropoffss = { 
[1]={ -2275.2744140625, 612.84197998047, 43.402828216553 }, 
[2]={ -2566.2153320313, 578.38897705078, 14.453125 }, 
[3]={ -2128.4689941406, 310.44934082031, 35.254566192627 }, 
[4]={ -1702.652941016, 717.54370117188, 24.890625 }, 
[5]={ -1912.1589355469, 883.3916015625, 35.215755462646 }, 
[6]={ -1977.3975830078, 1118.9444580078, 53.23331451416 }, 
[7]={ -1703.1501464844, 1340.6345214844, 7.1796875 } 
} 
  
  
  
local pedCus = { 
[1]={ 7 }, 
[2]={ 21 }, 
[3]={ 29 }, 
[4]={ 137 }, 
[5]={ 27 }, 
[6]={ 240 }, 
[7]={ 264 } 
} 
  
  
function SetVisiteFor (mark,player) 
               setElementVisibleTo ( mark, root, false ) 
               setElementVisibleTo ( mark, player, true ) 
end 
  
  
  
  
  
taxiVehs = { [420] = true } 
Cars = {} 
function teamSet ( ) 
        if (isElement(Cars[source])) then 
            destroyElement(Cars[source]) 
        end 
        setElementData(source,"taximarker",4) 
        setElementModel(source, 255) 
            Cars[source] = createVehicle(420, -2485.3188476563, -169.93522644043, 25.6171875) 
            addEventHandler ( "onVehicleExit", Cars[source], deleteOnExit ) 
            addEventHandler ( "onVehicleEnter", Cars[source], inVEH ) 
            addEventHandler ( "onVehicleStartEnter", Cars[source], enterVehicle ) 
            warpPedIntoVehicle ( source, Cars[source] ) 
            outputChatBox("You are now employed as a Taxi Driver!", source) 
end 
addEvent ( "sTeame", true) 
addEventHandler ( "sTeame", root, teamSet ) 
  
addEventHandler('onPlayerQuit', root, 
function() 
        if isElement( Cars[source] ) then 
                destroyElement(Cars[source] ) 
        end 
end 
) 
  
  
function enterVehicle ( thePlayer, seat, jacked ) -- when a player enters a vehicle 
    if getElementType ( thePlayer ) == "player" and getElementData(thePlayer,"JobNew") ~= 4 then 
            removePedFromVehicle( thePlayer ) 
            outputChatBox("Only Taxi Drivers can drive this vehicle!", thePlayer) 
    end 
end 
  
  
  
markers = { } 
blips = { } 
peds = { } 
mposi = { } 
mposii = {} 
  
  
  
  
function startJob ( thePlayer ) 
    local x, y, z = unpack ( pickups [ math.random ( #pickups ) ] ) 
    markers [ thePlayer ] = createMarker ( x, y, z, "cylinder", 5.0, 255, 0, 0, 0 ) 
    SetVisiteFor (markers [ thePlayer ],thePlayer) 
    mposi = { getElementPosition( markers [ thePlayer ] ) } 
    local skins = unpack ( pedCus [ math.random ( #pedCus ) ] ) 
    peds [ thePlayer ] = createPed( skins, x, y, z )   
    SetVisiteFor (peds [ thePlayer ],thePlayer) 
    blips [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 58 ) 
    SetVisiteFor (blips [ thePlayer ],thePlayer) 
    addEventHandler ( "onMarkerHit", markers [ thePlayer ], warpit ) 
    end 
  
function inVEH ( thePlayer ) 
    if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) and getElementData(thePlayer,"JobNew") == 4 then 
            startJob ( thePlayer ) 
   end 
 end 
  
function warpit ( thePlayer ) 
    if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) then 
       local vehiclee = getPedOccupiedVehicle ( thePlayer ) 
        if ( getElementModel ( vehiclee ) == 420 ) and getElementData(thePlayer,"JobNew") == 4 then 
            setTimer ( warpPedIntoVehicle, 2000, 1, peds [ thePlayer ], vehiclee, 2 ) 
            destroyJob ( thePlayer ) 
            local x, y, z = unpack ( dropoffss [ math.random ( #dropoffss ) ] ) 
            markers [ thePlayer ] = createMarker ( x, y, z - 1, "cylinder", 5.0, 195, 197, 9, 255 ) 
            SetVisiteFor (markers [ thePlayer ],thePlayer) 
            mposii = { getElementPosition( markers [ thePlayer ] ) } 
            blips [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 41 ) 
            SetVisiteFor (blips [ thePlayer ],thePlayer) 
            addEventHandler ( "onMarkerHit", markers [ thePlayer ], pickmeup ) 
            end 
            end 
        end 
  
  
function pickmeup ( thePlayer ) 
    if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) then 
        destroyJob ( thePlayer ) 
        local mx, my, mz = unpack ( mposi ) 
        local mmx, mmy, mmz = unpack ( mposii ) 
        local money = getDistanceBetweenPoints2D ( mx, my, mmx, mmy ) 
        finalmoney = math.floor ( money ) 
        if finalmoney then 
        setTimer( function () 
        finalmoney = finalmoney + 1000 
        outputChatBox( "You have earned ".. finalmoney .."!", thePlayer,0, 144, 0) 
        setElementData(thePlayer,"Money", (getElementData(thePlayer,"Money") or 0 ) +  ) 
        end, 3000, 1 ) 
        setTimer ( 
            function ( ) 
                if ( isElement ( peds [ thePlayer ] ) ) then 
                    destroyElement ( peds [ thePlayer ] ) 
                end 
                startJob ( thePlayer ) 
            end 
            ,3000, 1 
        ) 
            end 
        end 
    end 
  
function deleteOnExit ( thePlayer ) 
    if ( isElement ( markers [ thePlayer ] ) ) then 
        destroyElement ( markers [ thePlayer ] ) 
    end 
    if ( isElement ( blips [ thePlayer ] ) ) then 
        destroyElement ( blips [ thePlayer ] ) 
    end 
    if ( isElement ( peds [ thePlayer ] ) ) then 
        destroyElement ( peds [ thePlayer ] ) 
    end 
end 
  
  
  
function destroyJob ( thePlayer ) 
    if ( isElement ( markers [ thePlayer ] ) ) then 
        destroyElement ( markers [ thePlayer ] ) 
    end 
    if ( isElement ( blips [ thePlayer ] ) ) then 
        destroyElement( blips [ thePlayer ] ) 
    end 
end 
  
  

Link to comment

And this would be the clientside

  
  
  
  
GUIEditor = { 
    memo = {}, 
    button = {}, 
    window = {}, 
} 
  
  
    GUIEditor.window[1] = guiCreateWindow(0.4, 0.16, 0.35, 0.45, "Gta-Ar Taxi Job", true) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetVisible(GUIEditor.window[1], false) 
         
        bAccept = guiCreateButton(0.10, 0.90, 0.41, 0.80, "Accept", true, GUIEditor.window[1]) 
        guiSetProperty(bAccept, "NormalTextColour", "FFAAAAAA") 
         
        bClose = guiCreateButton(0.52, 0.90, 0.41, 0.80, "Decline", true, GUIEditor.window[1]) 
        guiSetProperty(bClose, "NormalTextColour", "FFAAAAAA")  
         
        GUIEditor.memo[1] = guiCreateMemo(0.10, 0.1, 0.80, 0.75, "               Gta-Ar Taxi Job                                                              Rules:                                            1) Go  To Player (Blue Blip).           2) Pick up Player by pressing car horn.                                            3) Drop off Player to Red Blip.                                                             Be sure not to die, if you do you will lose your customer. Every dropoff you will earn up to $1000!                                                                         Made By: [Gta-Ar]#Ivan                ", true, GUIEditor.window[1]) 
         
        local taximarker = createMarker(-2479.9282226563, -198.06895446777, 24.623662948608, "cylinder", 1.5, 255, 0, 0) 
 createBlipAttachedTo( taximarker, 42) 
  
    addEventHandler( "onClientRender", root, function (  ) 
        local x, y, z = getElementPosition( taximarker ) 
           local Mx, My, Mz = getCameraMatrix(   ) 
            if ( getDistanceBetweenPoints3D( x, y, z, Mx, My, Mz ) <= 15 ) then 
               local WorldPositionX, WorldPositionY = getScreenFromWorldPosition( x, y, z +1.2, 3 ) 
                if ( WorldPositionX and WorldPositionY ) then 
                    dxDrawText ( "Taxi Job", WorldPositionX, WorldPositionY, WorldPositionX, WorldPositionY, tocolor(255,255,255,255), 2.4, "arial" ) 
                end 
          end 
    end ) 
  
function showGUIbt(hitElement) 
if (hitElement == localPlayer )  and not isPedInVehicle(localPlayer) then  
    if getTeamName(getPlayerTeam(localPlayer)) ~= "Police" then 
        guiSetVisible(GUIEditor.window[1], true) 
        showCursor( true ) 
        end 
    end 
end 
addEventHandler("onClientMarkerHit", taximarker, showGUIbt)  
  
function showGUIbf() 
   if source == bAccept then 
    guiSetVisible (GUIEditor.window[1], false ) 
    showCursor ( false ) 
    joinTeam() 
    elseif source == bClose then 
    guiSetVisible (GUIEditor.window[1], false )  
    showCursor ( false ) 
    end 
end 
 addEventHandler("onClientGUIClick", getRootElement(), showGUIbf) 

Link to comment

between line 136 and 137 :

        setElementData(thePlayer,"Money", (getElementData(thePlayer,"Money") or 0 ) +  ) 
        end, 3000, 1 ) 

Remove the + in (getElementData(thePlayer,"Money") or 0) + )

And also, the problem is your clientside is not triggering server. There's no triggerServerEvent in the client side script :/ , so i assume that its probably in the joinTeam() function!!!

Link to comment

so I would be putting this for client? taking a gusse..

  
GUIEditor = { 
    memo = {}, 
    button = {}, 
    window = {}, 
} 
  
  
    GUIEditor.window[1] = guiCreateWindow(0.4, 0.16, 0.35, 0.45, "Gta-Ar Taxi Job", true) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetVisible(GUIEditor.window[1], false) 
         
        bAccept = guiCreateButton(0.10, 0.90, 0.41, 0.80, "Accept", true, GUIEditor.window[1]) 
        guiSetProperty(bAccept, "NormalTextColour", "FFAAAAAA") 
        addEventHandler("onClientGUIClick", bAccept, showGUIbf, false) 
        triggerServerEvent( "sTeame", thePlayer, "joinTeam" ) 
         
        bClose = guiCreateButton(0.52, 0.90, 0.41, 0.80, "Decline", true, GUIEditor.window[1]) 
        guiSetProperty(bClose, "NormalTextColour", "FFAAAAAA")  
         
        GUIEditor.memo[1] = guiCreateMemo(0.10, 0.1, 0.80, 0.75, "               Gta-Ar Taxi Job                                                              Rules:                                            1) Go  To Player (Blue Blip).           2) Pick up Player by pressing car horn.                                            3) Drop off Player to Red Blip.                                                             Be sure not to die, if you do you will lose your customer. Every dropoff you will earn up to $1000!                                                                         Made By: [Gta-Ar]#Ivan                ", true, GUIEditor.window[1]) 
         
        local taximarker = createMarker(-2479.9282226563, -198.06895446777, 24.623662948608, "cylinder", 1.5, 255, 0, 0) 
 createBlipAttachedTo( taximarker, 42) 
  
    addEventHandler( "onClientRender", root, function (  ) 
        local x, y, z = getElementPosition( taximarker ) 
           local Mx, My, Mz = getCameraMatrix(   ) 
            if ( getDistanceBetweenPoints3D( x, y, z, Mx, My, Mz ) <= 15 ) then 
               local WorldPositionX, WorldPositionY = getScreenFromWorldPosition( x, y, z +1.2, 3 ) 
                if ( WorldPositionX and WorldPositionY ) then 
                    dxDrawText ( "Taxi Job", WorldPositionX, WorldPositionY, WorldPositionX, WorldPositionY, tocolor(255,255,255,255), 2.4, "arial" ) 
                end 
          end 
    end ) 
  
function showGUIbt(hitElement) 
if (hitElement == localPlayer )  and not isPedInVehicle(localPlayer) then  
    if getTeamName(getPlayerTeam(localPlayer)) ~= "Police" then 
        guiSetVisible(GUIEditor.window[1], true) 
        showCursor( true ) 
        end 
    end 
end 
addEventHandler("onClientMarkerHit", taximarker, showGUIbt)  
  
function showGUIbf() 
   if source == bAccept then 
    guiSetVisible (GUIEditor.window[1], false ) 
    showCursor ( false ) 
    joinTeam() 
    elseif source == bClose then 
    guiSetVisible (GUIEditor.window[1], false )  
    showCursor ( false ) 
    end 
end 
 addEventHandler("onClientGUIClick", getRootElement(), showGUIbf)    
  
  

Link to comment

this is the serversided

  
local pickups = { 
[1]={ -2514.2985839844, -19.26721572876, 25.6171875 }, 
[2]={ -2413.8093261719, 314.66299438477, 35.171875 }, 
[3]={ -1980.0808105469, 884.00354003906, 45.203125 }, 
[4]={ -1584.2047119141, 812.43743896484, 6.8203125 }, 
[5]={ -1817.1701660516, 1286.7491455078, 15.492509841919 }, 
[6]={ -2343.4348144531, 983.23840322031, 50.6953125 }, 
[7]={ -2554.942629531,  193.716659548, 6.2031769752502 } 
} 
  
local dropoffss = { 
[1]={ -2275.2744140625, 612.84197998047, 43.402828216553 }, 
[2]={ -2566.2153320313, 578.38897705078, 14.453125 }, 
[3]={ -2128.4689941406, 310.44934082031, 35.254566192627 }, 
[4]={ -1702.652941016, 717.54370117188, 24.890625 }, 
[5]={ -1912.1589355469, 883.3916015625, 35.215755462646 }, 
[6]={ -1977.3975830078, 1118.9444580078, 53.23331451416 }, 
[7]={ -1703.1501464844, 1340.6345214844, 7.1796875 } 
} 
  
  
  
local pedCus = { 
[1]={ 7 }, 
[2]={ 21 }, 
[3]={ 29 }, 
[4]={ 137 }, 
[5]={ 27 }, 
[6]={ 240 }, 
[7]={ 264 } 
} 
  
  
function SetVisiteFor (mark,player) 
               setElementVisibleTo ( mark, root, false ) 
               setElementVisibleTo ( mark, player, true ) 
end 
  
  
  
  
  
taxiVehs = { [420] = true } 
Cars = {} 
function teamSet ( ) 
        if (isElement(Cars[source])) then 
            destroyElement(Cars[source]) 
        end 
        setElementData(source,"taximarker",4) 
        setElementModel(source, 255) 
            Cars[source] = createVehicle(420, -2485.3188476563, -169.93522644043, 25.6171875) 
            addEventHandler ( "onVehicleExit", Cars[source], deleteOnExit ) 
            addEventHandler ( "onVehicleEnter", Cars[source], inVEH ) 
            addEventHandler ( "onVehicleStartEnter", Cars[source], enterVehicle ) 
            warpPedIntoVehicle ( source, Cars[source] ) 
            outputChatBox("You are now employed as a Taxi Driver!", source) 
end 
addEvent ( "sTeame", true) 
addEventHandler ( "sTeame", root, teamSet ) 
  
addEventHandler('onPlayerQuit', root, 
function() 
        if isElement( Cars[source] ) then 
                destroyElement(Cars[source] ) 
        end 
end 
) 
  
  
function enterVehicle ( thePlayer, seat, jacked )  
    if getElementType ( thePlayer ) == "player" and getElementData(thePlayer,"JobNew") ~= 4 then 
            removePedFromVehicle( thePlayer ) 
            outputChatBox("Only Taxi Drivers can drive this vehicle!", thePlayer) 
    end 
end 
  
  
  
markers = { } 
blips = { } 
peds = { } 
mposi = { } 
mposii = {} 
  
  
  
  
function startJob ( thePlayer ) 
    local x, y, z = unpack ( pickups [ math.random ( #pickups ) ] ) 
    markers [ thePlayer ] = createMarker ( x, y, z, "cylinder", 5.0, 255, 0, 0, 0 ) 
    SetVisiteFor (markers [ thePlayer ],thePlayer) 
    mposi = { getElementPosition( markers [ thePlayer ] ) } 
    local skins = unpack ( pedCus [ math.random ( #pedCus ) ] ) 
    peds [ thePlayer ] = createPed( skins, x, y, z )   
    SetVisiteFor (peds [ thePlayer ],thePlayer) 
    blips [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 58 ) 
    SetVisiteFor (blips [ thePlayer ],thePlayer) 
    addEventHandler ( "onMarkerHit", markers [ thePlayer ], warpit ) 
    end 
  
function inVEH ( thePlayer ) 
    if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) and getElementData(thePlayer,"JobNew") == 4 then 
            startJob ( thePlayer ) 
   end 
 end 
  
function warpit ( thePlayer ) 
    if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) then 
       local vehiclee = getPedOccupiedVehicle ( thePlayer ) 
        if ( getElementModel ( vehiclee ) == 420 ) and getElementData(thePlayer,"JobNew") == 4 then 
            setTimer ( warpPedIntoVehicle, 2000, 1, peds [ thePlayer ], vehiclee, 2 ) 
            destroyJob ( thePlayer ) 
            local x, y, z = unpack ( dropoffss [ math.random ( #dropoffss ) ] ) 
            markers [ thePlayer ] = createMarker ( x, y, z - 1, "cylinder", 5.0, 195, 197, 9, 255 ) 
            SetVisiteFor (markers [ thePlayer ],thePlayer) 
            mposii = { getElementPosition( markers [ thePlayer ] ) } 
            blips [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 41 ) 
            SetVisiteFor (blips [ thePlayer ],thePlayer) 
            addEventHandler ( "onMarkerHit", markers [ thePlayer ], pickmeup ) 
            end 
            end 
        end 
  
  
function pickmeup ( thePlayer ) 
    if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) then 
        destroyJob ( thePlayer ) 
        local mx, my, mz = unpack ( mposi ) 
        local mmx, mmy, mmz = unpack ( mposii ) 
        local money = getDistanceBetweenPoints2D ( mx, my, mmx, mmy ) 
        finalmoney = math.floor ( money ) 
        if finalmoney then 
        setTimer( function () 
        finalmoney = finalmoney + 1000 
        outputChatBox( "You have earned ".. finalmoney .."!", thePlayer,0, 144, 0) 
        setElementData(thePlayer,"Money", (getElementData(thePlayer,"Money") or 0 )  
        end, 3000, 1 ) 
        setTimer ( 
            function ( ) 
                if ( isElement ( peds [ thePlayer ] ) ) then 
                    destroyElement ( peds [ thePlayer ] ) 
                end 
                startJob ( thePlayer ) 
            end 
            ,3000, 1 
        ) 
            end 
        end 
    end 
  
function deleteOnExit ( thePlayer ) 
    if ( isElement ( markers [ thePlayer ] ) ) then 
        destroyElement ( markers [ thePlayer ] ) 
    end 
    if ( isElement ( blips [ thePlayer ] ) ) then 
        destroyElement ( blips [ thePlayer ] ) 
    end 
    if ( isElement ( peds [ thePlayer ] ) ) then 
        destroyElement ( peds [ thePlayer ] ) 
    end 
end 
  
  
  
function destroyJob ( thePlayer ) 
    if ( isElement ( markers [ thePlayer ] ) ) then 
        destroyElement ( markers [ thePlayer ] ) 
    end 
    if ( isElement ( blips [ thePlayer ] ) ) then 
        destroyElement( blips [ thePlayer ] ) 
    end 
end 
  

Link to comment

First remove the line 51(joinTeam() since you are not really using that function).

Secondly, no, the line 16 ( triggerServerEvent( "sTeame", thePlayer, "joinTeam" )) should be between 50 and 51 :/

Ivan, it would be better if you first check out the tutorials found in wiki :

https://wiki.multitheftauto.com/wiki/In ... ng_the_GUI

You will learn how and when to use the triggerServerEvent function too at this page.

Also, like i told you before, its better to make your scripts as simple as you can so that you can know if there are mistakes in it, and if the script is good and workin perfectly, then you can try to make it more complex.

Link to comment

Ivan, your problem is not because of the team format, but because you dont know when to use the triggerServerEvent function.

oka, i will explain, when you create the gui with the accept the job and reject the job buttons, you first want that when the player clicks on the reject button, the gui should dissapear, and everythin gets back to normal, but when the player clicks on the accept button, then only should the job start( so, that the part where you should use the triggerServerEvent so as to trigger the server to start the job)

Ivan, please take my advice into consideration, make the script simple first.

Link to comment

Dude the script isnt mine I told you Im making this for a friend and he wanted me to fix it up, sicne the script isnt mine i have to do it his way, if this was for me i would of started off simple, and the first time i did i had it like this

bAccept = guiCreateButton(0.10, 0.90, 0.41, 0.80, "Accept", true, GUIEditor.window[1])

guiSetProperty(bAccept, "NormalTextColour", "FFAAAAAA")

addEventHandler("onClientGUIClick", bAccept, showGUIbf, false)

triggerServerEvent( "sTeame", thePlayer, "joinTeam" )

which you said was incorrect my gusse is im putting the wrong ifno in triggerServerEvent

Link to comment

idk man ill just ask my friend #Twerky he will help me understand when we do teamviwer anyways thanks for always helping me if you can 1 do come to [Gta-Ar] Gangwars I would like to chill with you sometime, oh also idk if you know but im new to scripting like im really bad i probley started 8 days ago somewhere around their... i hope to get better soon

Link to comment

My friend, its been nearly 7 months since i started to script, and i know im not a pro, and you know what, i still make some mistakes. We all do mistakes, but we should not give up. In these 7 months, i read the gui tutorials many times, i can say i read it more than 10 times, just to master the basics. When i read them and understand them fully, i learned what events do and what parameters you should use. Now, i almost know all the basics. So bro, plz read the tutorials again. The link that i gave you, it has the triggerServerEvent in it, if you read it, you will know when to use it and how. Peace bro :) just dont give up!!!

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