· 7 years ago · Oct 17, 2018, 03:00 PM
1util.AddNetworkString( "armorSend" )
2
3hook.Add( "PlayerSpawn", "giveArmorBack", function( ply )
4 if ( Armor.LoseOnDeath and ply.armorSuit ) then
5 ply:removeArmorSuit()
6 return
7 end
8
9 timer.Simple( .05, function()
10 if ( ply.armorSuit ) then
11 ply:applyArmorSuit()
12 end
13 end )
14end )
15
16local PMeta = FindMetaTable( "Player" )
17
18function PMeta:applyArmorSuit()
19 local data = Armor:Get( self.armorSuit )
20
21 if ( !data ) then return end
22
23 self:SetModel( data.Model )
24
25 if ( data.OnGive ) then
26 data.OnGive( self )
27 end
28end
29
30function PMeta:removeArmorSuit()
31 local data = Armor:Get( self.armorSuit )
32
33 if ( !data ) then return end
34
35 if ( data.OnRemove ) then
36 data.OnRemove( self )
37 end
38
39 net.Start( "armorSend" )
40 net.WriteString( "nil" )
41 net.Send( self )
42
43 hook.Call( "PlayerSetModel", GAMEMODE, self )
44
45 timer.Destroy( self:SteamID().."_"..self.armorSuit )
46
47 self.armorSuit = nil
48end
49
50function PMeta:giveArmorSuit( name )
51 local data = Armor:Get( name )
52
53 if ( !data ) then return end
54
55 if ( self.armorSuit ) then
56 self:removeArmorSuit()
57 end
58
59 self.armorSuit = name
60 self:applyArmorSuit()
61
62 net.Start( "armorSend" )
63 net.WriteString( name )
64 net.Send( self )
65
66 if ( Armor.Save ) then
67 local info = sql.Query( "SELECT * from armor_suits WHERE SteamID = '"..self:SteamID().."'" )
68
69 if ( info and table.Count( info ) > 0 ) then
70 sql.Query( "UPDATE armor_suits SET SuitName = '"..name.."' WHERE SteamID = '"..self:SteamID().."'" )
71 else
72 sql.Query( "INSERT INTO armor_suits(`SteamID`, `SuitName`) VALUES('"..self:SteamID().."', '"..name.."')" )
73 end
74 else
75 local tStr = self:SteamID().."_"..name
76
77 timer.Create( tStr, data.Length, 1, function()
78 timer.Destroy( tStr )
79
80 if ( IsValid( self ) ) then
81 self:removeArmorSuit()
82 end
83 end )
84 end
85end
86
87local delay_of_boost = 5
88
89hook.Add( "KeyPress", "boostOnsHIFTtAU", function( ply, key )
90 if ( key != IN_SPEED ) then return end
91 if ( ply.armorSuit != "TAU Armor" ) then return end
92 if ( ( ply.armorLiftOff or 0 ) > CurTime() ) then return end
93
94 ply:SetVelocity( ( ply:GetAngles():Forward() * 800 ) + Vector( 0, 0, 400 ) )
95 sound.Play( "ambient/explosions/exp1.wav", ply:GetPos() )
96
97 ply.armorLiftOff = CurTime() + delay_of_boost
98end )
99
100if ( Armor.Save ) then
101 sql.Query( "CREATE TABLE IF NOT EXISTS armor_suits ( SteamID VARCHAR(50), SuitName VARCHAR(50) )" )
102
103 hook.Add( "PlayerInitialSpawn", "loadArmorsRay", function( ply )
104 timer.Simple( 10, function()
105 if ( !IsValid( ply ) ) then return end
106
107 local info = sql.Query( "SELECT * from armor_suits WHERE SteamID = '"..ply:SteamID().."'" )
108
109 if ( info and table.Count( info ) > 0 ) then
110 ply.armorSuit = info[1]["SuitName"]
111 ply:applyArmorSuit()
112
113 net.Start( "armorSend" )
114 net.WriteString( ply.armorSuit )
115 net.Send( ply )
116 end
117 end )
118 end )
119else
120 hook.Remove( "PlayerInitialSpawn", "loadArmorsRay" )
121end