Guest User

Untitled

a guest
Oct 17th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 23.75 KB | None | 0 0
  1. function iGo2_Chat(ply,txt)
  2.     local explode = string.Explode(" ",txt)
  3.     if ply:IsSuperAdmin() or iGo2_AsLeDroit(ply:SteamID()) then
  4.         if explode[1] == "!dial" then
  5.             if explode[2] != "" and explode[2] != nil then
  6.                 iGo2_OpenGates_DepartClosest_DestChat(ply,explode[2])
  7.             else
  8.                 iGo2_SendColoredText(ply,"Veuillez rentrer une adresse !",Color(255,255,255))
  9.             end
  10.             return ""
  11.         elseif explode[1] == "!close" then
  12.             iGo2_CloseGate(ply)
  13.             return ""
  14.         elseif explode[1] == "!rdm" then
  15.             iGo2_OpenGates_RandomDest(ply)
  16.             return ""
  17.         elseif explode[1] == "!inverse" then
  18.             iGo2_InverseGates(ply)
  19.             return ""
  20.         elseif explode[1] == "!closeall" and ply:IsSuperAdmin() then
  21.             iGo2_CloseAllGates(ply)
  22.             return ""
  23.         elseif explode[1] == "!dialid" then
  24.             if explode[2] != "" and tonumber(explode[2]) != nil then
  25.                 iGo2_OpenGates_DepartClosest_DestID(ply,explode[2])
  26.             else
  27.                 iGo2_SendColoredText(ply,"Veuillez rentrer un ID !",Color(255,255,255))
  28.             end
  29.             return ""
  30.         elseif explode[1] == "!miroir" then
  31.             iGo2_CreateMiroir(ply)
  32.             return ""
  33.         elseif explode[1] == "!iris" and ply:IsSuperAdmin() then
  34.             iGo2_DisableIris(ply)
  35.             return ""
  36.         elseif explode[1] == "!boom" and ply:IsSuperAdmin() then
  37.             iGo2_TrololoBOOM(ply)
  38.             return ""
  39.         elseif explode[1] == "!igorank" and ply:IsSuperAdmin() then
  40.             if explode[2] != "" and explode[2] != nil then
  41.                 iGo2_Rank(ply,explode[2])
  42.             end
  43.             return ""
  44.         elseif explode[1] == "!igodel" and ply:IsSuperAdmin() then
  45.             if explode[2] != "" and explode[2] != nil then
  46.                 iGo2_UnRank(ply,explode[2])
  47.             end
  48.             return ""
  49.         elseif explode[1] == "!liste" then
  50.             iGo2_ACC_Liste(ply)
  51.             return ""
  52.         elseif explode[1] == "!tollan" then
  53.             iGo2_TollanGate(ply)
  54.         elseif explode[1] == "!atlantis" then
  55.             iGo2_AtlantisGate(ply)
  56.         end
  57.     else
  58.         if txt == "!tollan" then
  59.             iGo2_TollanGate(ply)
  60.         elseif txt == "!atlantis" then
  61.             iGo2_AtlantisGate(ply)
  62.         end
  63.     end
  64. end
  65. hook.Add("PlayerSay","iGo2_Chat",iGo2_Chat)
  66.  
  67. local function FilterList(list, criterion)
  68.     local index = 1
  69.     while index <= #list do
  70.         if not criterion(list[index]) then
  71.             list[index] = list[#list]
  72.             table.remove(list)
  73.         else index = index + 1 end
  74.     end
  75.     return list
  76. end
  77.  
  78. function iGo2_AtlantisGate(jou)
  79.     porte = iGo2_TrouverGate(ply)
  80.     if jou:IsAdmin() or jou:IsSuperAdmin() then
  81.         if porte != nil then
  82.             if porte:GetClass() == "stargate_atlantis" then
  83.                 if porte.IsTollan then
  84.                     iGo2_AtlantisRAW(porte)
  85.                     iGo2_SendColoredText(jou,"Transformation : tollan --> atlantis ( ADMIN ! )",Color(255,255,255))
  86.                 else iGo2_SendColoredText(jou,"Cette porte n'est pas une porte Tollan !",Color(255,0,0)) end
  87.             else iGo2_SendColoredText(jou,"Cette porte n'est pas une Stargate Atlantis-Tollan !",Color(255,0,0)) end
  88.         else iGo2_SendColoredText(jou,"Vous n'etes pres d'aucune porte !",Color(255,0,0)) end
  89.     else
  90.         if porte != nil then
  91.             if porte:GetClass() == "stargate_atlantis" then
  92.                 if porte.Owner == jou then
  93.                     if porte.IsTollan then
  94.                         iGo2_AtlantisRAW(porte)
  95.                         iGo2_SendColoredText(jou,"Transformation : tollan --> atlantis ( NON ADMIN ! )",Color(255,255,255))
  96.                     else iGo2_SendColoredText(jou,"Cette porte n'est pas une porte Tollan !",Color(255,0,0)) end
  97.                 else iGo2_SendColoredText(jou,"Vous ne possedez pas cette porte, impossible de la transformer en Atlantis !",Color(255,0,0)) end
  98.             else iGo2_SendColoredText(jou,"Cette porte n'est pas une Stargate Atlantis-Tollan !",Color(255,0,0)) end
  99.         else iGo2_SendColoredText(jou,"Vous n'etes pres d'aucune porte !",Color(255,0,0)) end
  100.     end
  101. end
  102.  
  103. function iGo2_AtlantisRAW(porte)
  104.     porte:AddChevron()
  105.     for i=1,7 do porte.Chevron[i]:SetAngles(porte:GetAngles()) end
  106.     porte:SetModel("models/zup/stargate/sga_base.mdl")
  107.     porte.Sounds = {
  108.         Ring=Sound("stargate/gate_roll_atlantis.mp3"),
  109.         Open=Sound("stargate/gate_open_atlantis.mp3"),
  110.         Travel=Sound("stargate/gate_travel.mp3"),
  111.         Close=Sound("stargate/gate_close.mp3"),
  112.         Chevron=Sound("stargate/chevron_atlantis.mp3"),
  113.         Inbound=Sound("stargate/chevron_atlantis_incoming.mp3"),
  114.         Lock=Sound("stargate/chevron_lock_atlantis.mp3"),
  115.         LockInbound=Sound("stargate/chevron_lock_atlantis_incoming.mp3"),
  116.         Fail=Sound("stargate/dial_fail_atlantis.mp3")
  117.     }
  118.     porte.IsTollan = false
  119. end
  120.  
  121. function iGo2_TollanGate(jou)
  122.     porte = iGo2_TrouverGate(jou)
  123.     if jou:IsAdmin() or jou:IsSuperAdmin() then
  124.         if porte != nil then
  125.             if porte:GetClass() == "stargate_atlantis" then
  126.                 if not porte.IsTollan then
  127.                     iGo2_TollanRAW(porte)
  128.                     iGo2_SendColoredText(jou,"Transformation : atlantis --> tollan ( ADMIN ! )",Color(255,255,255))
  129.                 else iGo2_SendColoredText(jou,"Cette porte est deja une porte Tollan !",Color(255,0,0)) end
  130.             else iGo2_SendColoredText(jou,"Cette porte n'est pas une Stargate Atlantis !",Color(255,0,0)) end
  131.         else iGo2_SendColoredText(jou,"Vous n'etes pres d'aucune porte !",Color(255,0,0)) end
  132.     else
  133.         if porte != nil then
  134.             if porte:GetClass() == "stargate_atlantis" then
  135.                 if porte.Owner == jou then
  136.                     if not porte.IsTollan then
  137.                         iGo2_TollanRAW(porte)
  138.                         iGo2_SendColoredText(jou,"Transformation : atlantis --> tollan ( NON ADMIN !)",Color(255,255,255))
  139.                     else iGo2_SendColoredText(jou,"Cette porte est deja une porte Tollan !",Color(255,0,0)) end
  140.                 else iGo2_SendColoredText(jou,"Vous ne possedez pas cette porte, impossible de la transformer en Tollan !",Color(255,0,0)) end
  141.             else iGo2_SendColoredText(jou,"Cette porte n'est pas une Stargate Atlantis !",Color(255,0,0)) end
  142.         else iGo2_SendColoredText(jou,"Vous n'etes pres d'aucune porte !",Color(255,0,0)) end
  143.     end
  144. end
  145.  
  146. function iGo2_TollanRAW(porte)
  147.     porte:SetModel("models/Cebt/test_sgt.mdl")
  148.     for i=1,7 do porte.Chevron[i]:Remove() end
  149.     porte.Sounds = {
  150.         Ring=Sound("stargate/supergate/roll.mp3"),
  151.         Open=Sound("stargate/shield/hit_2.mp3"),
  152.         Lock=Sound("stargate/shield/close.mp3"),
  153.         Chevron=Sound("stargate/iris_atlantis_hit.mp3"),
  154.         Inbound=Sound("stargate/iris_atlantis_hit.mp3"),
  155.         LockInbound=Sound("stargate/shield/close.mp3"),
  156.         Fail=Sound("stargate/iris/hit_2.mp3")
  157.     }
  158.     porte.IsTollan = true
  159. end
  160.  
  161. function iGo2_FindPEByName(name)
  162.     name = string.lower(name)
  163.     return FilterList(player.GetAll(), function(ent) return string.find(string.lower(ent:GetName()), name,1,true) end)[1]
  164. end
  165.  
  166. function iGo2_ACC_Liste(ply)
  167.     if table.Count(iGo2_AcceptedClients) == 0 then
  168.         ply:ChatPrint("liste vide")
  169.     else
  170.         ply:ChatPrint("liste :")
  171.         for k,v in pairs(iGo2_AcceptedClients) do
  172.             ply:ChatPrint(tostring(k).." : "..v)
  173.         end
  174.     end
  175. end
  176.  
  177. function iGo2_ReloadFile()
  178.     if file.Exists("iGo2AcceptedClients.txt") then
  179.         iGo2_AcceptedClients = glon.decode(file.Read("iGo2AcceptedClients.txt"))
  180.     else
  181.         file.Write("iGo2AcceptedClients.txt",glon.encode({}))
  182.         iGo2_AcceptedClients = {}
  183.     end
  184. end
  185. iGo2_ReloadFile()
  186.  
  187. function iGo2_RewriteFile()
  188.     file.Write("iGo2AcceptedClients.txt",glon.encode(iGo2_AcceptedClients))
  189. end  
  190.  
  191. function iGo2_Rank(ply,name)
  192.     local temp_arank = iGo2_FindPEByName(name)
  193.     if temp_arank then
  194.         local verify_print = iGo2_RankRAW(temp_arank)
  195.         if verify_print then
  196.             iGo2_SendColoredText(ply,"Le joueur \\\""..temp_arank:Nick().."\\\" possede deja le droit d'utiliser iGo V2.",Color(255,255,255))
  197.         else
  198.             iGo2_SendColoredText(ply,"Le joueur \\\""..temp_arank:Nick().."\\\" peut maintenant utiliser iGo V2.",Color(255,255,255))
  199.         end
  200.     else
  201.         iGo2_SendColoredText(ply,"Joueur introuvable !",Color(255,255,255))
  202.     end
  203. end
  204.  
  205. function iGo2_UnRank(ply,name)
  206.     local temp_arank = iGo2_FindPEByName(name)
  207.     if temp_arank then
  208.         local verify_print = iGo2_UnRankRAW(temp_arank)
  209.         if verify_print then
  210.             iGo2_SendColoredText(ply,"Le joueur \\\""..temp_arank:Nick().."\\\" n'a plus le droit d'utiliser iGo V2.",Color(255,255,255))
  211.         else
  212.             iGo2_SendColoredText(ply,"Le joueur n'est pas present dans la liste ACC.",Color(255,255,255))
  213.         end
  214.     else
  215.         iGo2_SendColoredText(ply,"Joueur introuvable !",Color(255,255,255))
  216.     end
  217. end
  218.  
  219. function iGo2_UnRankRAW(temp_arank)
  220.     local TEMP = false
  221.     if table.Count(iGo2_AcceptedClients) != 0 then
  222.         for k,v in pairs(iGo2_AcceptedClients) do
  223.             if v == temp_arank:SteamID() then
  224.                 TEMP = true
  225.                 TEMP_NUM = k
  226.             end
  227.         end
  228.     end
  229.     if TEMP == true then
  230.         iGo2_SendColoredText(temp_arank,"Vous n'avez plus le droit d'utiliser iGo V2...",Color(255,255,255))
  231.         table.remove(iGo2_AcceptedClients,TEMP_NUM)
  232.         iGo2_RewriteFile()
  233.     end
  234.     return TEMP
  235. end
  236.  
  237. function iGo2_RankRAW(temp_arank)
  238.     local TEMP = false
  239.     if table.Count(iGo2_AcceptedClients) != 0 then
  240.         for k,v in pairs(iGo2_AcceptedClients) do
  241.             if v == temp_arank:SteamID() then TEMP = true end
  242.         end
  243.     end
  244.     if TEMP == false then
  245.         table.insert(iGo2_AcceptedClients,temp_arank:SteamID())
  246.         iGo2_SendColoredText(temp_arank,"Felicitations, un administrateur vous donne le droit d'utiliser iGo V2 !",Color(255,255,255))
  247.         iGo2_RewriteFile()
  248.     end
  249.     return TEMP
  250. end
  251.  
  252. function iGo2_AsLeDroit(SID)
  253.     local RET = false
  254.     for k,v in pairs(iGo2_AcceptedClients) do
  255.         if v == SID then RET = true end
  256.     end
  257.     return RET
  258. end
  259.  
  260.  
  261. function iGo2_TrololoBOOM(ply)
  262.     local VerifyGates = iGo2_TrouverGate(ply)
  263.     if VerifyGates != nil then
  264.         if VerifyGates.IsOpen then
  265.             StargateExtras:DestroyStargate(VerifyGates.Target)
  266.             iGo2_SendColoredText(ply,"YA TATATA YA TATATATATATA KABOOOOOOOOOM !",Color(255,255,255))
  267.         else
  268.             iGo2_SendColoredText(ply,"La porte la plus proche n'est pas ouverte !.",Color(255,255,255))
  269.         end
  270.     else
  271.         iGo2_SendColoredText(ply,"Aucune porte sur la map.",Color(255,255,255))
  272.     end
  273. end
  274.  
  275. function iGo2_DisableIris(ply)
  276.     local VerifyGates = iGo2_TrouverGate(ply)
  277.     if VerifyGates != nil then
  278.         if VerifyGates.IsOpen then
  279.             local Iris1 = iGo2_GetIrisFromGate(VerifyGates)
  280.             if Iris1 then if Iris1.IsActivated then Iris1:Toggle() end end
  281.             local Iris2 = iGo2_GetIrisFromGate(VerifyGates.Target)
  282.             if Iris2 then if Iris2.IsActivated then Iris2:Toggle() end end
  283.         else
  284.             local Iris1 = iGo2_GetIrisFromGate(VerifyGates)
  285.             if Iris1 then if Iris1.IsActivated then Iris1:Toggle() end end
  286.         end
  287.     else
  288.         iGo2_SendColoredText(ply,"Aucune porte sur la map.",Color(255,255,255))
  289.     end
  290. end
  291.  
  292. function iGo2_GetIrisFromGate(porte)
  293.     local Final = nil
  294.     local max = 15
  295.     for _,v in pairs(ents.FindByClass("stargate_iris")) do
  296.         local distance = (porte:GetPos()-v:GetPos()):Length()
  297.         if ( distance < max ) then
  298.             max = distance
  299.             Final = v
  300.         end
  301.     end
  302.     return Final
  303. end
  304.  
  305. function iGo2_CloseGate(jou)
  306.     local Porte = iGo2_TrouverGate(jou)
  307.     if Porte.IsOpen then
  308.         Porte:AbortDialling()
  309.         hook.Call("StarGate.Player.ClosedGate",GAMEMODE,jou,Porte)
  310.         iGo2_SendColoredText(jou,"Fermeture de la porte !",Color(255,255,255))
  311.     else
  312.         iGo2_SendColoredText(jou,"Cette porte n'est pas ouverte !",Color(255,255,255))
  313.     end
  314. end
  315.  
  316. function iGo2_UnlinkG(SG)
  317.     if SG != nil then
  318.         if SG.IsOpen then
  319.             SG.DialledAddress = {}
  320.             SG.Target = nil
  321.             SG:Close(1)
  322.         end
  323.     end
  324. end
  325.  
  326. function iGo2_SendColoredText(ply,txt,col)
  327.     ply:SendLua("chat.AddText(Color(200,100,0),\"[iGo] \",Color("..col.r..","..col.g..","..col.b.."),\""..txt.."\")")
  328. end
  329.  
  330. function iGo2_OpenGates_RandomDest(ply)
  331.     local Tdep = iGo2_TrouverGate(ply)
  332.                                         local Tdest = iGo2_GetRandomGate_Except(Tdep,ply)
  333.     iGo2_OpenGates_Security(ply,Tdep,Tdest)
  334. end
  335.  
  336. function iGo2_CloseAllGates(ply)
  337.     local VerifyGates = iGo2_TrouverGate(ply)
  338.     if VerifyGates != nil then
  339.         for k,v in pairs(iGo2_ListeGates()) do
  340.             v:AbortDialling()
  341.         end
  342.         iGo2_SendColoredText(ply,"Fermeture de toute les portes de la map !",Color(255,255,255))
  343.     else
  344.         iGo2_SendColoredText(ply,"Aucune porte sur la map !",Color(255,255,255))
  345.     end
  346. end
  347.  
  348. function iGo2_InverseGates(ply)
  349.     local VerifyGates = iGo2_TrouverGate(ply)
  350.     if VerifyGates != nil then
  351.         TINVDepart = iGo2_TrouverGate(ply)
  352.         if TINVDepart.IsOpen then
  353.             if TINVDepart.Outbound then
  354.                 iGo2_OpenGates_Security(ply,TINVDepart.Target,TINVDepart)
  355.             else
  356.                 iGo2_OpenGates_Security(ply,TINVDepart,TINVDepart.Target)
  357.             end
  358.         else
  359.             iGo2_SendColoredText(ply,"Impossible d'inverser les vortex, cette porte n'est pas ouverte.",Color(255,255,255))
  360.         end
  361.     else
  362.         iGo2_SendColoredText(ply,"Aucune porte sur la map.",Color(255,255,255))
  363.     end
  364. end
  365.  
  366. function iGo2_GetRandomGate_Except(gatetoeject,ply)
  367.     TEMP_LG = iGo2_ListeGates()
  368.     if table.Count(TEMP_LG) > 1 then
  369.         local TEMP_LG = iGo2_ListeGates()
  370.             for k,v in pairs(TEMP_LG) do
  371.                 if v == gatetoeject then
  372.                     table.remove(TEMP_LG,k)
  373.                 end
  374.             end
  375.             local random_number_gate = math.random(1,table.Count(TEMP_LG))
  376.         return TEMP_LG[random_number_gate]
  377.     else
  378.         return nil
  379.     end
  380. end
  381.  
  382. function iGo2_OpenGates_DepartClosest_DestChat(ply,txt)
  383.     local departT = iGo2_TrouverGate(ply)
  384.     local destT = iGo2_AddressToEntity(txt)
  385.     iGo2_OpenGates_Security(ply,departT,destT)
  386. end
  387.  
  388. function iGo2_OpenGates_DepartClosest_DestID(ply,testnum)
  389.     local departT = iGo2_TrouverGate(ply)
  390.     local destT = ents.GetByIndex(tonumber(testnum))
  391.    
  392.     if destT:EntIndex() != 0 and destT != nil then
  393.         if destT.IsStargate then
  394.             iGo2_OpenGates_Security(ply,departT,destT)
  395.         else
  396.             iGo2_SendColoredText(ply,"La destination "..tonumber(testnum).." n'est pas une stargate ( \\\""..destT:GetClass().."\\\" )!",Color(255,255,255))
  397.         end
  398.     else
  399.         iGo2_SendColoredText(ply,"La destination "..tonumber(testnum).." n'existe pas !",Color(255,255,255))
  400.     end
  401. end
  402.  
  403. function iGo2_OpenGates_Security(ply,depf,destf)
  404.     if ValidEntity(ply) then
  405.         if ply:IsPlayer() then
  406.             if !depf then
  407.                 iGo2_SendColoredText(ply,"Stargate de depart invalide !",Color(255,255,255))
  408.             elseif !destf then
  409.                 iGo2_SendColoredText(ply,"Stargate de destination invalide !",Color(255,255,255))
  410.                 depf.EmitSound(depf,depf.Sounds.Fail,90,math.random(95,105))
  411.             elseif depf == destf then
  412.                 iGo2_SendColoredText(ply,"Impossible d'appeler la meme porte ! ( Depart = Destination )",Color(255,255,255))
  413.                 depf.EmitSound(depf,depf.Sounds.Fail,90,math.random(95,105))
  414.             else
  415.                 iGo2_OpenTwoGates(depf,destf)
  416.                 iGo2_SendColoredText(ply,"Ouverture vers "..string.upper(destf:GetGateAddress()).." !",Color(255,255,255))
  417.             end
  418.         end
  419.     end
  420. end
  421.  
  422. function iGo2_AddressToEntity(addr)
  423.     local find = nil
  424.     for k,v in pairs(iGo2_ListeGates()) do
  425.         if string.lower(v:GetGateAddress()) == string.lower(addr) then
  426.             find = v
  427.         end
  428.     end
  429.     return find
  430. end
  431.  
  432. function iGo2_CreateMiroir(ply)
  433.     MiroirT = iGo2_TrouverGate(ply)
  434.     if MiroirT != nil then
  435.         MiroirT.Target = MiroirT
  436.         MiroirT.Outbound = true
  437.         iGo2_ActChevron(MiroirT,0)
  438.         iGo2_CreateEV(MiroirT)
  439.         MiroirT.EventHorizon:SetMaterial("models/props_lab/Tank_Glass001")
  440.         iGo2_SendColoredText(ply,"Creation d'une stargate miroir !",Color(255,255,255))
  441.     else
  442.         iGo2_SendColoredText(ply,"Aucune porte sur la map.",Color(255,255,255))
  443.     end
  444. end
  445.  
  446. function iGo2_OpenTwoGates(gate1,gate2)
  447.     if gate1.IsStargate and gate2.IsStargate then
  448.         if gate1.Target != gate2 and gate2.Target != gate1 then
  449.             if gate1.IsOpen then iGo2_UnlinkG(gate1.Target) end
  450.             if gate2.IsOpen then iGo2_UnlinkG(gate2.Target) end
  451.         end
  452.        
  453.         local Iris1 = iGo2_GetIrisFromGate(gate1)
  454.         if Iris1 then if Iris1.IsActivated then Iris1:Toggle() end end
  455.        
  456.         local Iris2 = iGo2_GetIrisFromGate(gate2)
  457.         if Iris2 then if Iris2.IsActivated then Iris2:Toggle() end end
  458.    
  459.         gate1.Target = gate2
  460.         gate2.Target = gate1
  461.         gate1.Outbound = true
  462.         gate2.Outbound = false
  463.         iGo2_ActChevron(gate1,0)
  464.         iGo2_ActChevron(gate2,1)
  465.         iGo2_CreateEV(gate1)
  466.         iGo2_CreateEV(gate2)
  467.         gate1.IsOpen = true
  468.         gate2.IsOpen = true
  469.         iGo2_ActivateDHD(gate1,gate2:GetGateAddress())
  470.         iGo2_ActivateDHD(gate2,gate1:GetGateAddress())
  471.     end
  472. end
  473.  
  474. function iGo2_ListeGates()
  475.     local sg1 = ents.FindByClass("stargate_sg1")
  476.     local sga = ents.FindByClass("stargate_atlantis")
  477.     local sg1p = ents.FindByClass("stargate_energy_sg1")
  478.     local gates = {}
  479.     for _,v in pairs(sg1) do table.insert(gates,v) end
  480.     for _,v in pairs(sga) do table.insert(gates,v) end
  481.     for _,v in pairs(sg1p) do table.insert(gates,v) end
  482.     return gates
  483. end
  484.  
  485. function iGo2_TrouverGate(jou)
  486.     tr = jou:GetEyeTrace()
  487.     Find = 0
  488.     if tr.Entity:IsValid() then
  489.         AimEnt = tr.Entity
  490.         if AimEnt:GetClass() != "stargate_iris" and AimEnt:GetClass():find("stargate_") then
  491.             Find = 1
  492.             return AimEnt
  493.         end
  494.     end
  495.     if Find == 0 then
  496.         local gate
  497.         local dist = 1000000
  498.         local pos = jou:GetPos()
  499.         for _,v in pairs(iGo2_ListeGates()) do
  500.             local sg_dist = (pos-v:GetPos()):Length()
  501.             if ( sg_dist < dist ) then
  502.                 dist = sg_dist
  503.                 gate = v
  504.             end
  505.         end
  506.         return gate
  507.     end
  508. end
  509.  
  510. function iGo2_ActChevron(Porte,inbound)
  511.     if not Porte:IsPlayer() then
  512.         if Porte:GetClass() == "stargate_atlantis" or Porte:GetClass() == "stargate_sg1" then
  513.             for i=1,7 do
  514.                 Porte.Chevron[i]:Fire("skin",1)
  515.                 Porte:SetNWBool("chevron"..i,true)
  516.             end
  517.             Porte:Fire("SetBodyGroup",8+inbound)
  518.         end
  519.     end
  520. end
  521.  
  522. function iGo2_ActivateDHD(gate,address)
  523.     if address == "" then
  524.         for k,v in pairs(gate:FindDHD()) do
  525.             v:AddChevron("DIAL",true)
  526.         end
  527.     else
  528.         for k,v in pairs(gate:FindDHD()) do
  529.             for u,i in pairs(string.Explode("",address)) do
  530.                 v:AddChevron(i,true)
  531.             end
  532.             v:AddChevron("DIAL",true)
  533.         end
  534.     end
  535. end
  536.  
  537. function iGo2_CreateEV(SG)
  538.     if not SG:IsPlayer() then SG:SetStatus(true,false,false) end
  539.     local e = ents.Create("event_horizon")
  540.     e:SetPos(SG:GetPos())
  541.     e:SetAngles(SG:GetAngles())
  542.     e:SetParent(SG.Entity)
  543.     e:SetEVInstantOpen()
  544.     if SG.Sounds and SG.Sounds.Open then e.Sounds.Open = SG.Sounds.Open end
  545.     e:Spawn()
  546.     e:Activate()
  547.     if SG.Outbound then e:SetTarget(SG.Target) end
  548.     if ValidEntity(SG.EventHorizon) then SG.EventHorizon:Remove() end
  549.     SG.EventHorizon = e
  550. end
  551.  
  552. function iGo2_SG_Initialize(EventHorizon)
  553.     EventHorizon.Sounds = {
  554.         Idle=Sound("stargate/wormhole_loop.wav"),
  555.         Teleport=Sound("stargate/teleport.mp3"),
  556.         Shutdown=Sound("stargate/gate_close.mp3"),
  557.         Open=Sound("stargate/shield/hit.mp3")
  558.     }
  559.     EventHorizon.Entity:SetModel(EventHorizon.Model)
  560.     EventHorizon.Entity:PhysicsInit(SOLID_VPHYSICS)
  561.     EventHorizon.Entity:SetMoveType(MOVETYPE_NONE)
  562.     EventHorizon.Entity:SetTrigger(true)
  563.     EventHorizon.Entity:SetNotSolid(true)
  564.     EventHorizon.Entity:DrawShadow(false)
  565.     EventHorizon.Entity:SetColor(255,255,255,1)
  566.     EventHorizon.Created = CurTime()
  567.     EventHorizon.AutoClose = StarGate.CFG:Get("stargate","autoclose",true)
  568.     EventHorizon.HorizonRadius = 150
  569.     EventHorizon.OpeningDelay = 0.7
  570.     EventHorizon.OpenTime = 0.7
  571.     EventHorizon.Holding = {}
  572.     EventHorizon.DoNotDestroy = {}
  573.     iGo2_SG_Open(EventHorizon)
  574.     local phys = EventHorizon.Entity:GetPhysicsObject()
  575.     if phys:IsValid() then
  576.         phys:EnableCollisions(true)
  577.     end
  578. end
  579.  
  580. function iGo2_SG_Open(EventHorizon)
  581.     EventHorizon.Attached = {}
  582.     local parent = EventHorizon.Entity:GetParent()
  583.     if ValidEntity(parent) then
  584.         EventHorizon.Attached[parent] = true
  585.         EventHorizon.Attached[parent.Target] = true
  586.         EventHorizon.Attached[EventHorizon.Entity] = true
  587.         for _,v in pairs(StarGate.GetConstrainedEnts(parent,10) or {}) do EventHorizon.Attached[v] = true end
  588.     end
  589.     local e = EventHorizon.Entity
  590.     local fx = EffectData()
  591.     fx:SetEntity(e)
  592.     fx:SetOrigin(e:GetPos())
  593.     fx:SetScale(EventHorizon.OpeningDelay+0.1);
  594.     util.Effect("eventhorizon_open",fx,true,true);
  595.     EventHorizon.Entity:EmitSound(EventHorizon.Sounds.Open,90,math.random(98,102))
  596.     timer.Create("EventHorizonOpening"..EventHorizon.Entity:EntIndex(),EventHorizon.OpeningDelay,1,
  597.     function()
  598.         if ValidEntity(e) then
  599.             local blocked = false
  600.             if ValidEntity(parent) and parent.IsStargate then blocked = parent:IsBlocked() end
  601.             if not ValidEntity(EventHorizon.Target) and ValidEntity(EventHorizon.TargetGate) then EventHorizon.Target = EventHorizon.TargetGate.EventHorizon end
  602.             e:SetNWEntity("Target",EventHorizon.Target)
  603.             local pos = e:GetPos()
  604.             e:SetColor(255,255,255,255)
  605.             timer.Simple(e.OpenTime+0.3,function()
  606.                 if ValidEntity(e) then e:SetColor(255,255,255,255) end
  607.             end)
  608.             e:SetNWBool("activate_lights",true)
  609.             util.ScreenShake(pos,2,2.5,3,1000)
  610.             e.IdleSound = CreateSound(e,e.Sounds.Idle)
  611.             e.IdleSound:Play()
  612.             local fx = EffectData()
  613.             fx:SetEntity(e)
  614.             fx:SetOrigin(pos)
  615.             fx:SetScale(e.OpenTime)
  616.             util.Effect("eventhorizon_stabilize",fx,true,true)
  617.             local fx = EffectData()
  618.             fx:SetEntity(e)
  619.             fx:SetOrigin(pos)
  620.             util.Effect("eventhorizon_refract",fx,true,true)
  621.         end
  622.     end)
  623. end
  624.  
  625. function iGo2_SG_OpenViaConsoleCommand(ply,C,A)
  626.     if A[1] != nil then
  627.         if A[1] != "" then
  628.             iGo2_OpenGates_DepartClosest_DestID(ply,A[1])
  629.         else
  630.             iGo2_SendColoredText(ply,"DEBUG CONSOLE / Empty value for arg",Color(255,255,255))
  631.         end
  632.     else
  633.         iGo2_SendColoredText(ply,"DEBUG CONSOLE / Nil value for arg",Color(255,255,255))
  634.     end
  635. end
  636.  
  637. concommand.Add("_iGoV2_OpenClosestGateToEntIndex",iGo2_SG_OpenViaConsoleCommand)
  638.  
  639. EV_MT = FindMetaTable("Entity")
  640. function EV_MT:SetEVInstantOpen()
  641.     self.Initialize = function() iGo2_SG_Initialize(self) end
  642. end
Add Comment
Please, Sign In to add comment