shadowndacorner

char create so far

Feb 3rd, 2012
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.41 KB | None | 0 0
  1. charCreate={}
  2. charCreate.Functions={}
  3. charCreate.Vars={}
  4. charCreate.Hooks={}
  5. charCreate.Opened=false
  6. charCreate.Vars.Angles=Angle(0, 0, 0)
  7. charCreate.Vars.ReadingX=false
  8. charCreate.Vars.ReadingY=false
  9. charCreate.Vars.ReadingZ=false
  10. charCreate.Vars.Zoom=1
  11. charCreate.Vars.CurX=0
  12. charCreate.Vars.CurY=0
  13. local classes={
  14. ["Mage"]=   {
  15.     ["Advanced"]={
  16.                 ["Templar"]="Specialty: Healing/Support\nTotal Health: Low\nAttacks: Low power, low cooldown",
  17.                 ["Sorceror"]="Specialty: Damage over Time\nTotal Health: Medium\nAttacks: Medium power, low cooldown",
  18.                 ["Warlock"]="Specialty: High Power\nTotal Health: High\nAttacks: High Power, low cooldown"
  19.                 }
  20.             },
  21. ["Swordsman"]=  {
  22.     ["Advanced"]={
  23.                 ["Cutthroat"]="Specialty: Speed\nTotal Health: Medium\nAttacks: Fast, medium power",
  24.                 ["Knight"]="Specialty: High Power\nTotal Health: Very high\nAttacks: Slow, high power"
  25.                 }
  26.             }
  27. }
  28.  
  29. function OpenCharacterCreation()
  30.     charCreate.Opened=true
  31.     local CreateChar
  32.     local AdvancedType
  33.     local CharDescription
  34.     local DLabel4
  35.     local DLabel3
  36.     local DLabel2
  37.     local CharName
  38.     local BaseType
  39.     local ModelSelectR
  40.     local ModelSelectName
  41.     local ModelSelectL
  42.     local DFrame1
  43.     local selectedClass
  44.  
  45.     DFrame1 = vgui.Create('DFrame')
  46.     DFrame1:SetSize(230, 480)
  47.     DFrame1:SetPos(10, 10)
  48.     DFrame1:SetTitle('Character Creation')
  49.     DFrame1:SetSizable(false)
  50.     DFrame1:SetDraggable(false)
  51.     DFrame1:SetDeleteOnClose(false)
  52.     --DFrame1:ShowCloseButton(false)
  53.     DFrame1:MakePopup()
  54.  
  55.     ModelSelectL = vgui.Create('DButton')
  56.     ModelSelectL:SetParent(DFrame1)
  57.     ModelSelectL:SetSize(20, 20)
  58.     ModelSelectL:SetPos(20, 110)
  59.     ModelSelectL:SetText('<')
  60.     ModelSelectL.DoClick = function() end
  61.  
  62.     ModelSelectName = vgui.Create('DLabel')
  63.     ModelSelectName:SetParent(DFrame1)
  64.     ModelSelectName:SetPos(60, 110)
  65.     ModelSelectName:SetText("Model Selection Here")
  66.     ModelSelectName:SizeToContents()
  67.  
  68.     ModelSelectR = vgui.Create('DButton')
  69.     ModelSelectR:SetParent(DFrame1)
  70.     ModelSelectR:SetSize(20, 20)
  71.     ModelSelectR:SetPos(190, 110)
  72.     ModelSelectR:SetText('>')
  73.     ModelSelectR.DoClick = function() end
  74.  
  75.  
  76.     CharName = vgui.Create('DTextEntry')
  77.     CharName:SetParent(DFrame1)
  78.     CharName:SetSize(190, 20)
  79.     CharName:SetPos(20, 70)
  80.     CharName:SetText('')
  81.     CharName.OnEnter = function() end
  82.  
  83.     DLabel2 = vgui.Create('DLabel')
  84.     DLabel2:SetParent(DFrame1)
  85.     DLabel2:SetPos(30, 160)
  86.     DLabel2:SetText('Base Class')
  87.     DLabel2:SizeToContents()
  88.  
  89.     DLabel3 = vgui.Create('DLabel')
  90.     DLabel3:SetParent(DFrame1)
  91.     DLabel3:SetPos(30, 50)
  92.     DLabel3:SetText('Character Name')
  93.     DLabel3:SizeToContents()
  94.  
  95.     DLabel4 = vgui.Create('DLabel')
  96.     DLabel4:SetParent(DFrame1)
  97.     DLabel4:SetPos(30, 220)
  98.     DLabel4:SetText('Advanced Class')
  99.     DLabel4:SizeToContents()
  100.  
  101.     CharDescription = vgui.Create('DLabel')
  102.     CharDescription:SetParent(DFrame1)
  103.     CharDescription:SetPos(30, 350)
  104.     CharDescription:SetText("Select a class to see it's\nfull description")
  105.     CharDescription:SizeToContents()
  106.  
  107.     AdvancedType = vgui.Create('DComboBox')
  108.     AdvancedType:SetParent(DFrame1)
  109.     AdvancedType:SetMultiple(false)
  110.     AdvancedType:SetSize(190, 100)
  111.     AdvancedType:SetPos(20, 240)
  112.     AdvancedType:EnableHorizontal(false)
  113.     AdvancedType:EnableVerticalScrollbar(true)
  114.     function AdvancedType:OnMousePressed()
  115.         if AdvancedType:GetSelectedItems() and AdvancedType:GetSelectedItems()[1] and selectedClass then
  116.             --PrintTable(AdvancedType:GetSelectedItems())
  117.             CharDescription:SetText(classes[selectedClass].Advanced[AdvancedType:GetSelectedItems()[1]:GetValue()])
  118.             CharDescription:SizeToContents()
  119.         end
  120.     end
  121.     AdvancedType:SetMultiple(false)
  122.    
  123.     BaseType = vgui.Create('DMultiChoice')
  124.     BaseType:SetParent(DFrame1)
  125.     BaseType:SetPos(20, 180)
  126.     BaseType:SetSize(190, 20)
  127.     BaseType.OnMousePressed = function()
  128.         BaseType:OpenMenu()
  129.     end
  130.    
  131.     BaseType:SetEditable(false)
  132.     function BaseType:OnSelect(index, value, data)
  133.         AdvancedType:Clear()
  134.         for f, v in pairs(classes[value].Advanced) do
  135.             AdvancedType:AddItem(f)
  136.         end
  137.         AdvancedType:SetSelected(1)
  138.         selectedClass=value
  139.     end
  140.  
  141.     BaseType:AddChoice('Mage')
  142.     BaseType:AddChoice('Swordsman')
  143.  
  144.     CreateChar = vgui.Create('DButton')
  145.     CreateChar:SetParent(DFrame1)
  146.     CreateChar:SetSize(140, 30)
  147.     CreateChar:SetPos(40, 430)
  148.     CreateChar:SetText('Create Character')
  149.     CreateChar.DoClick = function() end
  150. end
  151. concommand.Add("showCharacterCreation", OpenCharacterCreation)
  152.  
  153. local oldMouseX=nil
  154. local oldMouseY=nil
  155. function charCreate.Hooks.Think()
  156.     if charCreate.Opened and !MWCursorEnabled then
  157.         gui.EnableScreenClicker(true)
  158.         MWCursorEnabled=true
  159.     end
  160.     if charCreate.Vars.ReadingX then
  161.         charCreate.Vars.CurX=charCreate.Vars.CurX+(gui.MouseX()-oldMouseX)
  162.         oldMouseX=gui.MouseX()
  163.     elseif charCreate.Vars.ReadingY then
  164.         charCreate.Vars.CurY=math.Clamp(charCreate.Vars.CurY+(gui.MouseY()-oldMouseY), -60, 60)
  165.         oldMouseY=gui.MouseY()
  166.     end
  167.     if charCreate.Vars.ReadingZ then
  168.         charCreate.Vars.Zoom=math.Clamp(charCreate.Vars.Zoom+((gui.MouseY()-oldMouseY)/50), 0.22, 1)
  169.         oldMouseY=gui.MouseY()
  170.     end
  171.     charCreate.Vars.Angles=Angle(charCreate.Vars.CurY, charCreate.Vars.CurX, 0)
  172. end
  173.  
  174. function charCreate.Hooks.CallScreenClickHook( click, mousecode, vec )
  175.     if click and mousecode==107 then
  176.         charCreate.Vars.ReadingX=true
  177.         oldMouseX=gui.MouseX()
  178.         --print("Clicked left")
  179.         --print(tostring(charCreate.Vars.ReadingX))
  180.     elseif !click and mousecode==107 then
  181.         charCreate.Vars.ReadingX=false
  182.         oldMouseX=nil
  183.         --print("Unclicked left")
  184. --      print(tostring(charCreate.Vars.ReadingX))
  185.     end
  186.     if click and mousecode==108 then
  187.         charCreate.Vars.ReadingY=true
  188.         oldMouseY=gui.MouseY()
  189.         --print("Clicked left")
  190.         --print(tostring(charCreate.Vars.ReadingX))
  191.     elseif !click and mousecode==108 then
  192.         charCreate.Vars.ReadingY=false
  193.         oldMouseY=nil
  194.         --print("Unclicked left")
  195. --      print(tostring(charCreate.Vars.ReadingX))
  196.     end
  197. end
  198.  
  199. function charCreate.Hooks.CalcView(ply, pos, angles, fov)
  200.     local view={}
  201.     view.angles=angles+charCreate.Vars.Angles
  202.     view.origin=pos-(view.angles:Forward()*(100*charCreate.Vars.Zoom))
  203.     view.fox=fov
  204.    
  205.     return view
  206. end
  207.  
  208. function charCreate.Hooks.GUIMousePressed(mc)
  209.     if mc==MOUSE_MIDDLE then
  210.         charCreate.Vars.ReadingZ=true
  211.         oldMouseY=gui.MouseY()
  212.     end
  213. end
  214.  
  215. function charCreate.Hooks.GUIMouseReleased(mc)
  216.     if mc==MOUSE_MIDDLE then
  217.         charCreate.Vars.ReadingZ=false
  218.         oldMouseY=nil
  219.     end
  220. end
  221.  
  222. function charCreate.Hooks.CreateMove(cmd)
  223.     cmd:SetViewAngles(LocalPlayer():GetAngles())
  224. end
  225.  
  226. local bindFunctions={
  227.     ["+forward"]=function()
  228.         return true
  229.     end,
  230.     ["+moveright"]=function()
  231.         return true
  232.     end,
  233.     ["+back"]=function()
  234.         return true
  235.     end,
  236.     ["+moveleft"]=function()
  237.         return true
  238.     end,
  239.     ["+duck"]=function()
  240.         return true
  241.     end,
  242.     ["+attack"]=function()
  243.         return true
  244.     end,
  245.     ["+attack2"]=function()
  246.         return true
  247.     end,
  248.     ["messagemode"]=function()
  249.         return true
  250.     end,
  251.     ["invnext"]=function()
  252.         charCreate.Vars.Zoom=charCreate.Vars.Zoom+30
  253.         print(charCreate.Vars.Zoom)
  254. --      return true
  255.     end,
  256.     ["invprev"]=function()
  257.         charCreate.Vars.Zoom=charCreate.Vars.Zoom+30
  258.         print(charCreate.Vars.Zoom)
  259. --      return true
  260.     end
  261. }
  262.  
  263. function charCreate.Hooks.PlayerBindPress(ply, bind, active)
  264.     if bindFunctions[bind] and active and charCreate.Opened then
  265.         return bindFunctions[bind]()
  266.     end
  267. end
  268.  
  269. for f, v in pairs(charCreate.Hooks) do
  270.     hook.Add(f, "char_create_hook", function(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
  271.         if charCreate.Opened then
  272.             return v(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
  273.         end
  274.     end)
  275. end
Advertisement
Add Comment
Please, Sign In to add comment