Advertisement
Guest User

client_main

a guest
Nov 6th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.45 KB | None | 0 0
  1. [lua]addEvent("doSlenderClientPlaySound", true)
  2. addEvent("onSlenderClientTaschenlampe", true)
  3.  
  4. addEvent("doSlenderClientSendMessage", true)
  5.  
  6. -- VARIABLES --
  7. local slender_font = dxCreateFont("data/fonts/COPRGTB.ttf", 50)
  8.  
  9. sound = {}
  10. local textd = {}
  11.  
  12. local slendyshock = false
  13.  
  14. wasted = false
  15.  
  16. local s_en = false
  17.  
  18. taschenlampstate = true
  19.  
  20. textd["status"] = false
  21. textd["text"] = ""
  22. textd["timer"] = false
  23.  
  24. local sprinttimer
  25. local cantsprint = true
  26. local fade = 0
  27.  
  28. local atSelection = false
  29.  
  30. local select_button = {}
  31.  
  32. current_map = false
  33.  
  34. alpha_selection = {}
  35. alpha_selection["industry"] = 200
  36. alpha_selection["forest"] = 200
  37.  
  38. -- EVENTS AN FUNCTIONS --
  39.  
  40. addEventHandler("doSlenderClientPlaySound", getLocalPlayer(), function(url, bool)
  41.     playSound("data/sounds/"..url, bool)
  42. end)
  43.  
  44.  
  45. addEventHandler("onSlenderClientTaschenlampe", getLocalPlayer(), function(state)
  46.     if(fertig ~= true) then
  47.         if(state == true) then
  48.             setFogDistance(0)
  49.         else
  50.             setFogDistance(-500)
  51.         end
  52.         taschenlampstate = state
  53.     end
  54. end)
  55.  
  56.  
  57. local function collect_page(id)
  58.     pages = pages+1
  59.     pages_done[id] = true
  60.     triggerEvent("doSlenderClientSendMessage", localPlayer, "Pages "..pages.."/8")
  61.     playSound("data/sounds/page_collect.mp3", false)
  62.     if(pages == 1) then
  63.         sound["page1"] = playSound("data/sounds/music_page_1.mp3", true)
  64.     end
  65.     if(pages == 3) then
  66.         sound["page3"] = playSound("data/sounds/music_page_3.mp3", true)
  67.         setTimer(function()
  68.             destroyElement(sound["page1"])
  69.         end, 2000, 1)
  70.     end
  71.     if(pages == 6) then
  72.         sound["page6"] = playSound("data/sounds/music_page_6.mp3", true)
  73.         setTimer(function()
  74.             destroyElement(sound["page3"])
  75.         end, 2000, 1)
  76.     end
  77.     refresh_slender_ai(pages)
  78. end
  79.  
  80. local function slender_page_check()
  81.     for i = 1, 8, 1 do
  82.         local x, y, z = getElementPosition(localPlayer)
  83.         local x2, y2, z2 = page_location[current_map][i][1], page_location[current_map][i][2], page_location[current_map][i][3]
  84.         if(getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) < 3) and (pages_done[i] ~= true) then
  85.             collect_page(i)
  86.             break;
  87.         end
  88.     end
  89. end
  90.  
  91. local function triggerResourceStart(theMap)
  92.     if(theMap == "forest") then
  93.         sound["grillen"] = playSound3D("data/sounds/grillen2.mp3", -742.23272705078, -2068.0236816406, 20.0146446228027, true)
  94.         setSoundMaxDistance(sound["grillen"], 500)
  95.     elseif(theMap == "city") then
  96.    
  97.     elseif(theMap == "industry") then
  98.    
  99.     end
  100.     setTimer(function()
  101.         triggerEvent("doSlenderClientSendMessage", localPlayer, "Press 'Fire' to turn the Flashlight on/off,", 4000)
  102.         setTimer(function()
  103.             triggerEvent("doSlenderClientSendMessage", localPlayer, "Press 'E' to pick up pages.")
  104.         end, 4000, 1)
  105.     end, 4000, 1)
  106.    
  107.     -- SPRINT --
  108.     setGameSpeed(0.<!-- s8) --><img src=\"{SMILIES_PATH}/icon_cool.gif\" alt=\"8)\" title=\"Cool\" /><!-- s8) -->
  109.     bindKey("sprint", "both", function(key, state)
  110.         if(state == "down") then
  111.             if(cantsprint == true) then
  112.                 setGameSpeed(1.2)
  113.                 sprinttimer = setTimer(function()
  114.                     local gs = getGameSpeed()
  115.                     gs = gs-0.05
  116.                     if(gs > 0.9) then
  117.                         setGameSpeed(gs)
  118.                     else
  119.                         if(cantsprint == true) then
  120.                             cantsprint = false
  121.                             setTimer(function()
  122.                                 cantsprint = true
  123.                             end, 10000, 1)
  124.                             setSoundVolume(playSound("data/sounds/breathing.mp3", false), 0.<!-- s8) --><img src=\"{SMILIES_PATH}/icon_cool.gif\" alt=\"8)\" title=\"Cool\" /><!-- s8) -->
  125.                         end
  126.                     end
  127.                 end, 1000, -1)
  128.             end
  129.         else
  130.             if(isTimer(sprinttimer)) then
  131.                 killTimer(sprinttimer)
  132.             end
  133.             setGameSpeed(0.<!-- s8) --><img src=\"{SMILIES_PATH}/icon_cool.gif\" alt=\"8)\" title=\"Cool\" /><!-- s8) -->
  134.         end
  135.     end)
  136.    
  137.     bindKey("e", "down", slender_page_check)
  138.     -- SOUNDS --
  139.     sound["staticlong"] = playSound("data/sounds/static_long.mp3", true)
  140.     setSoundVolume(sound["staticlong"], 0)
  141. end
  142.  
  143. local function deleteSelectionButtons()
  144.     for index, k in pairs(select_button) do
  145.         destroyElement(k)
  146.     end
  147.     atSelection = false
  148.     setTimer(function()
  149.         triggerServerEvent("doClientSpawnPlayerToServer", localPlayer, current_map)
  150.         triggerResourceStart(current_map)
  151.     end, 1000, 1)
  152.     showCursor(false)
  153. end
  154.  
  155. local function buildSelectionButtons()
  156.     --[[
  157.         dxDrawImage(sx/2-(275/1600*sx), sy/2-(200/900*sy), 501/1600*sx, 103/900*sy, "data/img/selection_forest.jpg", 0, 0, 0, tocolor(255, 255, 255, alpha_selection["forest"]))
  158.         dxDrawImage(sx/2-(275/1600*sx), sy/2-(80/900*sy), 501/1600*sx, 103/900*sy, "data/img/selection_industry.jpg", 0, 0, 0, tocolor(255, 255, 255, alpha_selection["industry"]))
  159.         -- TEXT --
  160.         local scale = 0.5/1600*sx
  161.         dxDrawText("CHOOSE A MAP", sx/2-(200/1600*sx), sy/2-(300/900*sy), sx/2, sy/2, tocolor(255, 255, 255), scale, slender_font)
  162.         scale = 0.3/1600*sx
  163.         dxDrawText("FOREST", sx/2-(270/1600*sx), sy/2-(125/900*sy), sx/2, sy/2, tocolor(255, 255, 255, alpha_selection["forest"]), scale, slender_font)
  164.         dxDrawText("INDUSTRY", sx/2-(270/1600*sx), sy/2-(5/900*sy), sx/2, sy/2, tocolor(255, 255, 255, alpha_selection["forest"]), scale, slender_font)
  165.     ]]
  166.     local sx, sy = guiGetScreenSize()
  167.     select_button["forest"] = guiCreateButton(sx/2-(275/1600*sx), sy/2-(200/900*sy), 501/1600*sx, 103/900*sy, "", false)
  168.     select_button["industry"] = guiCreateButton(sx/2-(275/1600*sx), sy/2-(80/900*sy), 501/1600*sx, 103/900*sy, "", false)
  169.     guiSetAlpha(select_button["forest"], 0)
  170.     guiSetAlpha(select_button["industry"], 0)
  171.     addEventHandler("onClientMouseEnter", select_button["forest"], function()
  172.         alpha_selection["forest"] = 255
  173.         playSoundFrontEnd(41)
  174.     end)
  175.     addEventHandler("onClientMouseLeave", select_button["forest"], function()
  176.         alpha_selection["forest"] = 200
  177.     end)
  178.    
  179.     addEventHandler("onClientGUIClick", select_button["forest"], function()
  180.         deleteSelectionButtons()
  181.         current_map = "forest"
  182.     end, false)
  183.    
  184.     addEventHandler("onClientMouseEnter", select_button["industry"], function()
  185.         alpha_selection["industry"] = 255
  186.         playSoundFrontEnd(41)
  187.     end)
  188.     addEventHandler("onClientMouseLeave", select_button["industry"], function()
  189.         alpha_selection["industry"] = 200
  190.     end)
  191.    
  192.     addEventHandler("onClientGUIClick", select_button["industry"], function()
  193.         deleteSelectionButtons()
  194.         current_map = "industry"
  195.     end, false)
  196. end
  197.  
  198. addEventHandler("onClientResourceStart", getResourceRootElement(), function()
  199.     for i = 1, 30, 1 do
  200.         outputChatBox(" ")
  201.     end
  202.     showPlayerHudComponent("all", false)
  203. --  triggerServerEvent("doClientSpawnPlayerToServer", getLocalPlayer())
  204.     -- SELECTION --
  205.    
  206.     addEventHandler("onClientPlayerDamage", localPlayer, cancelEvent)
  207.    
  208.     atSelection = true
  209.     buildSelectionButtons()
  210.     showCursor(true)
  211.    
  212.     fadeCamera(true)
  213.     setCameraMatrix(2226.3798828125, -2209.3366699219, 14.26592540741, 2293.7722167969, -2135.7702636719, 21.066173553467)
  214. end)
  215.  
  216. function try_slender_again()
  217. --  triggerServerEvent("doClientSpawnPlayerToServer", getLocalPlayer(), current_map)
  218.     atSelection = true
  219.     buildSelectionButtons()
  220.     showCursor(true)
  221.     fadeCamera(true)
  222.     setCameraMatrix(2226.3798828125, -2209.3366699219, 14.26592540741, 2293.7722167969, -2135.7702636719, 21.066173553467)
  223.     unbindKey("enter", "down", try_slender_again)
  224.     wasted = false
  225.     slendyshock = false
  226.     s_en = false
  227.     fertig = false
  228.     pages = 0
  229.     last_ai = 1
  230.     fade = 0
  231.     for i = 1, 8, 1 do
  232.         pages_done[i] = false
  233.     end
  234.     if(isTimer(ai_data["timer"])) then
  235.         killTimer(ai_data["timer"])
  236.     end
  237. end
  238.  
  239. local function slender_player_wasted()
  240.     if(isElement(sound["page1"])) then
  241.         destroyElement(sound["page1"])
  242.     end
  243.     if(isElement(sound["page3"])) then
  244.         destroyElement(sound["page3"])
  245.     end
  246.     if(isElement(sound["page6"])) then
  247.         destroyElement(sound["page6"])
  248.     end
  249.     playSound("data/sounds/bum.mp3", false)
  250.     wasted = true
  251.     setTimer(function()
  252.         s_en = true
  253.         setSoundVolume(sound["staticlong"], 1.0)
  254.         setTimer(function()
  255.             s_en = false
  256.             setSoundVolume(sound["staticlong"], 0.0)
  257.             setTimer(function()
  258.                 s_en = true
  259.                 setSoundVolume(sound["staticlong"], 1.0)
  260.                 setTimer(function()
  261.                     s_en = false
  262.                     setSoundVolume(sound["staticlong"], 0.0)
  263.                     setTimer(function()
  264.                         s_en = true
  265.                         setSoundVolume(sound["staticlong"], 1.0)
  266.                         setTimer(function()
  267.                             s_en = false
  268.                             setSoundVolume(sound["staticlong"], 0.0)
  269.                             setTimer(function()
  270.                                 triggerEvent("doSlenderClientSendMessage", localPlayer, "Press enter to try again.")
  271.                                 bindKey("enter", "down", try_slender_again)
  272.                             end, 1000, 1)
  273.                         end, 500, 1)
  274.                     end, 150, 1)
  275.                 end, 250, 1)
  276.             end, 200, 1)
  277.         end, 50, 1)
  278.     end, 100, 1)
  279.     destroyElement(slendy)
  280.     page = 0
  281.     for i = 1, 8, 1 do
  282.         pages_done[i] = false
  283.     end
  284.     if(isTimer(ai_data["timer"])) then
  285.         killTimer(ai_data["timer"])
  286.     end
  287.    
  288. end
  289.  
  290. -- addCommandHandler("die", slender_player_wasted)
  291. -- CLIENT RENDER --
  292.  
  293.  
  294. local function slender_render()
  295.     if(atSelection == false) then
  296.         local sx, sy = guiGetScreenSize()
  297.         local scale
  298.         -- PAGES --
  299.         for i = 1, 8, 1 do
  300.             if(pages_done[i] == false) then
  301.                 dxDrawMaterialLine3D(page_location[current_map][i][1], page_location[current_map][i][2], page_location[current_map][i][3]+0.5, page_location[current_map][i][1], page_location[current_map][i][2], page_location[current_map][i][3]-0.5, page_mat[i], 0.9, tocolor(255,255,255,255), page_facel[current_map][i][1],page_facel[current_map][i][2], page_facel[current_map][i][3])
  302.             end
  303.         end
  304.         -- SLENDER --
  305.         if(isElement(slendy)) then
  306.             -- ROT --
  307.             local x3, y3, z3 = getElementPosition(slendy)
  308.             local x4, y4, z4 = getElementPosition(localPlayer)
  309.             local rot = math.atan2(y4 - y3, x4 - x3) * 180 / math.pi
  310.             rot = rot-90
  311.             setPedRotation(slendy, rot)
  312.             -- BUM CHECK --
  313.             local x, y, z = getElementPosition(localPlayer)
  314.             local x2, y2, z2 = getElementPosition(slendy)
  315.             if(isElementOnScreen(slendy)) and (isLineOfSightClear(x, y, z, x2, y2, z2, true, true, false, true)) and (getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) < 5) then
  316.                 if(slendyshock == false) then
  317.                     slendyshock = true
  318.                     playSound("data/sounds/bum.mp3", false)
  319.                 end
  320.             else
  321.                 slendyshock = false
  322.             end
  323.             -- FADE --
  324.             local distance = getDistanceBetweenPoints3D(x3, y3, z3, x4, y4, z4)
  325.             if(taschenlampstate == true) then
  326.                 distance = 0
  327.             end
  328.             if(isElementOnScreen(slendy)) and (isLineOfSightClear(x, y, z, x2, y2, z2, true, true, false, true)) and (distance < 10) then
  329.                 fade = fade+1
  330.                 dxDrawImage(0, 0, sx, sy, "data/img/slender.png", 0, 0, 0, tocolor(255, 255, 255, fade))
  331.                 dxDrawImage(0, 0, sx, sy, "data/img/static.png", 0, 0, 0, tocolor(255, 255, 255, fade))
  332.                 setSoundVolume(sound["staticlong"], fade/2.55/100)
  333.                 if(fade > 200) then
  334.                     if(page ~= <!-- s8) --><img src=\"{SMILIES_PATH}/icon_cool.gif\" alt=\"8)\" title=\"Cool\" /><!-- s8) --> then
  335.                         if(wasted == false) then
  336.                             slender_player_wasted()
  337.                         end
  338.                     end
  339.                 end
  340.             else
  341.                 if(fade > 0) then
  342.                     fade = fade-0.5
  343.                     dxDrawImage(0, 0, sx, sy, "data/img/slender.png", 0, 0, 0, tocolor(255, 255, 255, fade))
  344.                     dxDrawImage(0, 0, sx, sy, "data/img/static.png", 0, 0, 0, tocolor(255, 255, 255, fade))
  345.                     setSoundVolume(sound["staticlong"], fade/2.55/100)
  346.                 end
  347.             end
  348.         end
  349.         if(wasted == true) then
  350.             dxDrawRectangle(0, 0, sx, sy, tocolor(0, 0, 0, 255))
  351.             if(s_en == true) then
  352.                 dxDrawImage(0, 0, sx, sy, "data/img/static.png", 0, 0, 0, tocolor(255, 255, 255, 255))
  353.                 dxDrawImage(0, 0, sx, sy, "data/img/slender.png", 0, 0, 0, tocolor(255, 255, 255, 200))
  354.             end
  355.         end
  356.         if(textd["status"] == true) then
  357.             scale = 3/1920*sx
  358.             dxDrawText(textd["text"], sx/2, sy/2-(200/1080*sy), sx/2, sy/2-(500/1080*sy), tocolor(255, 255, 255, 200), scale, "default-bold", "center")
  359.         end
  360.     else
  361.         -- SELECTION DRAW --
  362.         -- IMAGES --
  363.         local sx, sy = guiGetScreenSize()
  364.         dxDrawImage(sx/2-(275/1600*sx), sy/2-(200/900*sy), 501/1600*sx, 103/900*sy, "data/img/selection_forest.jpg", 0, 0, 0, tocolor(255, 255, 255, alpha_selection["forest"]))
  365.         dxDrawImage(sx/2-(275/1600*sx), sy/2-(80/900*sy), 501/1600*sx, 103/900*sy, "data/img/selection_industry.jpg", 0, 0, 0, tocolor(255, 255, 255, alpha_selection["industry"]))
  366.         -- TEXT --
  367.         local scale = 0.5/1600*sx
  368.         dxDrawText("CHOOSE A MAP", sx/2-(200/1600*sx), sy/2-(300/900*sy), sx/2, sy/2, tocolor(255, 255, 255), scale, slender_font)
  369.         scale = 0.3/1600*sx
  370.         dxDrawText("FOREST", sx/2-(270/1600*sx), sy/2-(125/900*sy), sx/2, sy/2, tocolor(255, 255, 255, alpha_selection["forest"]), scale, slender_font)
  371.         dxDrawText("INDUSTRY", sx/2-(270/1600*sx), sy/2-(5/900*sy), sx/2, sy/2, tocolor(255, 255, 255, alpha_selection["forest"]), scale, slender_font)
  372.     end
  373. end
  374.  
  375. addEventHandler("onClientPreRender", getRootElement(), slender_render)
  376.  
  377. -- SLENDER MSG --
  378.  
  379. addEventHandler("doSlenderClientSendMessage", getLocalPlayer(), function(text, time)
  380.     if(isTimer(textd["timer"])) then
  381.         killTimer(textd["timer"])
  382.     end
  383.     if not(time) then time = 5000 end
  384.     textd["text"] = text
  385.     textd["status"] = true
  386.  
  387.     textd["timer"] = setTimer(function()
  388.         textd["status"] = false
  389.         textd["text"] = ""
  390.     end, time, 1)
  391. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement