sir135 Posted May 26, 2011 Share Posted May 26, 2011 Скрипт работает только для последнего, зашедшего на сервер. Клиентская часть: addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource() ), function() triggerServerEvent ( "start_fuel", getRootElement(), getPlayerName(getLocalPlayer())) end ) addEvent("show_fuel",true) addEventHandler("show_fuel",getRootElement(), function(fuel, flag) prflag = flag fl = fuel fuelrender2() end ) addEventHandler("onClientRender", getRootElement(), function() if (prflag == 1) then fp = dxDrawImage(838,642,185,87, "fuel/images/fuelful.png", 0.0,0.0,0.0,tocolor(255, 255, 255, 255),false) end end ) function fuelrender2() if (prflag == 1) then fm = dxDrawImage(820+fl, 684, 50,26, "fuel/images/fuelmark.png", 0.0,0.0,0.0,tocolor(255, 255, 255, 255),false) end end addEventHandler("onClientRender", getRootElement(), fuelrender2) Серверная часть: refuel = 0 addEvent("start_fuel",true) addEventHandler("start_fuel",getRootElement(), function(nameCurrentPlayer) CurrentPlayer = getPlayerFromName(nameCurrentPlayer) bindKey ( CurrentPlayer , "i", "down", engine_operation) --bindKey ( CurrentPlayer , "l", "both", door_operation) fuelmark1 = createMarker ( 1944.852, -1769.554, 12.0125, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark2 = createMarker ( 2209.816, 2481.934, 9.8203, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark3 = createMarker ( 604.8804, 1705.273, 5.541, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark4 = createMarker ( -2414.49, 982.081, 44.2969, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark5 = createMarker ( -2244.623, -2561.828, 30.9219, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark6 = createMarker ( -1327.512, 2678.107, 49.0625, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark7 = createMarker ( -95.1488, -1174.303, 0.9281, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark8 = createMarker ( -1679.982, 408.9051, 6.2365, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark9 = createMarker ( 652.03, -571.34, 15.34, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark10 = createMarker ( -1605.897, -2714.252, 47.5335, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark11 = createMarker ( -1471.48, 1864.31, 31.64, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark12 = createMarker ( 1596.5, 2199.1, 9.83, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark13 = createMarker ( 2145.9, 2748.16, 9.83, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark14 = createMarker ( 2642.11, 1106.53, 9.83, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark15 = createMarker ( 2117.42, 920.42, 9.83, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark16 = createMarker ( 1381.68, 456.26, 18.91, "cylinder", 1.5, 255, 128, 0, 17 ) fuelmark17 = createMarker ( 1002.0087890625, -933.244140625, 41.1796875, "cylinder", 1.5, 255, 128, 0, 17 ) veh_check() end ) function engine_operation() if (isPedInVehicle (CurrentPlayer)) then if (fuel ~= 0) then setVehicleEngineState ( fv, not (getVehicleEngineState(fv))) else tryburn = math.random(1,9) if (tryburn == 5) then setVehicleEngineState ( fv, not (getVehicleEngineState(fv))) end end end end --[[function door_operation() setVehicleLocked ( fv, not (getVehicleLocked(fv))) end]] function veh_check() veh_check_timer = setTimer(veh_check, 5000, 1) if (isPedInVehicle (CurrentPlayer)) then fv = getPedOccupiedVehicle (CurrentPlayer) if (refuel == 0) then fuel = math.random(50,100) killTimer(veh_check_timer) decrease_fuel() else fuel = 100 killTimer(veh_check_timer) refuel = 0 decrease_fuel() end end end function decrease_fuel() dTimer = setTimer(decrease_fuel, 26000, 1) --3250 if isElement(fv) then if (isVehicleBlown (fv)) then flag = 0 triggerClientEvent(CurrentPlayer, "show_fuel", getRootElement(), fuel, flag) killTimer(dTimer) veh_check() end -- if (isElementInWater (fv)) then -- flag = 0 -- triggerClientEvent(CurrentPlayer, "show_fuel", getRootElement(), fuel, flag) -- killTimer(dTimer) -- veh_check() -- end else flag = 0 triggerClientEvent(CurrentPlayer, "show_fuel", getRootElement(), fuel, flag) killTimer(dTimer) veh_check() end if (isPedInVehicle (CurrentPlayer)) then fv = getPedOccupiedVehicle (CurrentPlayer) if (getElementData(fv,"fuel") == false) then fuel = math.random(50,100) setElementData(fv,"fuel",tonumber(fuel)) end fuel = tonumber(getElementData(fv,"fuel")) if (fuel > 0) then if getVehicleEngineState(fv) then fuel = fuel-1 flag = 1 setElementData(fv,"fuel",tonumber(fuel)) triggerClientEvent(CurrentPlayer, "show_fuel", getRootElement(), fuel, flag) else flag = 1 setElementData(fv,"fuel",tonumber(fuel)) triggerClientEvent(CurrentPlayer, "show_fuel", getRootElement(), fuel, flag) end else flag = 1 setElementData(fv,"fuel",0) triggerClientEvent(CurrentPlayer, "show_fuel", getRootElement(), fuel, flag) setVehicleEngineState ( fv, false ) end else if (fuel > 0) then if getVehicleEngineState(fv) then fuel = fuel-1 flag = 0 setElementData(fv,"fuel",tonumber(fuel)) triggerClientEvent(CurrentPlayer, "show_fuel", getRootElement(), fuel, flag) else flag = 0 setElementData(fv,"fuel",tonumber(fuel)) triggerClientEvent(CurrentPlayer, "show_fuel", getRootElement(), fuel, flag) end else flag = 0 setElementData(fv,"fuel",0) triggerClientEvent(CurrentPlayer, "show_fuel", getRootElement(), fuel, flag) setVehicleEngineState ( fv, false ) end end end addEventHandler( "onMarkerHit", getRootElement(), function(hitElement) if (getElementType( hitElement ) == "player") then if (source == fuelmark1) or (source == fuelmark2) or (source == fuelmark3) or (source == fuelmark4) or (source == fuelmark5) or (source == fuelmark6) or (source == fuelmark7) or (source == fuelmark8) or (source == fuelmark9) or (source == fuelmark10) or (source == fuelmark11) or (source == fuelmark12) or (source == fuelmark13) or (source == fuelmark14) or (source == fuelmark15) or (source == fuelmark16) or (source == fuelmark17) then if (isPedInVehicle ( hitElement )) then if (fuel < 100) then setVehicleFrozen ( fv, true ) playSoundFrontEnd ( hitElement, 46 ) refuel = 1 setElementData(fv,"fuel",100) flag = 1 setTimer(setVehicleFrozen, 1000, 1, fv, false ) veh_check() end end end end end ) Link to comment
MX_Master Posted May 26, 2011 Share Posted May 26, 2011 Никаких triggerServerEvent в простом скрипте с бензином не нужно, setElementData предостаточно. Всю эту серверную часть может делать клиент. Link to comment
Kenix Posted May 26, 2011 Share Posted May 26, 2011 Вычисления делай на клиенте иначе серву конец Советовал бы вообще весь код на клиенте делать а уж маркеры и т.п на серве. 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