WolfPire Posted February 25, 2012 Share Posted February 25, 2012 So... Remember the jobs script? I'm just 99% to complete it and i really need help on this one guys, please! ___________________________________________________________________________________________________________ Client DeliveryLocations = { "-1838, 14, 16, 0", "-1708, 12, 4, 0", "-2464, 787, 36, 0", "-1935, 272, 42, 0", "653, 1691, 8, 0", "1052, 2088, 11, 0", "2185, 1976, 11, 0", "2868, 2577, 11, 0", "2244, 2234, 11, 0", "2351, 1891, 11, 0", "2842, 899, 11, 0", "2793, -2417, 14, 0", "2057, -2195, 14, 0", "1619, -1554, 14, 0", "988, -913, 43, 0", "1340, 285, 20, 0", "2260, -85, 27, 0", "708, -607, 17, 0", "202, -173, 2, 0", "-546, -499, 26, 0", "-1019, -649, 33, 0", "-165, 1016, 21, 0", "273, 1344, 12, 0" } ----------------------------------------------------------- local sWidth,sHeight = guiGetScreenSize() local loca = {} local DeliveryLocationTableSize = table.maxn ( DeliveryLocations ) local randomLocationIdx = math.random ( 1, DeliveryLocationTableSize ) local locString = tostring( DeliveryLocations[randomLocationIdx] ) loca.Location = split ( locString, string.byte( "," ) ) local DelX = loca.Location[1] local DelY = loca.Location[2] local DelZ = loca.Location[3] JobStart = createColSphere( -50, -271, 5.7, 1 ) JobStartM = createMarker( -50, -271, 5.7, "cylinder", 1, 0, 200, 0 ) JobStartB = createBlipAttachedTo( JobStart, 58 ) function giveVehicle( theElement ) if ( theElement == getLocalPlayer() ) then removeEventHandler("onClientColShapeHit",JobStart,giveVehicle) triggerServerEvent("start",root, theElement) addEventHandler("onClientRender",root,renderHP) destroyElement(JobStart) destroyElement(JobStartM) destroyElement(JobStartB) end end addEventHandler("onClientColShapeHit",JobStart,giveVehicle) addEvent("HP",true) addEventHandler("HP",root, function(mVehicle, mTrailer) TruckHP = getElementHealth(mVehicle) TrailerHP = getElementHealth(mTrailer) TruckHP2 = tonumber(TruckHP) TrailerHP2 = tonumber(TrailerHP) TruckHPF = math.ceil(TruckHP2) TrailerHPF = math.ceil(TrailerHP2) end ) function renderHP() truHP = dxDrawText("HP(Truck): " .. tostring(TruckHPF) .. "", sWidth/1.2,sHeight-47, sWidth, sHeight ) traHP = dxDrawText("HP(Trailer): " .. tostring(TrailerHPF) .. "", sWidth/1.2,sHeight-57, sWidth, sHeight ) end addEvent("trailerAtt",true) addEventHandler("trailerAtt",root, function() Destiny = createColSphere( DelX, DelY, DelZ, 3 ) DestinyM = createMarker( DelX, DelY, DelZ, "cylinder", 3, 0, 200, 0 ) DestinyB = createBlipAttachedTo( Destiny, 52 ) addEventHandler("onClientColShapeHit",Destiny,Reward) end ) addEvent("trailerDet",true) addEventHandler("trailerDet",root, function() removeEventHandler("onClientRender",root,renderHP) destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end ) addEvent("markersOn",true) addEventHandler("markersOn",root, function() JobStart = createColSphere( -50, -271, 5.7, 1 ) JobStartM = createMarker( -50, -271, 5.7, "cylinder", 1, 0, 200, 0 ) JobStartB = createBlipAttachedTo( JobStart, 58 ) addEventHandler("onClientColShapeHit",JobStart,giveVehicle) end ) addEvent("destroyWin",true) addEventHandler("destroyWin",root, function( theElement ) if ( theElement == getLocalPlayer() ) then removeEventHandler("onClientRender",root,renderHP) JobStart = createColSphere( -50, -271, 5.7, 1 ) JobStartM = createMarker( -50, -271, 5.7, "cylinder", 1, 0, 200, 0 ) JobStartB = createBlipAttachedTo( JobStart, 58 ) addEventHandler("onClientColShapeHit",JobStart,giveVehicle) end end ) addEvent("destroyFail",true) addEventHandler("destroyFail",root, function() removeEventHandler("onClientRender",root,renderHP) if (Destiny) then if (DestinyM) then if (DestinyB) then removeEventHandler("onClientRender",root,renderHP) destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end end end end ) addEvent("destroyFailE",true) addEventHandler("destroyFailE",root, function() removeEventHandler("onClientRender",root,renderHP) if (Destiny) then if (DestinyM) then if (DestinyB) then destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end end end end ) function Reward( theElement ) if ( theElement == getLocalPlayer() ) then removeEventHandler("onClientRender",root,renderHP) triggerServerEvent("win",root, theElement) destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end end Server addEvent("start",true) addEventHandler("start",root, function( theElement ) if theElement then mVehicle = createVehicle( 403, -22, -291, 6, 0, 0, 180 ) mTrailer = createVehicle ( 435, -14, -285, 7, 0, 0, 180 ) triggerClientEvent("HP",root,mVehicle,mTrailer) warpPedIntoVehicle(theElement, mVehicle) end end ) function FailE() if (source == mTrailer or mVehicle) then outputChatBox("Congratulations, you've earned a free...", getVehicleController(source), 0, 255, 0) setTimer( outputChatBox, 1000, 1, "GTFO. For making the vehicle go BOOM! And we ain't paying the hospital.", getVehicleController(source), 255, 0, 0 ) triggerClientEvent("markersOn",root) triggerClientEvent("destroyFail",root) destroyElement(mVehicle) destroyElement(mTrailer) end end addEventHandler("onVehicleExplode",root,FailE) addEvent("win",true) addEventHandler("win",root, function( theElement ) if theElement then vHP = getElementHealth(mVehicle) vTHP = getElementHealth(mTrailer) Money = 3000 + math.ceil(vHP) + math.ceil(vTHP) outputChatBox("Thanks, your reward is " .. Money .. "$", theElement, 0, 255, 0) triggerClientEvent("destroyWin",root, theElement) givePlayerMoney( theElement, Money) destroyElement(mVehicle) destroyElement(mTrailer) end end ) function attachT( theTruck ) if (source == mTrailer) then outputChatBox("Deliver these parts to the indicated location. Do no step out of the vehicle or loose your trailer. if so YOU'RE FIRED.", getVehicleController(theTruck), 0, 255, 0) triggerClientEvent("trailerAtt",root) end end addEventHandler("onTrailerAttach",root,attachT) function detachT( theTruck ) if (source == mTrailer) then outputChatBox("Nice fail, you just lost your trailer.", getVehicleController(theTruck), 0, 255, 0) setTimer(outputChatBox,1500,1,"Oh yeah... YOU'RE FIRED.", getVehicleController(theTruck), 255, 0, 0) triggerClientEvent("trailerDet",root) triggerClientEvent("markersOn",root) destroyElement(mVehicle) destroyElement(mTrailer) end end addEventHandler("onTrailerDetach",root,detachT) function Fail( theVehicle ) if (source) and ( theVehicle == mVehicle) then outputChatBox("Congratulations, you've earned a free...", source, 0, 255, 0) setTimer( outputChatBox, 1000, 1, "GTFO.", source, 255, 0, 0 ) triggerClientEvent("markersOn",root) triggerClientEvent("destroyFail",root, source) destroyElement(mVehicle) destroyElement(mTrailer) end end addEventHandler("onPlayerVehicleExit",root,Fail) The problem is: I'm trying to use math.ceil and tostring. To get the exact vehicle HP, and because the vehicles are created server-side and i can't just get the element hp. I needed to create an event. So everythign is perfect. But Health does not update. Link to comment
Jaysds1 Posted February 25, 2012 Share Posted February 25, 2012 Use OnVehicleDamage(Server-Sided) to update the health. Link to comment
Castillo Posted February 25, 2012 Share Posted February 25, 2012 Try this: DeliveryLocations = { "-1838, 14, 16, 0", "-1708, 12, 4, 0", "-2464, 787, 36, 0", "-1935, 272, 42, 0", "653, 1691, 8, 0", "1052, 2088, 11, 0", "2185, 1976, 11, 0", "2868, 2577, 11, 0", "2244, 2234, 11, 0", "2351, 1891, 11, 0", "2842, 899, 11, 0", "2793, -2417, 14, 0", "2057, -2195, 14, 0", "1619, -1554, 14, 0", "988, -913, 43, 0", "1340, 285, 20, 0", "2260, -85, 27, 0", "708, -607, 17, 0", "202, -173, 2, 0", "-546, -499, 26, 0", "-1019, -649, 33, 0", "-165, 1016, 21, 0", "273, 1344, 12, 0" } ----------------------------------------------------------- local sWidth,sHeight = guiGetScreenSize() local loca = {} local DeliveryLocationTableSize = table.maxn ( DeliveryLocations ) local randomLocationIdx = math.random ( 1, DeliveryLocationTableSize ) local locString = tostring( DeliveryLocations[randomLocationIdx] ) loca.Location = split ( locString, string.byte( "," ) ) local DelX = loca.Location[1] local DelY = loca.Location[2] local DelZ = loca.Location[3] JobStart = createColSphere( -50, -271, 5.7, 1 ) JobStartM = createMarker( -50, -271, 5.7, "cylinder", 1, 0, 200, 0 ) JobStartB = createBlipAttachedTo( JobStart, 58 ) local vehicle = nil local trailer = nil function giveVehicle( theElement ) if ( theElement == getLocalPlayer() ) then removeEventHandler("onClientColShapeHit",JobStart,giveVehicle) triggerServerEvent("start",root, theElement) addEventHandler("onClientRender",root,renderHP) destroyElement(JobStart) destroyElement(JobStartM) destroyElement(JobStartB) end end addEventHandler("onClientColShapeHit",JobStart,giveVehicle) addEvent("HP",true) addEventHandler("HP",root, function(mVehicle, mTrailer) vehicle = mVehicle trailer = mTrailer end ) function renderHP() if (isElement(vehicle) and isElement(trailer)) then TruckHP = getElementHealth(vehicle) TrailerHP = getElementHealth(trailer) TruckHP2 = tonumber(TruckHP) TrailerHP2 = tonumber(TrailerHP) TruckHPF = math.ceil(TruckHP2) TrailerHPF = math.ceil(TrailerHP2) truHP = dxDrawText("HP(Truck): " .. tostring(TruckHPF) .. "", sWidth/1.2,sHeight-47, sWidth, sHeight ) traHP = dxDrawText("HP(Trailer): " .. tostring(TrailerHPF) .. "", sWidth/1.2,sHeight-57, sWidth, sHeight ) end end addEvent("trailerAtt",true) addEventHandler("trailerAtt",root, function() Destiny = createColSphere( DelX, DelY, DelZ, 3 ) DestinyM = createMarker( DelX, DelY, DelZ, "cylinder", 3, 0, 200, 0 ) DestinyB = createBlipAttachedTo( Destiny, 52 ) addEventHandler("onClientColShapeHit",Destiny,Reward) end ) addEvent("trailerDet",true) addEventHandler("trailerDet",root, function() removeEventHandler("onClientRender",root,renderHP) destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end ) addEvent("markersOn",true) addEventHandler("markersOn",root, function() JobStart = createColSphere( -50, -271, 5.7, 1 ) JobStartM = createMarker( -50, -271, 5.7, "cylinder", 1, 0, 200, 0 ) JobStartB = createBlipAttachedTo( JobStart, 58 ) addEventHandler("onClientColShapeHit",JobStart,giveVehicle) end ) addEvent("destroyWin",true) addEventHandler("destroyWin",root, function( theElement ) if ( theElement == getLocalPlayer() ) then removeEventHandler("onClientRender",root,renderHP) JobStart = createColSphere( -50, -271, 5.7, 1 ) JobStartM = createMarker( -50, -271, 5.7, "cylinder", 1, 0, 200, 0 ) JobStartB = createBlipAttachedTo( JobStart, 58 ) addEventHandler("onClientColShapeHit",JobStart,giveVehicle) end end ) addEvent("destroyFail",true) addEventHandler("destroyFail",root, function() removeEventHandler("onClientRender",root,renderHP) if (Destiny) then if (DestinyM) then if (DestinyB) then removeEventHandler("onClientRender",root,renderHP) destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end end end end ) addEvent("destroyFailE",true) addEventHandler("destroyFailE",root, function() removeEventHandler("onClientRender",root,renderHP) if (Destiny) then if (DestinyM) then if (DestinyB) then destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end end end end ) function Reward( theElement ) if ( theElement == getLocalPlayer() ) then removeEventHandler("onClientRender",root,renderHP) triggerServerEvent("win",root, theElement) destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end end Link to comment
Kenix Posted February 25, 2012 Share Posted February 25, 2012 (edited) Addation to your code.WolfPire Client Find addEvent("HP",true) addEventHandler("HP",root, function(mVehicle, mTrailer) TruckHP = getElementHealth(mVehicle) TrailerHP = getElementHealth(mTrailer) TruckHP2 = tonumber(TruckHP) TrailerHP2 = tonumber(TrailerHP) TruckHPF = math.ceil(TruckHP2) TrailerHPF = math.ceil(TrailerHP2) end ) function renderHP() truHP = dxDrawText("HP(Truck): " .. tostring(TruckHPF) .. "", sWidth/1.2,sHeight-47, sWidth, sHeight ) traHP = dxDrawText("HP(Trailer): " .. tostring(TrailerHPF) .. "", sWidth/1.2,sHeight-57, sWidth, sHeight ) end Replace local TruckHP,TrailerHP addEvent( "HP",true ) addEventHandler( "HP",root, function( mVehicle, mTrailer ) TruckHP = getElementHealth( mVehicle ) TrailerHP = getElementHealth( mTrailer ) end ) function renderHP( ) if TruckHP and TrailerHP then TruckHPF = math.ceil( TruckHP2 ) TrailerHPF = math.ceil( TrailerHP2 ) dxDrawText( "HP(Truck): " .. tostring( TruckHPF ) .. "", sWidth/1.2,sHeight-47, sWidth, sHeight ) dxDrawText( "HP(Trailer): " .. tostring( TrailerHPF ) .. "", sWidth/1.2,sHeight-57, sWidth, sHeight ) end end Server addEventHandler( 'onVehicleDamage',root, function( ) if source == mVehicle or source == mTrailer then triggerClientEvent( "HP",root,mVehicle,mTrailer ) end end ) addEventHandler( 'onVehicleExplode',root, function( ) if source == mVehicle or source == mTrailer then triggerClientEvent( "HP",root,mVehicle,mTrailer ) end end ) Or i think better create custom element. And in client side loop this elements and check ( getElementHealth ,... ) Like this Server addEvent( "start",true ) addEventHandler( "start",root, function( theElement ) if theElement then local uTrailerElement = createElement( 'uCars','uTrailer' ) local uRootElement = createElement( 'uCars','uRoot' ) mVehicle = createVehicle( 403, -22, -291, 6, 0, 0, 180 ) mTrailer = createVehicle ( 435, -14, -285, 7, 0, 0, 180 ) setElementParent( mVehicle,uRootElement ) setElementParent( mTrailer,uTrailerElement ) --warpPedIntoVehicle( theElement, mVehicle ) warpPedIntoVehicle( theElement, uRootElement ) end end ) Client function renderHP( ) for _,v in pairs( getElementsByType 'uCars' ) then if getElementType( v ) == 'uTrailer' then dxDrawText( "HP(Trailer): " .. tostring( math.floor( getElementHealth( v ) ) ) .. "", sWidth/1.2,sHeight-57, sWidth, sHeight ) end if getElementType( v ) == 'uRoot' then dxDrawText( "HP(Truck): " .. tostring( math.floor( getElementHealth( v ) ) ) .. "", sWidth/1.2,sHeight-47, sWidth, sHeight ) end end end Edited February 25, 2012 by Guest Link to comment
Scooby Posted February 25, 2012 Share Posted February 25, 2012 once again... bombarded with so many choices of fix... (kenix... u should work on ur efficiency - i must admit tho... u do give me the odd giggle reading thru ur code) another thing to look into once u have it working is, ur triggering all client events when u trigger, im not sure if theres a reason for this but im guessing not... im guessing that ur testing alone so this might not be an issue yet. but basically: triggerClientEvent("HP",root,mVehicle,mTrailer) will be triggered for ALL clients... u should be using: triggerClientEvent(thePlayerOnTheJob,"HP",root,mVehicle,mTrailer) which will only trigger for the player on the job. Link to comment
Kenix Posted February 25, 2012 Share Posted February 25, 2012 (kenix... u should work on ur efficiency - i must admit tho... u do give me the odd giggle reading thru ur code) Not understand you ... triggerClientEvent("HP",root,mVehicle,mTrailer) will be triggered for ALL clients... It's him code ,maybe he need trigger for all elements in tree. https://wiki.multitheftauto.com/wiki/Element_tree Link to comment
Scooby Posted February 25, 2012 Share Posted February 25, 2012 well he doesnt need a loop just to get the health of 1 vehicle and 1 trailer, also, getting the health in onClientRender, rounding it etc... is less efficient than using a variable which can be updated when the vehicle health changes.. either by using setElementData or triggerClientEvent with an onVehicleDamage Event handler set to that vehicle. while using scripts... try to think how they would work with 100 of the same running... also on server with a lot of people. a working script is not the same as a script working efficiently. Link to comment
Castillo Posted February 25, 2012 Share Posted February 25, 2012 -- client side: DeliveryLocations = { "-1838, 14, 16, 0", "-1708, 12, 4, 0", "-2464, 787, 36, 0", "-1935, 272, 42, 0", "653, 1691, 8, 0", "1052, 2088, 11, 0", "2185, 1976, 11, 0", "2868, 2577, 11, 0", "2244, 2234, 11, 0", "2351, 1891, 11, 0", "2842, 899, 11, 0", "2793, -2417, 14, 0", "2057, -2195, 14, 0", "1619, -1554, 14, 0", "988, -913, 43, 0", "1340, 285, 20, 0", "2260, -85, 27, 0", "708, -607, 17, 0", "202, -173, 2, 0", "-546, -499, 26, 0", "-1019, -649, 33, 0", "-165, 1016, 21, 0", "273, 1344, 12, 0" } ----------------------------------------------------------- local sWidth,sHeight = guiGetScreenSize() local loca = {} local DeliveryLocationTableSize = table.maxn ( DeliveryLocations ) local randomLocationIdx = math.random ( 1, DeliveryLocationTableSize ) local locString = tostring( DeliveryLocations[randomLocationIdx] ) loca.Location = split ( locString, string.byte( "," ) ) local DelX = loca.Location[1] local DelY = loca.Location[2] local DelZ = loca.Location[3] JobStart = createColSphere( -50, -271, 5.7, 1 ) JobStartM = createMarker( -50, -271, 5.7, "cylinder", 1, 0, 200, 0 ) JobStartB = createBlipAttachedTo( JobStart, 58 ) local vehicle local trailer function giveVehicle( theElement ) if ( theElement == getLocalPlayer() ) then triggerServerEvent("start",root, theElement) addEventHandler("onClientRender",root,renderHP) end end addEventHandler("onClientColShapeHit",JobStart,giveVehicle) addEvent("HP",true) addEventHandler("HP",root, function(mVehicle, mTrailer) vehicle = math.ceil(tonumber(mVehicle)) trailer = math.ceil(tonumber(mTrailer)) end ) function renderHP() dxDrawText("HP(Truck): " .. tostring(vehicle) .. "", sWidth/1.2,sHeight-47, sWidth, sHeight ) dxDrawText("HP(Trailer): " .. tostring(trailer) .. "", sWidth/1.2,sHeight-57, sWidth, sHeight ) end addEvent("trailerAtt",true) addEventHandler("trailerAtt",root, function() Destiny = createColSphere( DelX, DelY, DelZ, 3 ) DestinyM = createMarker( DelX, DelY, DelZ, "cylinder", 3, 0, 200, 0 ) DestinyB = createBlipAttachedTo( Destiny, 52 ) addEventHandler("onClientColShapeHit",Destiny,Reward) end ) addEvent("trailerDet",true) addEventHandler("trailerDet",root, function() removeEventHandler("onClientRender",root,renderHP) destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end ) addEvent("destroyWin",true) addEventHandler("destroyWin",root, function( theElement ) if ( theElement == getLocalPlayer() ) then removeEventHandler("onClientRender",root,renderHP) end end ) addEvent("destroyFail",true) addEventHandler("destroyFail",root, function() removeEventHandler("onClientRender",root,renderHP) if (Destiny) then if (DestinyM) then if (DestinyB) then removeEventHandler("onClientRender",root,renderHP) destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end end end end ) addEvent("destroyFailE",true) addEventHandler("destroyFailE",root, function() removeEventHandler("onClientRender",root,renderHP) if (Destiny) then if (DestinyM) then if (DestinyB) then destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end end end end ) function Reward( theElement ) if ( theElement == getLocalPlayer() ) then removeEventHandler("onClientRender",root,renderHP) triggerServerEvent("win",root, theElement) destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end end -- server side: local vehicles = {} addEvent("start",true) addEventHandler("start",root, function( theElement ) if theElement then if (not vehicles[theElement]) then vehicles[theElement] = {} end vehicles[theElement]["truck"] = createVehicle( 403, -22, -291, 6, 0, 0, 180 ) addEventHandler("onVehicleExplode",vehicles[theElement]["truck"],FailE) vehicles[theElement]["trailer"] = createVehicle ( 435, -14, -285, 7, 0, 0, 180 ) addEventHandler("onVehicleExplode",vehicles[theElement]["trailer"],FailE) setElementData(vehicles[theElement]["trailer"],"truck",vehicles[theElement]["truck"]) setElementData(vehicles[theElement]["truck"],"trailer",vehicles[theElement]["trailer"]) addEventHandler("onTrailerAttach",vehicles[theElement]["trailer"],attachT) addEventHandler("onTrailerDetach",vehicles[theElement]["trailer"],detachT) triggerClientEvent(theElement,"HP",root,getElementHealth(vehicles[theElement]["truck"]),getElementHealth(vehicles[theElement]["trailer"])) warpPedIntoVehicle(theElement, vehicles[theElement]["truck"]) addEventHandler("onVehicleDamage", vehicles[theElement]["truck"], function () local thePlayer = getVehicleOccupant(source) if (thePlayer) then local trailer = getVehicleTowedByVehicle(source) if (trailer) then trailerHealth = getElementHealth(trailer) else trailerHealth = 0 end triggerClientEvent(thePlayer,"HP",root,getElementHealth(source), trailerHealth) end end ) addEventHandler("onVehicleDamage", vehicles[theElement]["trailer"], function () if getVehicleTowingVehicle(source) then local thePlayer = getVehicleOccupant(getVehicleTowingVehicle(source)) if (thePlayer) then triggerClientEvent(thePlayer,"HP",root,getElementHealth(source),getElementHealth(getVehicleTowingVehicle(source))) end end end ) end end ) function FailE() local thePlayer = getVehicleController(source) outputChatBox("Congratulations, you've earned a free...", thePlayer, 0, 255, 0) setTimer( outputChatBox, 1000, 1, "GTFO. For making the vehicle go BOOM! And we ain't paying the hospital.", thePlayer, 255, 0, 0 ) triggerClientEvent(thePlayer,"destroyFail",thePlayer) if (getVehicleType(source) == "Trailer") then local truck = getElementData(source,"truck") if isElement(truck) then destroyElement(truck) end else local trailer = getElementData(source,"trailer") if isElement(trailer) then destroyElement(trailer) end end destroyElement(source) triggerClientEvent(thePlayer,"HP",root,0,0) end addEvent("win",true) addEventHandler("win",root, function( theElement ) if theElement then vHP = getElementHealth(vehicles[theElement]["truck"]) vTHP = getElementHealth(vehicles[theElement]["trailer"]) Money = 3000 + math.ceil(vHP) + math.ceil(vTHP) outputChatBox("Thanks, your reward is " .. Money .. "$", theElement, 0, 255, 0) triggerClientEvent(theElement, "destroyWin", theElement) givePlayerMoney( theElement, Money) if isElement(vehicles[theElement]["truck"]) then destroyElement(vehicles[theElement]["truck"]) end if isElement(vehicles[theElement]["trailer"]) then destroyElement(vehicles[theElement]["trailer"]) end end end ) function attachT( theTruck ) local thePlayer = getVehicleController(theTruck) outputChatBox("Deliver these parts to the indicated location. Do no step out of the vehicle or loose your trailer. if so YOU'RE FIRED.", thePlayer, 0, 255, 0) triggerClientEvent(thePlayer,"trailerAtt",thePlayer) end function detachT( theTruck ) local thePlayer = getVehicleController(theTruck) outputChatBox("Nice fail, you just lost your trailer.", thePlayer, 0, 255, 0) setTimer(outputChatBox,1500,1,"Oh yeah... YOU'RE FIRED.", thePlayer, 255, 0, 0) triggerClientEvent(thePlayer,"trailerDet",thePlayer) if isElement(vehicles[thePlayer]["truck"]) then destroyElement(vehicles[thePlayer]["truck"]) end if isElement(vehicles[thePlayer]["trailer"]) then destroyElement(vehicles[thePlayer]["trailer"]) end end function Fail( theVehicle ) if (vehicles[source]["truck"] == theVehicle) then outputChatBox("Congratulations, you've earned a free...", source, 0, 255, 0) setTimer( outputChatBox, 1000, 1, "GTFO.", source, 255, 0, 0 ) triggerClientEvent(source, "destroyFail", source) if isElement(vehicles[source]["truck"]) then destroyElement(vehicles[source]["truck"]) end if isElement(vehicles[source]["trailer"]) then destroyElement(vehicles[source]["trailer"]) end end end addEventHandler("onPlayerVehicleExit",root,Fail) Link to comment
WolfPire Posted February 25, 2012 Author Share Posted February 25, 2012 -- client side: DeliveryLocations = { "-1838, 14, 16, 0", "-1708, 12, 4, 0", "-2464, 787, 36, 0", "-1935, 272, 42, 0", "653, 1691, 8, 0", "1052, 2088, 11, 0", "2185, 1976, 11, 0", "2868, 2577, 11, 0", "2244, 2234, 11, 0", "2351, 1891, 11, 0", "2842, 899, 11, 0", "2793, -2417, 14, 0", "2057, -2195, 14, 0", "1619, -1554, 14, 0", "988, -913, 43, 0", "1340, 285, 20, 0", "2260, -85, 27, 0", "708, -607, 17, 0", "202, -173, 2, 0", "-546, -499, 26, 0", "-1019, -649, 33, 0", "-165, 1016, 21, 0", "273, 1344, 12, 0" } ----------------------------------------------------------- local sWidth,sHeight = guiGetScreenSize() local loca = {} local DeliveryLocationTableSize = table.maxn ( DeliveryLocations ) local randomLocationIdx = math.random ( 1, DeliveryLocationTableSize ) local locString = tostring( DeliveryLocations[randomLocationIdx] ) loca.Location = split ( locString, string.byte( "," ) ) local DelX = loca.Location[1] local DelY = loca.Location[2] local DelZ = loca.Location[3] JobStart = createColSphere( -50, -271, 5.7, 1 ) JobStartM = createMarker( -50, -271, 5.7, "cylinder", 1, 0, 200, 0 ) JobStartB = createBlipAttachedTo( JobStart, 58 ) local vehicle local trailer function giveVehicle( theElement ) if ( theElement == getLocalPlayer() ) then removeEventHandler("onClientColShapeHit",JobStart,giveVehicle) triggerServerEvent("start",root, theElement) addEventHandler("onClientRender",root,renderHP) destroyElement(JobStart) destroyElement(JobStartM) destroyElement(JobStartB) end end addEventHandler("onClientColShapeHit",JobStart,giveVehicle) addEvent("HP",true) addEventHandler("HP",root, function(mVehicle, mTrailer) vehicle = math.ceil(tonumber(mVehicle)) trailer = math.ceil(tonumber(mTrailer)) end ) function renderHP() dxDrawText("HP(Truck): " .. tostring(vehicle) .. "", sWidth/1.2,sHeight-47, sWidth, sHeight ) dxDrawText("HP(Trailer): " .. tostring(trailer) .. "", sWidth/1.2,sHeight-57, sWidth, sHeight ) end addEvent("trailerAtt",true) addEventHandler("trailerAtt",root, function() Destiny = createColSphere( DelX, DelY, DelZ, 3 ) DestinyM = createMarker( DelX, DelY, DelZ, "cylinder", 3, 0, 200, 0 ) DestinyB = createBlipAttachedTo( Destiny, 52 ) addEventHandler("onClientColShapeHit",Destiny,Reward) end ) addEvent("trailerDet",true) addEventHandler("trailerDet",root, function() removeEventHandler("onClientRender",root,renderHP) destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end ) addEvent("markersOn",true) addEventHandler("markersOn",root, function() JobStart = createColSphere( -50, -271, 5.7, 1 ) JobStartM = createMarker( -50, -271, 5.7, "cylinder", 1, 0, 200, 0 ) JobStartB = createBlipAttachedTo( JobStart, 58 ) addEventHandler("onClientColShapeHit",JobStart,giveVehicle) end ) addEvent("destroyWin",true) addEventHandler("destroyWin",root, function( theElement ) if ( theElement == getLocalPlayer() ) then removeEventHandler("onClientRender",root,renderHP) JobStart = createColSphere( -50, -271, 5.7, 1 ) JobStartM = createMarker( -50, -271, 5.7, "cylinder", 1, 0, 200, 0 ) JobStartB = createBlipAttachedTo( JobStart, 58 ) addEventHandler("onClientColShapeHit",JobStart,giveVehicle) end end ) addEvent("destroyFail",true) addEventHandler("destroyFail",root, function() removeEventHandler("onClientRender",root,renderHP) if (Destiny) then if (DestinyM) then if (DestinyB) then removeEventHandler("onClientRender",root,renderHP) destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end end end end ) addEvent("destroyFailE",true) addEventHandler("destroyFailE",root, function() removeEventHandler("onClientRender",root,renderHP) if (Destiny) then if (DestinyM) then if (DestinyB) then destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end end end end ) function Reward( theElement ) if ( theElement == getLocalPlayer() ) then removeEventHandler("onClientRender",root,renderHP) triggerServerEvent("win",root, theElement) destroyElement(Destiny) destroyElement(DestinyM) destroyElement(DestinyB) end end -- server side: local vehicles = {} addEvent("start",true) addEventHandler("start",root, function( theElement ) if theElement then if (not vehicles[theElement]) then vehicles[theElement] = {} end vehicles[theElement]["truck"] = createVehicle( 403, -22, -291, 6, 0, 0, 180 ) addEventHandler("onVehicleExplode",vehicles[theElement]["truck"],FailE) vehicles[theElement]["trailer"] = createVehicle ( 435, -14, -285, 7, 0, 0, 180 ) addEventHandler("onVehicleExplode",vehicles[theElement]["trailer"],FailE) addEventHandler("onTrailerAttach",vehicles[theElement]["trailer"],attachT) addEventHandler("onTrailerDetach",vehicles[theElement]["trailer"],detachT) addEventHandler("onPlayerVehicleExit",vehicles[theElement]["truck"],Fail) triggerClientEvent(theElement,"HP",root,getElementHealth(vehicles[theElement]["truck"]),getElementHealth(vehicles[theElement]["trailer"])) warpPedIntoVehicle(theElement, vehicles[theElement]["truck"]) addEventHandler("onVehicleDamage", vehicles[theElement]["truck"], function () local thePlayer = getVehicleOccupant(source) if (thePlayer) then triggerClientEvent(thePlayer,"HP",root,getElementHealth(source),getElementHealth(getVehicleTowedByVehicle(source))) end end ) addEventHandler("onVehicleDamage", vehicles[theElement]["trailer"], function () local thePlayer = getVehicleOccupant(getVehicleTowingVehicle(source)) if (thePlayer) then triggerClientEvent(thePlayer,"HP",root,getElementHealth(source),getElementHealth(getVehicleTowingVehicle(source))) end end ) end end ) function FailE() local thePlayer = getVehicleController(source) outputChatBox("Congratulations, you've earned a free...", thePlayer, 0, 255, 0) setTimer( outputChatBox, 1000, 1, "GTFO. For making the vehicle go BOOM! And we ain't paying the hospital.", thePlayer, 255, 0, 0 ) triggerClientEvent("markersOn",root) triggerClientEvent("destroyFail",root) destroyElement(source) triggerClientEvent(thePlayer,"HP",root,0,0) end addEvent("win",true) addEventHandler("win",root, function( theElement ) if theElement then vHP = getElementHealth(mVehicle) vTHP = getElementHealth(mTrailer) Money = 3000 + math.ceil(vHP) + math.ceil(vTHP) outputChatBox("Thanks, your reward is " .. Money .. "$", theElement, 0, 255, 0) triggerClientEvent("destroyWin",root, theElement) givePlayerMoney( theElement, Money) destroyElement(mVehicle) destroyElement(mTrailer) end end ) function attachT( theTruck ) outputChatBox("Deliver these parts to the indicated location. Do no step out of the vehicle or loose your trailer. if so YOU'RE FIRED.", getVehicleController(theTruck), 0, 255, 0) triggerClientEvent("trailerAtt",root) end function detachT( theTruck ) local thePlayer = getVehicleController(theTruck) outputChatBox("Nice fail, you just lost your trailer.", thePlayer, 0, 255, 0) setTimer(outputChatBox,1500,1,"Oh yeah... YOU'RE FIRED.", thePlayer, 255, 0, 0) triggerClientEvent("trailerDet",root) triggerClientEvent("markersOn",root) if isElement(vehicles[thePlayer]["truck"]) then destroyElement(vehicles[thePlayer]["truck"]) end if isElement(vehicles[thePlayer]["trailer"]) then destroyElement(vehicles[thePlayer]["trailer"]) end end function Fail( theVehicle ) outputChatBox("Congratulations, you've earned a free...", source, 0, 255, 0) setTimer( outputChatBox, 1000, 1, "GTFO.", source, 255, 0, 0 ) triggerClientEvent("markersOn",root) triggerClientEvent("destroyFail",root, source) if isElement(vehicles[source]["truck"]) then destroyElement(vehicles[source]["truck"]) end if isElement(vehicles[source]["trailer"]) then destroyElement(vehicles[source]["trailer"]) end end Solid, Your code is winning so far. Tho' it outputs me many errors in the debug they all say... "ERROR: JobsONG//jobs_c.lua:37: bad argument #1 to 'ceil' (number expected, got nil)"... Whenever i crash the vehicle. Kenix, your codes were correct but it had many errors that prevent the script from working. Thanks for the help anyways. Scooby, actually it's only triggered by the localPlayer, tested with other people and works perfectly. Link to comment
Castillo Posted February 25, 2012 Share Posted February 25, 2012 Copy the server side again. Link to comment
WolfPire Posted February 25, 2012 Author Share Posted February 25, 2012 Copy the server side again. Works now but we got 2 issues. 1. Trailer's HP will be "0". (Unless attached) 2. Trailer won't loose health. Link to comment
Castillo Posted February 25, 2012 Share Posted February 25, 2012 I've tried to damage the trailer in a lot of ways, but no luck, I think is not possible if you don't shoot at it. Link to comment
WolfPire Posted February 25, 2012 Author Share Posted February 25, 2012 I've tried to damage the trailer in a lot of ways, but no luck, I think is not possible if you don't shoot at it. Possibly an MTA Problem?... Well i'll just get the Truck's HP then. EDIT: function Fail( theVehicle ) outputChatBox("Congratulations, you've earned a free...", source, 0, 255, 0) setTimer( outputChatBox, 1000, 1, "GTFO.", source, 255, 0, 0 ) triggerClientEvent("markersOn",root) triggerClientEvent("destroyFail",root, source) if isElement(vehicles[source]["truck"]) then destroyElement(vehicles[source]["truck"]) end if isElement(vehicles[source]["trailer"]) then destroyElement(vehicles[source]["trailer"]) end end ^ Server. Doesn't work. Link to comment
Castillo Posted February 26, 2012 Share Posted February 26, 2012 What part doesn't work? I don't see any problem. Link to comment
WolfPire Posted February 26, 2012 Author Share Posted February 26, 2012 What part doesn't work? I don't see any problem. When the vehicle explodes, it doesn't get destroyed. Link to comment
Castillo Posted February 26, 2012 Share Posted February 26, 2012 Copy the server side again, I've added to destroy the trailer when the truck explodes and if the trailer explodes it'll destroy the truck. Link to comment
WolfPire Posted February 26, 2012 Author Share Posted February 26, 2012 Console outputs error: " ERROR: JobsONG/jobs_s.lua:56: ')' expected near 'kw2' " <---- ??? ^ Another error with the same but saying that the loading of the script failed. Link to comment
Castillo Posted February 26, 2012 Share Posted February 26, 2012 That's a forum bug, copy the server side again, I removed the Lua tags. Link to comment
WolfPire Posted February 26, 2012 Author Share Posted February 26, 2012 That's a forum bug, copy the server side again, I removed the Lua tags. Works like charm Now one more thing, do the same. But as for when the player exit's the truck! After that, i gotta test the reward part and we're done in here =) P.S: In the explosión the text color doesn't change, any idea why this? Link to comment
Castillo Posted February 26, 2012 Share Posted February 26, 2012 When you exit the vehicle it should destroy both truck and trailer if exists, it doesn't work? Link to comment
WolfPire Posted February 26, 2012 Author Share Posted February 26, 2012 When you exit the vehicle it should destroy both truck and trailer if exists, it doesn't work? Doesn't work then D: Link to comment
Castillo Posted February 26, 2012 Share Posted February 26, 2012 Yeah, my mistake , copy the server side again, now it works . Link to comment
WolfPire Posted February 26, 2012 Author Share Posted February 26, 2012 I get an error when touching the reward marker. "ERROR: JobsONG/jobs_s.lua:72: bad argument #1 to 'ceil' (number expected, got boolean)" Link to comment
Castillo Posted February 26, 2012 Share Posted February 26, 2012 Yeah, I forgot to change some things, copy the server side script again. Link to comment
WolfPire Posted February 26, 2012 Author Share Posted February 26, 2012 It works now =D My system is complete. Thank you =) May i kiss you? Well.. better not if i'm not a girl. Thanks for you help! Everyone!!!! You're always welcome to my server in "Oriental Night Gaming" Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now