SHCREW

gcreator

Feb 27th, 2022 (edited)
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. Write-Host "GCreator - Automatic addon creation
  2. "
  3.  
  4. # Asking for details
  5. $DevName = Read-Host -Prompt "Enter the (lowercase, one word) name of your addon (Default: 'addon_name')"
  6. $TableName = Read-Host -Prompt "Enter the name of the global table that will be created (Default: 'AddonName')"
  7. Write-Host ""
  8. Clear-Host
  9.  
  10. Write-Host "GCreator - Automatic addon creation
  11.  
  12. Processing"
  13.  
  14. # Set default values
  15. if ($DevName -eq "") { $DevName = "addon_name" }
  16. if ($TableName -eq "") { $TableName = "AddonName" }
  17.  
  18. # $DevName = "wminimap"
  19. # $TableName = "WMinimap"
  20. $LuaRoot = "$DevName/lua/$DevName/"
  21.  
  22. # First step: Create folders
  23. New-Item -Name "$DevName/lua/autorun" -ItemType "directory" -Force > $NULL
  24. New-Item -Name "${LuaRoot}server" -ItemType "directory" -Force > $NULL
  25. New-Item -Name "${LuaRoot}client" -ItemType "directory" -Force > $NULL
  26. Write-Host "Processing."
  27.  
  28. # Second step: Create files
  29. ## autorun.lua
  30. New-Item -Path "./$DevName/lua/autorun/" -Name "${DevName}_load.lua" -ItemType "file" -Value "-- Loader file for '$DevName'
  31. $TableName = {}
  32.  
  33. -- Make loading functions
  34. local function Inclu(f) return include(`"${DevName}/f`") end
  35. local function AddCS(f) return AddCSLuaFile(`"${DevName}/f`") end
  36. local function IncAdd(f) return Inc(f), Add(f) end
  37.  
  38. -- Load addon files
  39. IncAdd(`"config.lua`")
  40. IncAdd(`"constants.lua`")
  41.  
  42. if SERVER then
  43.  
  44. Inclu(`"server/sv_functions.lua`")
  45. Inclu(`"server/sv_hooks.lua`")
  46. Inclu(`"server/sv_network.lua`")
  47.  
  48. AddCS(`"client/cl_functions.lua`")
  49. AddCS(`"client/cl_hooks.lua`")
  50. AddCS(`"client/cl_network.lua`")
  51.  
  52. else
  53.  
  54. Inclu(`"client/cl_functions.lua`")
  55. Inclu(`"client/cl_hooks.lua`")
  56. Inclu(`"client/cl_network.lua`")
  57.  
  58. end
  59. " -Force > $NULL
  60.  
  61. ## config.lua
  62. New-Item -Path "./${LuaRoot}" -Name "config.lua" -ItemType "file" -Value "$TableName.Config = {}
  63.  
  64. -- This is a configuration description
  65. $TableName.Config.AdminRanks = {
  66. [`"superadmin`"] = true,
  67. [`"admin`"] = true
  68. }" -Force > $NULL
  69.  
  70. ## constants.lua
  71. New-Item -Path "./${LuaRoot}" -Name "constants.lua" -ItemType "file" -Value "$TableName.Constants = {}
  72.  
  73. -- Colors constants
  74. $TableName.Constants[`"colors`"] = {
  75. [`"background`"] = Color(28, 31, 39),
  76. [`"hover`"] = Color(40, 45, 58)
  77. }
  78.  
  79. -- Materials constants
  80. $TableName.Constants[`"materials`"] = {
  81. [`"logo`"] = Material(`"../html/loading.png`"),
  82. }" -Force > $NULL
  83.  
  84. ## cl_functions.lua
  85. New-Item -Path "./${LuaRoot}client/" -Name "cl_functions.lua" -ItemType "file" -Value "$TableName.Fonts = {}
  86.  
  87. -- Automatic responsive functions
  88. RX = RX or function(x) return x / 1920 * ScrW() end
  89. RY = RY or function(y) return y / 1080 * ScrH() end
  90.  
  91. -- Automatic font-creation function
  92. function ${TableName}:Font(iSize, iWidth)
  93.  
  94. iSize = iSize or 15
  95. iWidth = iWidth or 500
  96.  
  97. local sName = (`"${TableName}:Font:%i:%i`"):format(iSize, iWidth)
  98. if not $TableName.Fonts[sName] then
  99.  
  100. surface.CreateFont(sName, {
  101. font = `"Arial`",
  102. size = iSize,
  103. width = iWidth,
  104. extended = false
  105. })
  106.  
  107. $TableName.Fonts[sName] = true
  108.  
  109. end
  110.  
  111. return sName
  112.  
  113. end" -Force > $NULL
  114.  
  115. ## cl_hooks.lua
  116. New-Item -Path "./${LuaRoot}client/" -Name "cl_hooks.lua" -ItemType "file" -Value "-- Called when the client is fully connected
  117. hook.Add(`"HUDPaint`", `"${TableName}:HUDPaint`", function()
  118.  
  119. print(`"[${TableName}] The client can now see the screen!`")
  120. hook.Remove(`"${TableName}:HUDPaint`")
  121.  
  122. end)" -Force > $NULL
  123.  
  124. ## cl_network.lua
  125. New-Item -Path "./${LuaRoot}client/" -Name "cl_network.lua" -ItemType "file" -Value "-- Called when the server ask for an update
  126. net.Receive(`"${TableName}`:UpdateCache`", function()
  127.  
  128. ${TableName}.Cache = net.ReadTable()
  129. print(`"[${TableName}] Client cache updated!`")
  130.  
  131. end)" -Force > $NULL
  132.  
  133. ## sv_network.lua
  134. New-Item -Path "./${LuaRoot}server/" -Name "sv_network.lua" -ItemType "file" -Value "-- Network strings registration
  135. util.AddNetworkString(`"${TableName}`:UpdateCache`")
  136.  
  137. -- Called when the client ask for a server cache update
  138. net.Receive(`"${TableName}`:UpdateCache`", function(_, pPlayer)
  139.  
  140. if not IsValid(pPlayer) then return end
  141.  
  142. local iCurTime = CurTime()
  143. if (pPlayer.i${TableName}Cooldown or 0) > iCurTime then return end
  144. pPlayer.i${TableName}Cooldown = iCurTime + 1
  145.  
  146. ${TableName}.Cache = net.ReadTable()
  147. print(`"[${TableName}] Server cache updated!`")
  148.  
  149. end)" -Force > $NULL
  150.  
  151. ## sv_functions.lua
  152. New-Item -Path "./${LuaRoot}server/" -Name "sv_functions.lua" -ItemType "file" -Value "-- Notify a player with the specified message
  153. function ${TableName}:Notify(pPlayer, sContent)
  154.  
  155. if not IsValid(pPlayer) or not pPlayer:IsPlayer() then return end
  156.  
  157. if DarkRP then
  158. return DarkRP.notify(pPlayer, 0, 7, sContent)
  159. end
  160.  
  161. return pPlayer:PrintMessage(HUD_PRINTTALK, sContent)
  162.  
  163. end" -Force > $NULL
  164.  
  165. ## sv_hooks.lua
  166. New-Item -Path "./${LuaRoot}server/" -Name "sv_hooks.lua" -ItemType "file" -Value "-- Called when the client is fully connected
  167. hook.Add(`"Initialize`", `"${TableName}:Initialize`", function()
  168. print(`"[${TableName}] The server is now initialized!`")
  169. end)" -Force > $NULL
  170.  
  171. Write-Host "Processing..
  172. Processing..."
  173. Clear-Host
  174.  
  175. Write-Host "
  176. Successfully created ! Have fun.
  177. Don't forget to follow me on https://twitch.tv/Wasied :)"
Add Comment
Please, Sign In to add comment