lopezloo

Class Selection PL 1b: client.lua

Mar 18th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.33 KB | None | 0 0
  1. x, y = guiGetScreenSize()
  2. skinsTable = { }
  3.  
  4. function onClientResourceStart(startedResource)
  5.     if startedResource == getThisResource() then
  6.         triggerServerEvent("getSettings", root)
  7.         setElementData(localPlayer, "alive", false)
  8.     end
  9. end
  10. addEventHandler("onClientResourceStart", root, onClientResourceStart)
  11.  
  12. function sendSettings(freeCam, camPosX, camPosY, camPosZ, camLookX, camLookY, camLookZ, pedPosX, pedPosY, pedPosZ, pedRot, interior, allSkins, skinID, skins)
  13.     setElementData(localPlayer, "class_freeCam", freeCam)
  14.  
  15.     setElementData(localPlayer, "class_camPosX", camPosX)
  16.     setElementData(localPlayer, "class_camPosY", camPosY)
  17.     setElementData(localPlayer, "class_camPosZ", camPosZ)
  18.    
  19.     setElementData(localPlayer, "class_camLookX", camLookX)
  20.     setElementData(localPlayer, "class_camLookY", camLookY)
  21.     setElementData(localPlayer, "class_camLookZ", camLookZ)
  22.    
  23.     setElementData(localPlayer, "class_pedPosX", pedPosX)
  24.     setElementData(localPlayer, "class_pedPosY", pedPosY)
  25.     setElementData(localPlayer, "class_pedPosZ", pedPosZ)
  26.    
  27.     setElementData(localPlayer, "class_pedRot", pedRot)
  28.     setElementData(localPlayer, "class_interior", interior)
  29.    
  30.     setElementData(localPlayer, "class_allSkins", allSkins)
  31.     setElementData(localPlayer, "class_skinID", skinID)
  32.     setElementData(localPlayer, "class_skins", skins)
  33.     skinsTable = skins
  34.    
  35.     setElementModel(localPlayer, skinsTable[1])
  36.     setElementData(localPlayer, "skinTableID", 1)  
  37.     setupPlayerForClassSelection()
  38. end
  39. addEvent("sendSettings", true)
  40. addEventHandler("sendSettings", root, sendSettings, freeCam, camPosX, camPosY, camPosZ, camLookX, camLookY, camLookZ, pedPosX, pedPosY, pedPosZ, pedRot, interior, allSkins, skinID, skins)
  41.  
  42. function renderSkinID()
  43.     dxDrawText(getElementModel(localPlayer), x - 898, y - 213, x - 769, y - 144, tocolor(255, 255, 255, 255), 2.0, "bankgothic", "center", "center", false, false, false)  
  44. end
  45.  
  46. function bindSetupPlayerForClassSelection()
  47.     if isPedInVehicle(localPlayer) then
  48.         outputChatBox("Nie możesz przejść do wybierałki, ponieważ jesteś w pojeździe!", 255, 102, 102)
  49.         return false
  50.     end
  51.     if getElementData(localPlayer, "alive") == false then
  52.         outputChatBox("Nie możesz przejść do wybierałki, ponieważ jesteś martwy!", 255, 102, 102)
  53.         return false
  54.     end
  55.    
  56.     unbindKey("F4")
  57.     outputChatBox("Przejście do wybierałki nastąpi za 5 sekund..", 0, 204, 51)
  58.     setTimer(timer_SetupPlayerForClassSelection, 5000, 1)
  59. end
  60.  
  61. function timer_SetupPlayerForClassSelection()
  62.     if isPedInVehicle(localPlayer) then
  63.         outputChatBox("Nie możesz przejść do wybierałki gdy jesteś w pojeździe!")
  64.         bindKey("F4", "down", bindSetupPlayerForClassSelection)
  65.         return false
  66.     end
  67.     if getElementData(localPlayer, "alive") == false then
  68.         bindKey("F4", "down", bindSetupPlayerForClassSelection)
  69.         return false
  70.     end
  71.    
  72.     setupPlayerForClassSelection()
  73. end
  74.  
  75. function setupPlayerForClassSelection()
  76.     if getElementData(localPlayer, "class_skinID") == 1 then
  77.         addEventHandler("onClientRender", root, renderSkinID)
  78.     end
  79.  
  80.     toggleAllControls(false, true, false)
  81.     setPedAnimation(localPlayer)
  82.    
  83.     setElementData(localPlayer, "classSelection", true)
  84.     showPlayerHudComponent("radar", false)
  85.    
  86.     currentSkinID = table.find(skinsTable, getElementModel(localPlayer))
  87.     if currentSkinID == nil then currentSkinID = 1 end
  88.     setElementModel(localPlayer, skinsTable[currentSkinID])
  89.     setElementData(localPlayer, "skinTableID", currentSkinID)
  90.  
  91.     setElementInterior(localPlayer, getElementData(localPlayer, "class_interior"))
  92.     setElementDimension(localPlayer, getElementID(localPlayer))
  93.     if getElementData(localPlayer, "class_freeCam") == 0 then
  94.         setCameraMatrix(getElementData(localPlayer, "class_camPosX"), getElementData(localPlayer, "class_camPosY"), getElementData(localPlayer, "class_camPosZ"), getElementData(localPlayer, "class_camLookX"), getElementData(localPlayer, "class_camLookY"), getElementData(localPlayer, "class_camLookZ"))
  95.     end
  96.     setElementPosition(localPlayer, getElementData(localPlayer, "class_pedPosX"), getElementData(localPlayer, "class_pedPosY"), getElementData(localPlayer, "class_pedPosZ"))
  97.     setPedRotation(localPlayer, getElementData(localPlayer, "class_pedRot"))
  98.  
  99.     unbindKey("F4")
  100.     bindKey("lshift", "down", stopPlayerClassSelection)
  101.     bindKey("rshift", "down", stopPlayerClassSelection)
  102.  
  103.     bindKey("arrow_l", "down", classSelectionChangeSkin, "left")
  104.     bindKey("arrow_r", "down", classSelectionChangeSkin, "right")
  105.    
  106.     bindKey("mouse1", "down", classSelectionChangeSkin, "right")
  107.     bindKey("mouse2", "down", classSelectionChangeSkin, "left")
  108.    
  109.     triggerEvent("onEnterClassSelection", root)
  110. end
  111.  
  112. function classSelectionChangeSkin(key, state, direction)
  113.     local oldSkin = getElementModel(localPlayer)
  114.     if direction == "right" then
  115.         tableID = getElementData(localPlayer, "skinTableID") + 1
  116.         if tableID == table.getn(skinsTable) + 1 then tableID = 1 end  
  117.     else
  118.         tableID = getElementData(localPlayer, "skinTableID") - 1
  119.         if tableID == 0 then tableID = table.getn(skinsTable) end  
  120.     end
  121.    
  122.     setElementData(localPlayer, "skinTableID", tableID)
  123.     setElementModel(localPlayer, skinsTable[tableID])
  124.     playSoundFrontEnd(2)
  125.     triggerEvent("onClassSelectionSkinChange", root, oldSkin, skinsTable[tableID]) 
  126. end
  127.  
  128. function stopPlayerClassSelection()
  129.     if getElementData(localPlayer, "class_skinID") == 1 then
  130.         removeEventHandler("onClientRender", root, renderSkinID)
  131.     end
  132.  
  133.     setElementData(localPlayer, "classSelection", false)
  134.     unbindKey("lshift")
  135.     unbindKey("rshift")
  136.     unbindKey("arrow_l")
  137.     unbindKey("arrow_r")
  138.     unbindKey("mouse1")
  139.     unbindKey("mouse2")
  140.  
  141.     bindKey("F4", "down", bindSetupPlayerForClassSelection)
  142.     toggleAllControls(true)
  143.     showPlayerHudComponent("radar", true)
  144.     setElementDimension(localPlayer, 0)
  145.     triggerServerEvent("stopPlayerClassSelection", root, getElementModel(localPlayer))
  146.     triggerEvent("onLeaveClassSelection", root)
  147. end
  148.  
  149. function onClientPlayerSpawn()
  150.     setElementData(localPlayer, "alive", true)
  151. end
  152. addEventHandler("onClientPlayerSpawn", localPlayer, onClientPlayerSpawn)
  153.  
  154. function onClientPlayerWasted()
  155.     setElementData(localPlayer, "alive", false)
  156. end
  157. addEventHandler("onClientPlayerWasted", localPlayer, onClientPlayerWasted)
  158.  
  159. function isPlayerInClassSelection()
  160.     return getElementData(localPlayer, "classSelection")
  161. end
  162.  
  163. function table.find(t, v)
  164.     for i, l in ipairs(t) do
  165.         if l == v then
  166.             return i
  167.         end
  168.     end
  169.     return nil
  170. end
Advertisement
Add Comment
Please, Sign In to add comment