Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.71 KB | None | 0 0
  1. AddCSLuaFile( "cl_init.lua" )
  2. AddCSLuaFile( "shared.lua" )
  3.  
  4.  
  5. include( "shared.lua" )
  6. include( 'config.lua' )
  7.  
  8. util.AddNetworkString( "openDuelMenu" )
  9. util.AddNetworkString( "sendDuelInfo" )
  10. util.AddNetworkString( "sendRequestDuelInfo" )
  11. util.AddNetworkString( "noLongerBeingDuelCh" )
  12. util.AddNetworkString( "sendVariablesDuel" )
  13. util.AddNetworkString( "DuelSE1" )
  14. util.AddNetworkString( "DuelSE2" )
  15.  
  16. --!!!
  17. --DO NOT EDIT ANYTHING UNDER THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
  18. --!!!
  19.  
  20. local function FindPlayers( name )
  21. local matches = {}
  22. for k,v in pairs(player.GetAll()) do
  23. if (v:GetName():lower():match( name:lower() ) ) then
  24. table.insert(matches,v)
  25. end
  26. end
  27. if (table.Count( matches ) == 0 ) then
  28. print( 'Found no matches!' )
  29. return false
  30. end
  31.  
  32. if ( table.Count( matches ) > 1 ) then
  33. print( 'Found multiple matches. Specify more.' )
  34. return false
  35. end
  36.  
  37. return matches[1]
  38. end
  39.  
  40. net.Receive( "noLongerBeingDuelCh", function( length, client )
  41. for k,v in pairs(player.GetAll()) do
  42. v:SetNWBool( 'hasDuelTimeLeft', false )
  43. end
  44. end )
  45.  
  46. net.Receive( "sendDuelInfo", function( length, client )
  47. local challengedPlyDuel = net.ReadString()
  48. local challengedWepDuel = net.ReadString()
  49. local challengedWagDuel = net.ReadString()
  50. local challengedPlyData = net.ReadEntity()
  51. local dueelWeppNum = net.ReadInt( 3 )
  52.  
  53. if tonumber(challengedWagDuel) < 0 then
  54. client:Kick()
  55. end
  56.  
  57.  
  58. curChallengedPly = challengedPlyduel
  59. curChallenger = client:Nick()
  60. curWeaponUse = challengedWepDuel
  61. curWager = challengedWagDuel
  62. dueelWeppNum = duelWeppNum
  63. local challenged = challengedPlyData
  64.  
  65. if challenged == client then
  66. client:Kick()
  67. end
  68.  
  69.  
  70. for k,v in pairs(player.GetAll()) do
  71. v:ChatPrint( "[Duels] "..client:Nick().." has challenged "..challengedPlyDuel.." to a duel for $"..challengedWagDuel.." using "..challengedWepDuel.."!" )
  72. end
  73.  
  74. MenuChallengerDuel = client:Nick()
  75. MenuWeaponDuel = challengedWepDuel
  76. MenuWagerDuel = challengedWagDuel
  77. net.Start( "sendVariablesDuel" )
  78. net.WriteString( MenuChallengerDuel )
  79. net.WriteString( MenuWeaponDuel )
  80. net.WriteString( MenuWagerDuel )
  81. net.Send( challenged )
  82.  
  83. challenged:SetNWBool( "isInDuel", true )
  84.  
  85. if duelUseChatInstead == true then
  86. challenged:ChatPrint( "You were challenged! Type /acceptduel within 30 seconds to accept!" )
  87. else
  88. net.Start( "sendRequestDuelInfo" )
  89. net.Send( challenged )
  90. end
  91.  
  92. challenged:SetNWBool( "hasDuelTimeLeft", true )
  93. challenged:SetNWEntity( "curChlngr", client )
  94.  
  95.  
  96. timer.Create( "duelAcceptTimer", 30, 1, function()
  97. if duelUseChatInstead == true then
  98. if challenged:GetNWBool( "hasDuelTimeLeft" ) == true then
  99. challenged:SetNWBool( "hasDuelTimeLeft", false )
  100. challenged:ChatPrint( "[Duels] Your time to accept the challenge is up!" )
  101. end
  102. end
  103. end )
  104.  
  105. end )
  106.  
  107. function DuelStart()
  108. for k,v in pairs(player.GetAll()) do
  109. v:ChatPrint( "A duel has started between "..curChallenger.." and "..curChallengedPly.."!" )
  110. end
  111. end
  112.  
  113. hook.Add( 'PlayerShouldTakeDamage', 'noOtherDmgInDuel', function(ply, attacker)
  114. if ply:GetNWBool( "isCurDueling" ) != attacker:GetNWBool( "isCurDueling" ) then
  115. return false
  116. end
  117. end )
  118.  
  119. hook.Add( "canDropWeapon", 'NoDropInDuel2', function( ply, weapon )
  120. if ply:GetNWString( "isCurDueling" ) == true then
  121. return false
  122. end
  123. end )
  124.  
  125.  
  126. hook.Add( 'PlayerSay', 'NoHolsterInDuel', function( ply, text, isteam )
  127. text = string.lower( text )
  128. if (string.sub(text,0,11) == "/invholster") then
  129. if ply:GetNWBool( "isCurDueling" ) == true then
  130. DarkRP.notify(ply, 0, 6, "You can't holster weapons while dueling.")
  131. return false
  132. end
  133. end
  134. end )
  135.  
  136. hook.Add( 'PlayerSpawnProp', 'NoPropsInDuel', function( ply, model )
  137. if ply:GetNWBool( 'isCurDueling' ) == true then
  138. DarkRP.notify( ply, 0, 6, "You can't spawn props during a duel." )
  139. return false
  140. end
  141. end)
  142.  
  143. if !file.Exists("duelinginfo", "DATA") then
  144. file.CreateDir("duelinginfo")
  145. end
  146.  
  147. local defTable = {
  148. ["STEAM_0:0:123456789"] = {
  149. name = "Default",
  150. wins = 0
  151. }
  152. }
  153.  
  154. if !file.Exists("duelinginfo/plyduels.txt", "DATA") then
  155. file.Write("duelinginfo/plyduels.txt", util.TableToJSON(defTable,true))
  156. end
  157.  
  158.  
  159. if !file.Exists("duelinginfo/nextresetdate.txt", "DATA") then
  160. file.Write("duelinginfo/nextresetdate.txt", os.time()+86400)
  161. end
  162.  
  163. timer.Create("checkforweekthingduels", 5, 0, function()
  164. if tonumber(file.Read("duelinginfo/nextresetdate.txt")) < os.time() then
  165. print("new day XD!")
  166. file.Write("duelinginfo/nextresetdate.txt", os.time()+86400)
  167. file.Write("duelinginfo/plyduels.txt", util.TableToJSON(defTable,true))
  168. end
  169. end)
  170.  
  171.  
  172. hook.Add( 'PlayerSay', 'kaegare', function(ply, text, isteam)
  173. text = string.lower( text )
  174. if (string.sub(text,0,11) == "/acceptduel") then
  175. text = string.Explode( " ", text )
  176.  
  177. if ply:GetNWBool( "hasDuelTimeLeft" ) == true then
  178. ply:ChatPrint( "[Duels] You accepted the challenge." )
  179. ply:SetNWBool( "hasDuelTimeLeft", false )
  180.  
  181. for k,v in pairs(player.GetAll()) do
  182. v:SetNWBool( "isCurDueling", false )
  183. end
  184.  
  185. duelAvailable = false
  186. duelAvailableText = "unavailable"
  187.  
  188. local dueler1 = ply:GetNWEntity( "curChlngr" )
  189. local dueler2 = ply
  190. if dueler1:InVehicle() then
  191. dueler1:ExitVehicle()
  192. end
  193. if dueler2:InVehicle() then
  194. dueler2:ExitVehicle()
  195. end
  196.  
  197. dueler1:SetNWBool( "isCurDueling", true )
  198. dueler2:SetNWBool( "isCurDueling", true )
  199.  
  200.  
  201. dueler1:SetNWVector( "b4DuelPlace", dueler1:GetPos() )
  202. dueler2:SetNWVector( "b4DuelPlace", dueler2:GetPos() )
  203.  
  204. if !dueler1:Alive() then
  205. dueler1:Spawn()
  206. end
  207. if !dueler2:Alive() then
  208. dueler2:Spawn()
  209. end
  210.  
  211. dueler1:SetPos( dueler1ArenaLocation )
  212. dueler1:SetEyeAngles( dueler1ArenaAngle )
  213. dueler2:SetPos( dueler2ArenaLocation )
  214. dueler2:SetEyeAngles( dueler2ArenaAngle )
  215.  
  216. dueler1:StripWeapons()
  217. dueler2:StripWeapons()
  218.  
  219. dueler1:SetHealth( 500 )
  220. dueler2:SetHealth( 500 )
  221.  
  222.  
  223.  
  224. if curWeaponUse == "Fists" then
  225. dueler1:Give( "weapon_fists" )
  226. dueler2:Give( "weapon_fists" )
  227. elseif curWeaponUse == "Sword" then
  228. dueler1:Give( "m9k_damascus" )
  229. dueler2:Give( "m9k_damascus" )
  230. elseif curWeaponUse == "Lightsaber" then
  231. dueler1:Give( "weapon_lightsaber_wos_jedisaber" )
  232. dueler2:Give( "weapon_lightsaber_wos_jedisaber" )
  233. elseif curWeaponUse == "DC-15a" then
  234. dueler1:Give( "tfa_swch_dc15a" )
  235. dueler2:Give( "tfa_swch_dc15a" )
  236. elseif curWeaponUse == "Stunstick" then
  237. dueler1:Give( "stunstick" )
  238. dueler2:Give( "stunstick" )
  239. elseif curWeaponUse == "Flame Thrower" then
  240. dueler1:Give( "wrist_flame" )
  241. dueler2:Give( "wrist_flame" )
  242. elseif curWeaponUse == "DC17M-AT" then
  243. dueler1:Give( "tfa_swch_dc17m_at" )
  244. dueler2:Give( "tfa_swch_dc17m_at" )
  245. elseif curWeaponUse == "Weststar 34" then
  246. dueler1:Give( "tfa_swch_alphablaster" )
  247. dueler2:Give( "tfa_swch_alphablaster" )
  248. elseif curWeaponUse == "DC17M-BR" then
  249. dueler1:Give( "tfa_swch_dc17m_br" )
  250. dueler2:Give( "tfa_swch_dc17m_br" )
  251. elseif curWeaponUse == "Random" then --Feel free to edit the table! Gives each player a random weapon from randomWeapons.
  252. local randomWeapons = { "weapon_fists", "weapon_crowbar", "stunstick", "weapon_rebcannon", "weapon_752_dc17dual", "m9k_damascus", "m9k_machete", "tfa_swch_dc15a", "weapon_lightsaber_wos_jedisaber", "tfa_swch_dc15a"}
  253. dueler1:Give( table.Random( randomWeapons ) )
  254. dueler2:Give( table.Random( randomWeapons ) )
  255. /*PUT YOUR CUSTOM WEAPONS HERE. Here's an example:
  256. elseif curWeaponUse == "Stupid Weapon" then
  257. dueler1:Give( "weapon_imstupid" )
  258. dueler2:Give( "weapon_imstupid" )
  259. */
  260. end
  261.  
  262. dueler1:Freeze( true )
  263. dueler2:Freeze( true )
  264. teihnvn = 3
  265. timer.Create( "countdownDuel", 1, 4, function()
  266.  
  267. if teihnvn > 0 then
  268. dueler1:ChatPrint( "[Duel] "..teihnvn )
  269. dueler2:ChatPrint( "[Duel] "..teihnvn )
  270. net.Start( "DuelSE1" )
  271. net.Send( dueler1 )
  272. net.Start( "DuelSE1" )
  273. net.Send( dueler2 )
  274. teihnvn = teihnvn - 1
  275. else
  276. net.Start( "DuelSE2" )
  277. net.Send( dueler1 )
  278. net.Start( "DuelSE2" )
  279. net.Send( dueler2 )
  280. dueler1:ChatPrint( "DUEL START!" )
  281. dueler2:ChatPrint( "DUEL START!" )
  282. dueler1:Freeze( false )
  283. dueler2:Freeze( false )
  284. end
  285. end )
  286.  
  287. hook.Add( 'PlayerDeath', 'playerdeathinDuel', function( ply, wep, killer )
  288. if ply:GetNWBool( "isCurDueling" ) then
  289. local victorrr = ""
  290. local vEnt = 0
  291. for k,v in pairs(player.GetAll()) do
  292. if (ply == v) then continue end
  293. if v:GetNWBool( "isCurDueling" ) then
  294. timer.Create( "victoryTimer", 3, 1, function()
  295. v:SetPos( v:GetNWVector( "b4DuelPlace" ) )
  296. v:addMoney( curWager )
  297. v:KillSilent()
  298. duelAvailable = true
  299. duelAvailableText = "available" end )
  300. victorrr = v:Nick()
  301. vEnt = v
  302. end
  303. v:ChatPrint( "[Duels] "..ply:Nick().." was just defeated in a duel!" )
  304. v:SetNWBool( "isCurDueling", false )
  305. end
  306. ply:ChatPrint( "[Duels] "..ply:Nick().." was just defeated in a duel!" )
  307. ply:SetPos( ply:GetNWVector( "b4DuelPlace" ) )
  308. ply:addMoney( -curWager )
  309. if ply:getDarkRPVar( "money" ) < 0 then
  310. ply:setSelfDarkRPVar( "money", 0 )
  311. end
  312. dueler1:SetNWBool( "isCurDueling", false )
  313. dueler2:SetNWBool( "isCurDueling", false )
  314. // saving json
  315. local duelNow = util.JSONToTable(file.Read("duelinginfo/plyduels.txt"))
  316. if !duelNow[vEnt:SteamID()] then
  317. duelNow[vEnt:SteamID()] = {name = vEnt:Nick(), wins = 1}
  318. file.Write("duelinginfo/plyduels.txt", util.TableToJSON(duelNow, true))
  319. else
  320. duelNow[vEnt:SteamID()] = {name = vEnt:Nick(), wins = duelNow[vEnt:SteamID()].wins + 1}
  321. file.Write("duelinginfo/plyduels.txt", util.TableToJSON(duelNow, true))
  322. end
  323. end
  324. end )
  325.  
  326. else
  327. ply:ChatPrint( "[Duels] You are not being challenged." )
  328. end
  329.  
  330. return ""
  331. end
  332. end )
  333.  
  334. util.AddNetworkString("paperlacksduelthing")
  335. resource.AddSingleFile("materials/topduelerthing/scrollhwrp.png")
  336.  
  337. /*
  338. for k, v in pairs(player.GetAll()) do
  339. local ply = v
  340. local duelNow = util.JSONToTable(file.Read("duelinginfo/plyduels.txt"))
  341. duelNow[ply:SteamID()] = {name = ply:Nick(), wins = 66}
  342. file.Write("duelinginfo/plyduels.txt", util.TableToJSON(duelNow, true))
  343. end
  344. */
  345.  
  346. local duelXPBoostAmount = 2/2 // give them an extra 10 percent of whatever amount of xp they got given, if this was 2, they would get 200% or 2 times the amount.
  347. // this is for the weekly person thing
  348.  
  349. local function findbysteamid(id)
  350. for k, v in pairs(player.GetAll()) do
  351. if v:SteamID() == id then return v end
  352. end
  353. return false
  354. end
  355.  
  356. timer.Create("paperlacksduelcaching", 5, 0, function()
  357. local biggestPly = false
  358. local plyEnt = 0
  359. if istable(util.JSONToTable(file.Read("duelinginfo/plyduels.txt"))) then
  360. for k, v in SortedPairsByMemberValue(util.JSONToTable(file.Read("duelinginfo/plyduels.txt")), "wins", true) do
  361. biggestPly = {name = v.name, wins = v.wins}
  362. plyEnt = findbysteamid(k)
  363. break
  364. end
  365. if istable(biggestPly) then
  366. net.Start("paperlacksduelthing")
  367. net.WriteTable(biggestPly)
  368. net.Broadcast()
  369. DuelingWeeklyWinner = biggestPly
  370. DuelingWeeklyWinner.ent = plyEnt
  371. end
  372. end
  373.  
  374. end)
  375.  
  376. hook.Add("PaperlacksXPBoostDueling", "boostshitdueling", function(ply, amount)
  377. if DuelingWeeklyWinner.ent != false then
  378. if ply == DuelingWeeklyWinner.ent then
  379. ply:addXP(amount * duelXPBoostAmount, false, true)
  380. end
  381. end
  382. end)
  383.  
  384. function ENT:Initialize( )
  385.  
  386. self:SetModel( "models/player/barney.mdl" )
  387. self:SetHullType( HULL_HUMAN )
  388. self:SetHullSizeNormal( )
  389. self:SetNPCState( NPC_STATE_SCRIPT )
  390. self:SetSolid( SOLID_BBOX )
  391. self:CapabilitiesAdd( bit.bor( CAP_ANIMATEDFACE, CAP_TURN_HEAD ) )
  392. self:SetUseType( SIMPLE_USE )
  393. self:DropToFloor()
  394.  
  395. self:SetMaxYawSpeed( 90 )
  396.  
  397. end
  398.  
  399. function ENT:OnTakeDamage()
  400. return false
  401. end
  402.  
  403. function ENT:AcceptInput( name, activator, caller )
  404. if name == "Use" and caller:IsPlayer() then
  405. net.Start( "openDuelMenu", caller)
  406. net.Send( caller )
  407. end
  408. end
  409.  
  410. concommand.Add( "whosdueling", function( ply )
  411. for k,v in pairs(player.GetAll()) do
  412. if v:GetNWBool( "isCurDueling" ) == true then
  413. ply:ChatPrint(v:Nick())
  414. end
  415. end
  416. end )
  417.  
  418. concommand.Add( "rg5ry54grewgerger", function( ply )
  419. for k,v in pairs(player.GetAll()) do
  420. v:SetNWBool( "isCurDueling", false )
  421. end
  422. end )
  423.  
  424. hook.Add( "InitPostEntity", "duelnpcspawn", function()
  425. local myEnt = ents.Create("npc_duel")
  426. myEnt:SetModel( "models/odessa.mdl" )
  427. myEnt:SetAngles(angleofDuelNPC)
  428. myEnt:SetPos(locationofDuelNPC)
  429. myEnt:Spawn()
  430. end )
  431.  
  432. hook.Add( "PlayerDisconnected", "endduelondc", function( ply )
  433. if ply:GetNWBool( "isCurDueling" ) == true then
  434. for k,v in pairs(player.GetAll()) do
  435. v:ChatPrint( "[Duels] "..ply:Nick().." left, so the duel ended in a draw." )
  436. if v:GetNWBool( "isCurDueling" ) == true then
  437. v:SetNWBool( "isCurDueling", false )
  438. v:KillSilent()
  439. duelAvailable = true
  440. duelAvailableText = "available"
  441. end
  442. end
  443. end
  444. end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement