· 9 years ago · Jan 15, 2017, 04:26 AM
1--########################
2--# Teleport System #
3--# Created By: Boxvader #
4--########################
5
6--##################################################################################################################
7-- CONFIGURATION SETTINGS BELOW
8--##################################################################################################################
9silent = true -- true = Silent Commands (no one can see it) / false = unsilenced commands (anyone can see it)
10addTPRanks = {"superadmin", "owner"} -- Enter the ranks you want to be able to add and remove teleports
11tpRanks = {"admin", "superadmin"} -- Enter the ranks you want to have access to the teleport command and show tp command
12tpChatCommand = "/tp" -- What you want the /tp command to be (NOTE: !tp will conflict with ULX)
13showTPCommand = "!tps" -- what you want the chat command to show all tp's to be
14addTPChatCommand = "/addtp" -- What you want the /addtp command to be
15--##################################################################################################################
16
17-- DO NOT TOUCH ANYTHING BELOW THIS LINE
18-----------------------------------------------------------------------------------------------------------------------------
19chatcomTP = string.len(tpChatCommand) -- DO NOT TOUCH THIS!!!
20chatcomADD = string.len(addTPChatCommand)--DO NOT TOUCH THIS!!!
21chatComShow = string.len(showTPCommand) -- DO NOT TOUCH THIS!!!
22locations = {} -- DO NOT TOUCH THIS!!!!
23
24hook.Add( "PlayerSay", "addTP", function( ply, text, public ) -- This is the add a teleport location command
25if ( string.sub(text,1, chatcomADD) == addTPChatCommand) then -- Checking for the right chat command
26local flag = false -- creating a flag variable
27local tableCon = table.Count(addTPRanks) -- Counting how many ranks in the table
28for i = 1, tableCon do -- Looping throught the ranks
29if( ply:IsUserGroup(addTPRanks[i]) == true) then flag = true end -- Checking if the player is a user group
30end
31-- if the player is not found in one of the user groups the program is terminated
32if(flag == false) then ply:PrintMessage( 3, "You do not have permission to use " .. string.sub(text,1,6) ) return false end
33
34local trace = ply:GetEyeTrace() -- finding the location of where the player is looking at
35local position = ply:GetPos() -- getting the players position
36local input = string.Explode(' ', text) -- Breaking apart the entered text
37print(table.Count(input))
38if (table.Count(input) == 1) then ply:PrintMessage( 3, "no name was entered") return false end
39local name = input[2] -- Getting the name of the teleport
40--ply:SetPos(position) -- setting the players position to that of the trace
41print(position) -- Printing the position to console for debugging
42local datawrite = tostring(position) -- converting the position data to a string
43
44datawrite = name.."$ " .. datawrite .. "#" -- adding the identifier
45print (datawrite)
46local alreadyThere = file.Exists("teleport.txt", "DATA") -- checking if the file already exsists
47if (alreadyThere == true) then -- If it exists we will append the exsisting file
48file.Append("teleport.txt", datawrite )
49print("FILE ALREADY FOUND")
50else -- If it does not exisit we will create the file and write to it
51file.Write("teleport.txt", datawrite )
52print("NEW FILE CREATED")
53end
54ply:PrintMessage( 3, "New teleport <" .. input[2] .. "> added")
55if (silent == true) then return "" end -- If commands are set to be silenced this will silence them
56end
57end)
58
59--###############################################################################################################################################
60-- THIS IS S A CHAT COMMAND FOR DEBUGGING PURPOSES IT READS THE FILE AND PRINTS IT TO CONSOLE
61--###############################################################################################################################################
62hook.Add( "PlayerSay", "readFILE", function( ply, text, public )
63if ( string.sub(text,1,5) == "/read") then
64local fileData = file.Read("teleport.txt", "DATA")
65print(fileData)
66locations = string.Explode( '#', fileData )
67PrintTable(locations)
68if (silent == true) then return "" end
69end
70end)
71
72--################################################################################################################################################
73-- CHAT COMMAND TO DISPLAY ALL TELEPORT LOCATIONS
74--################################################################################################################################################
75hook.Add( "PlayerSay", "displayTPs", function( ply, text, public )
76if ( string.sub(text,1,chatComShow) == showTPCommand) then
77
78local flag = false
79local tableCon = table.Count(tpRanks)
80for i = 1, tableCon do
81if( ply:IsUserGroup(tpRanks[i]) == true) then flag = true end
82end
83if(flag == false) then ply:PrintMessage( 3, "You do not have permission to use " .. string.sub(text,1,chatComShow) ) return false end
84
85local fileData = file.Read("teleport.txt", "DATA")
86ply:PrintMessage( 3,"Displaying Teleports: ")
87locations = string.Explode( '#', fileData )
88local size = table.Count(locations)
89for i = 1, size do -- A for loop to run the length of positions in the file
90local temp = string.Explode('$', locations[i])
91ply:PrintMessage( 3, temp[1])
92end -- END OF THE FOR LOOP
93if (silent == true) then return "" end
94end
95end)
96
97hook.Add( "PlayerSay", "readFILE", function( ply, text, public )
98if ( string.sub(text,1,5) == "/read") then
99local fileData = file.Read("teleport.txt", "DATA")
100print(fileData)
101locations = string.Explode( '#', fileData )
102PrintTable(locations)
103if (silent == true) then return "" end
104end
105end)
106
107--################################################################################################################################################
108-- THIS IS THE ACTUAL TELEPORT CHAT COMMAND
109--################################################################################################################################################
110hook.Add( "PlayerSay", "teleport", function( ply, text, public )
111if ( string.sub(text,1,chatcomTP) == tpChatCommand) then -- checking for the !tp command
112local fileData = file.Read("teleport.txt", "DATA") -- reading the data from the file
113local command = string.Explode( ' ', text) -- breaking apart the !tp command
114local length = table.Count(command) -- checking how long the command is
115
116local flag = false
117local tableCon = table.Count(tpRanks)
118for i = 1, tableCon do
119if( ply:IsUserGroup(tpRanks[i]) == true) then flag = true end
120end
121if(flag == false) then ply:PrintMessage( 3, "You do not have permission to use " .. string.sub(text,1,chatcomTP) ) return false end
122
123local togo = command[2] --
124locations = string.Explode( '#', fileData )
125local size = table.Count(locations)
126local indexSave = 0
127local vectorSave = ""
128for i = 1, size do -- A for loop to run the length of positions in the file
129print(i)
130local temp = string.Explode('$', locations[i])
131if( togo == temp[1]) then
132vectorSave = temp[2]
133print("VectorSave")
134print(vectorSave)
135end
136--print(temp[2])
137end -- END OF THE FOR LOOP
138print("$$$$$$$$$$$$$$$$")
139print(vectorSave)
140local placeToGo = util.StringToType( vectorSave, "Vector" )
141print(placeToGo)
142
143if (length == 2) then -- If there are only 2 entered inputs the user will be tped
144ply:SetPos(placeToGo)
145else -- This is for if the teleport is for another person
146table.remove(command, 1)
147table.remove(command, 1)
148local target = string.Implode(' ', command)
149print(target)
150
151local char = string.len(target)
152local nameSave = " "
153local counter = 0
154for k, v in pairs( player.GetAll() ) do
155 local playerName = string.sub(v:GetName(), 1,char)
156 local nameLenght = string.len(playerName)
157 if (string.upper(target) == string.upper(playerName)) then
158 counter = counter + 1
159 nameSave = v
160 print("Player Found!")
161 print(nameSave)
162 end
163end
164if(counter > 1) then ply:PrintMessage( 3, counter .. " people were found using " .. target) end
165if(counter == 0) then ply:PrintMessage( 3, "No player found with the name ".. target) end
166target = nameSave
167target:SetPos(placeToGo)
168end
169if (silent == true) then return "" end -- Makes the command silent
170end
171end)