Advertisement
Guest User

Untitled

a guest
May 26th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.69 KB | None | 0 0
  1. function table.save(  tbl,filename )
  2.    local charS,charE = "   ","\n"
  3.    local file,err
  4.    
  5.    if not filename then
  6.       file =  { write = function( self,newstr ) self.str = self.str..newstr end, str = "" }
  7.       charS,charE = ""
  8.  
  9.    elseif filename == true or filename == 1 then
  10.       charS,charE,file = "","",io.tmpfile()
  11.  
  12.    else
  13.       file,err = io.open( filename, "w" )
  14.       if err then return _,err end
  15.    end
  16.    
  17.    local tables,lookup = { tbl },{ [tbl] = 1 }
  18.    file:write( "return {"..charE )
  19.    for idx,t in ipairs( tables ) do
  20.       if filename and filename ~= true and filename ~= 1 then
  21.          file:write( "-- Table: {"..idx.."}"..charE )
  22.       end
  23.       file:write( "{"..charE )
  24.       local thandled = {}
  25.       for i,v in ipairs( t ) do
  26.          thandled[i] = true
  27.          
  28.          if type( v ) ~= "userdata" then
  29.            
  30.             if type( v ) == "table" then
  31.                if not lookup[v] then
  32.                   table.insert( tables, v )
  33.                   lookup[v] = #tables
  34.                end
  35.                file:write( charS.."{"..lookup[v].."},"..charE )
  36.             elseif type( v ) == "function" then
  37.                file:write( charS.."loadstring("..exportstring(string.dump( v )).."),"..charE )
  38.             else
  39.                local value =  ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
  40.                file:write(  charS..value..","..charE )
  41.             end
  42.          end
  43.       end
  44.       for i,v in pairs( t ) do
  45.        
  46.          if (not thandled[i]) and type( v ) ~= "userdata" then
  47.            
  48.             if type( i ) == "table" then
  49.                if not lookup[i] then
  50.                   table.insert( tables,i )
  51.                   lookup[i] = #tables
  52.                end
  53.                file:write( charS.."[{"..lookup[i].."}]=" )
  54.             else
  55.                local index = ( type( i ) == "string" and "["..exportstring( i ).."]" ) or string.format( "[%d]",i )
  56.                file:write( charS..index.."=" )
  57.             end
  58.          
  59.             if type( v ) == "table" then
  60.                if not lookup[v] then
  61.                   table.insert( tables,v )
  62.                   lookup[v] = #tables
  63.                end
  64.                file:write( "{"..lookup[v].."},"..charE )
  65.             elseif type( v ) == "function" then
  66.                file:write( "loadstring("..exportstring(string.dump( v )).."),"..charE )
  67.             else
  68.                local value =  ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
  69.                file:write( value..","..charE )
  70.             end
  71.          end
  72.       end
  73.       file:write( "},"..charE )
  74.    end
  75.    file:write( "}" )
  76.  
  77.    if not filename then
  78.      
  79.       return file.str.."--|"
  80.    
  81.    elseif filename == true or filename == 1 then
  82.       file:seek ( "set" )
  83.  
  84.       return file:read( "*a" ).."--|"
  85.    
  86.    else
  87.       file:close()
  88.       return 1
  89.    end
  90. end
  91.  
  92. --// The Load Function
  93. function table.load( sfile )
  94.    
  95.    if string.sub( sfile,-3,-1 ) == "" then
  96.       tables,err = loadstring( sfile )
  97.    else
  98.       tables,err = loadfile( sfile )
  99.    end
  100.    if err then return _,err
  101.    end
  102.    tables = tables()
  103.    for idx = 1,#tables do
  104.       local tolinkv,tolinki = {},{}
  105.       for i,v in pairs( tables[idx] ) do
  106.          if type( v ) == "table" and tables[v[1]] then
  107.             table.insert( tolinkv,{ i,tables[v[1]] } )
  108.          end
  109.          if type( i ) == "table" and tables[i[1]] then
  110.             table.insert( tolinki,{ i,tables[i[1]] } )
  111.          end
  112.       end
  113.      
  114.       for _,v in ipairs( tolinkv ) do
  115.          tables[idx][v[1]] = v[2]
  116.       end
  117.      
  118.       for _,v in ipairs( tolinki ) do
  119.          tables[idx][v[2]],tables[idx][v[]] =  tables[idx][v[1]],nil
  120.       end
  121.    end
  122.    return tables[1]
  123. end
  124.  
  125. end
  126. --[[End of Load and Save Functions]]--
  127.  
  128. t = {}
  129.  
  130. local NPCID = 1
  131.  
  132. function Tablez_OnTalk(Unit, event, player)
  133. if (player:IsInCombat() == true) then
  134. player:SendAreaTriggerMessage("You are in combat!")
  135. player:GossipComplete()
  136. else
  137. Unit:GossipCreateMenu(100, player, 0)
  138. Unit:GossipMenuAddItem(0, "Teleport Menu's!", 50, 0)
  139. Unit:GossipMenuAddItem(1, "Set Coordinates", 51, 0)
  140. Unit:GossipMenuAddItem(8, "Reset Coordinates", 997, 1)
  141. Unit:GossipMenuAddItem(7, "Nevermind", 999, 0)
  142. Unit:GossipSendMenu(player)
  143. end
  144. end
  145.  
  146. function Tablez_OnSelect(Unit, event, player, id, intid, Code, pMisc)
  147. if type(t[tostring(player)]) ~= "table" then
  148. t[tostring(player)] = {}
  149. end
  150.  
  151. local plrtable = t[tostring(player)
  152.  
  153. if (intid == 5) then
  154. t[tostring(player)]["Mapid1"] = (tonumber(Code))
  155. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Mapid to "..Code.."!")
  156. Unit:GossipCreateMenu(6, player, 3)
  157. Unit:GossipMenuAddItem(4, "Set X for teleport 1", 10, 1)
  158. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  159. Unit:GossipSendMenu(player)
  160. end
  161.  
  162. if (intid == 6) then
  163. t[tostring(player)]["Mapid2"] = (tonumber(Code))
  164. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Mapid to "..Code.."!")
  165. Unit:GossipCreateMenu(100, player, 4)
  166. Unit:GossipMenuAddItem(4, "Set X for teleport 2", 11, 1)
  167. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  168. Unit:GossipSendMenu(player)
  169. end
  170.  
  171. if (intid == 7) then
  172. t[tostring(player)]["Mapid3"] = (tonumber(Code))
  173. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Mapid to "..Code.."!")
  174. Unit:GossipCreateMenu(100, player, 5)
  175. Unit:GossipMenuAddItem(4, "Set X for teleport 3", 12, 1)
  176. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  177. Unit:GossipSendMenu(player)
  178. end
  179.  
  180. if (intid == 8) then
  181. t[tostring(player)]["Mapid4"] = (tonumber(Code))
  182. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Mapid to "..Code.."!")
  183. Unit:GossipCreateMenu(100, player, 6)
  184. Unit:GossipMenuAddItem(4, "Set X for teleport 4", 13, 1)
  185. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  186. Unit:GossipSendMenu(player)
  187. end
  188.  
  189. if (intid == 9) then
  190. t[tostring(player)]["Mapid5"] = (tonumber(Code))
  191. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Mapid to "..Code.."!")
  192. Unit:GossipCreateMenu(100, player, 7)
  193. Unit:GossipMenuAddItem(4, "Set X for teleport 5", 14, 1)
  194. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  195. Unit:GossipSendMenu(player)
  196. end
  197.  
  198.  
  199. if (intid == 10) then
  200. t[tostring(player)]["x1"] = (tonumber(Code))
  201. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet X axis to "..Code.."!")
  202. Unit:GossipCreateMenu(100, player, 8)
  203. Unit:GossipMenuAddItem(4, "Set Y for teleport 1", 15, 1)
  204. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  205. Unit:GossipSendMenu(player)
  206. end
  207.  
  208. if (intid == 11) then
  209. t[tostring(player)]["x2"] = (tonumber(Code))
  210. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet X axis to "..Code.."!")
  211. Unit:GossipCreateMenu(100, player, 9)
  212. Unit:GossipMenuAddItem(4, "Set Y for teleport 2", 16, 1)
  213. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  214. Unit:GossipSendMenu(player)
  215. end
  216.  
  217. if (intid == 12) then
  218. t[tostring(player)]["x3"] = (tonumber(Code))
  219. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet X axis to "..Code.."!")
  220. Unit:GossipCreateMenu(100, player, 10)
  221. Unit:GossipMenuAddItem(4, "Set Y for teleport 3", 17, 1)
  222. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  223. Unit:GossipSendMenu(player)
  224. end
  225.  
  226. if (intid == 13) then
  227. t[tostring(player)]["x4"] = (tonumber(Code))
  228. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet X axis to "..Code.."!")
  229. Unit:GossipCreateMenu(100, player, 11)
  230. Unit:GossipMenuAddItem(4, "Set Y for teleport 4", 18, 1)
  231. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  232. Unit:GossipSendMenu(player)
  233. end
  234.  
  235. if (intid == 14) then
  236. t[tostring(player)]["x5"] = (tonumber(Code))
  237. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet X axis to "..Code.."!")
  238. Unit:GossipCreateMenu(100, player, 12)
  239. Unit:GossipMenuAddItem(4, "Set Y for teleport 5", 19, 1)
  240. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  241. Unit:GossipSendMenu(player)
  242. end
  243.  
  244. if (intid == 15) then
  245. t[tostring(player)]["y1"] = (tonumber(Code))
  246. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Y axis to "..Code.."!")
  247. Unit:GossipCreateMenu(100, player, 13)
  248. Unit:GossipMenuAddItem(4, "Set Z for teleport 1", 20, 1)
  249. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  250. Unit:GossipSendMenu(player)
  251. end
  252.  
  253. if (intid == 16) then
  254. t[tostring(player)]["y2"] = (tonumber(Code))
  255. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Y axis to "..Code.."!")
  256. Unit:GossipCreateMenu(100, player, 14)
  257. Unit:GossipMenuAddItem(4, "Set Z for teleport 2", 21, 1)
  258. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  259. Unit:GossipSendMenu(player)
  260. end
  261.  
  262. if (intid == 17) then
  263. t[tostring(player)]["y3"] = (tonumber(Code))
  264. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Y axis to "..Code.."!")
  265. Unit:GossipCreateMenu(100, player, 15)
  266. Unit:GossipMenuAddItem(4, "Set Z for teleport 3", 22, 1)
  267. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  268. Unit:GossipSendMenu(player)
  269. end
  270.  
  271. if (intid == 18) then
  272. t[tostring(player)]["y4"] = (tonumber(Code))
  273. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Y axis to "..Code.."!")
  274. Unit:GossipCreateMenu(100, player, 16)
  275. Unit:GossipMenuAddItem(4, "Set Z for teleport 4", 23, 1)
  276. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  277. Unit:GossipSendMenu(player)
  278. end
  279.  
  280. if (intid == 19) then
  281. t[tostring(player)]["y5"] = (tonumber(Code))
  282. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Y axis to "..Code.."!")
  283. Unit:GossipCreateMenu(100, player, 17)
  284. Unit:GossipMenuAddItem(4, "Set Z for teleport 5", 24, 1)
  285. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  286. Unit:GossipSendMenu(player)
  287. end
  288.  
  289. if (intid == 20) then
  290. t[tostring(player)]["z1"] = (tonumber(Code))
  291. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Z axis to "..Code.."!")
  292. player:GossipComplete()
  293. end
  294.  
  295. if (intid == 21) then
  296. t[tostring(player)]["z2"] = (tonumber(Code))
  297. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Z axis to "..Code.."!")
  298. player:GossipComplete()
  299. end
  300.  
  301. if (intid == 22) then
  302. t[tostring(player)]["z3"] = (tonumber(Code))
  303. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Z axis to "..Code.."!")
  304. player:GossipComplete()
  305. end
  306.  
  307. if (intid == 23) then
  308. t[tostring(player)]["z4"] = (tonumber(Code))
  309. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Z axis to "..Code.."!")
  310. player:GossipComplete()
  311. end
  312.  
  313. if (intid == 24) then
  314. t[tostring(player)]["z5"] = (tonumber(Code))
  315. player:SendAreaTriggerMessage("|cFFFF0000[Success!]:|rSet Z axis to "..Code.."!")
  316. player:GossipComplete()
  317. end
  318.  
  319. if (intid == 50) then
  320. Unit:GossipCreateMenu(100, player, 1)
  321. Unit:GossipMenuAddItem(4, "Teleport 1", 101, 0)
  322. Unit:GossipMenuAddItem(4, "Teleport 2", 102, 0)
  323. Unit:GossipMenuAddItem(4, "Teleport 3", 103, 0)
  324. Unit:GossipMenuAddItem(4, "Teleport 4", 104, 0)
  325. Unit:GossipMenuAddItem(4, "Teleport 5", 105, 0)
  326. Unit:GossipMenuAddItem(7, "Back", 998, 0)
  327. Unit:GossipSendMenu(player)
  328. end
  329.  
  330. if (intid == 51) then
  331. Unit:GossipCreateMenu(100, player, 18)
  332. Unit:GossipMenuAddItem(4, "Teleport Coords 1", 53, 0)
  333. Unit:GossipMenuAddItem(4, "Teleport Coords 2", 54, 0)
  334. Unit:GossipMenuAddItem(4, "Teleport Coords 3", 55, 0)
  335. Unit:GossipMenuAddItem(4, "Teleport Coords 4", 56, 0)
  336. Unit:GossipMenuAddItem(4, "Teleport Coords 5", 57, 0)
  337. Unit:GossipSendMenu(player)
  338. end
  339.  
  340. if (intid == 52) then
  341. Unit:GossipCreateMenu(100, player, 2)
  342. Unit:GossipMenuAddItem(4, "Mapid 1", 5, 1)
  343. Unit:GossipMenuAddItem(4, "Mapid 2", 6, 1)
  344. Unit:GossipMenuAddItem(4, "Mapid 3", 7, 1)
  345. Unit:GossipMenuAddItem(4, "Mapid 4", 8, 1)
  346. Unit:GossipMenuAddItem(4, "Mapid 5", 9, 1)
  347. Unit:GossipMenuAddItem(7, "Back", 998, 0)
  348. Unit:GossipSendMenu(player)
  349. end
  350.  
  351. if (intid == 53) then
  352. Unit:GossipCreateMenu(100, player, 19)
  353. Unit:GossipMenuAddItem(4, "Mapid 1", 5, 1)
  354. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  355. Unit:GossipSendMenu(player)
  356. end
  357.  
  358. if (intid == 54) then
  359. Unit:GossipCreateMenu(100, player, 20)
  360. Unit:GossipMenuAddItem(4, "Mapid 2", 6, 1)
  361. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  362. Unit:GossipSendMenu(player)
  363. end
  364.  
  365. if (intid == 55) then
  366. Unit:GossipCreateMenu(100, player, 21)
  367. Unit:GossipMenuAddItem(4, "Mapid 3", 7, 1)
  368. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  369. Unit:GossipSendMenu(player)
  370. end
  371.  
  372. if (intid == 56) then
  373. Unit:GossipCreateMenu(100, player, 22)
  374. Unit:GossipMenuAddItem(4, "Mapid 4", 8, 1)
  375. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  376. Unit:GossipSendMenu(player)
  377. end
  378.  
  379. if (intid == 57) then
  380. Unit:GossipCreateMenu(100, player, 23)
  381. Unit:GossipMenuAddItem(4, "Mapid 5", 9, 1)
  382. Unit:GossipMenuAddItem(4, "Nevermind", 999, 1)
  383. Unit:GossipSendMenu(player)
  384. end
  385.  
  386. if (intid == 997) and
  387. Code == "Yes" then
  388. t[tostring(player)] = nil
  389. player:SendAreaTriggerMessage("|cFFFF0000[Success!]: Coordinates Reset!")
  390. player:GossipComplete()
  391. elseif
  392. (intid == 11) and
  393. Code == "No" then
  394. player:GossipComplete()
  395. end
  396.  
  397. if (intid == 101) and
  398. plrtable["z1"] ~= nil then
  399. player:Teleport(plrtable["Mapid1"], plrtable["x1"], plrtable["y1"], plrtable["z1"])
  400. player:GossipComplete()
  401. elseif
  402. (intid == 101) and
  403. plrtable["z1"] == nil then
  404. player:SendAreaTriggerMessage("|cFFFF0000[Failure!]: Please insert all of the data in the fields")
  405. player:GossipComplete()
  406. end
  407.  
  408. if (intid == 102) and
  409. plrtable["z2"] ~= nil then
  410. player:Teleport(plrtable["Mapid2"], plrtable["x2"], plrtable["y2"], plrtable["z2"])
  411. player:GossipComplete()
  412. elseif
  413. (intid == 102) and
  414. plrtable["z2"] == nil then
  415. player:SendAreaTriggerMessage("|cFFFF0000[Failure!]: Please insert all of the data in the fields")
  416. player:GossipComplete()
  417. end
  418.  
  419. if (intid == 103) and
  420. plrtable["z3"] ~= nil then
  421. player:Teleport(plrtable["Mapid3"], plrtable["x3"], plrtable["y3"], plrtable["z3"])
  422. player:GossipComplete()
  423. elseif
  424. (intid == 103) and
  425. plrtable["z3"] == nil then
  426. player:SendAreaTriggerMessage("|cFFFF0000[Failure!]: Please insert all of the data in the fields")
  427. player:GossipComplete()
  428. end
  429.  
  430. if (intid == 104) and
  431. plrtable["z4"] ~= nil then
  432. player:Teleport(plrtable["Mapid4"], plrtable["x4"], plrtable["y4"], plrtable["z4"])
  433. player:GossipComplete()
  434. elseif
  435. (intid == 104) and
  436. plrtable["z4"] == nil then
  437. player:SendAreaTriggerMessage("|cFFFF0000[Failure!]: Please insert all of the data in the fields")
  438. player:GossipComplete()
  439. end
  440.  
  441. if (intid == 105) and
  442. plrtable["z5"] ~= nil then
  443. player:Teleport(plrtable["Mapid5"], plrtable["x5"], plrtable["y5"], plrtable["z5"])
  444. player:GossipComplete()
  445. elseif
  446. (intid == 105) and
  447. plrtable["z5"] == nil then
  448. player:SendAreaTriggerMessage("|cFFFF0000[Failure!]: Please insert all of the data in the fields")
  449. player:GossipComplete()
  450. end
  451.  
  452. if (intid == 998) then
  453. Unit:GossipCreateMenu(100, player, 0)
  454. Unit:GossipMenuAddItem(0, "Teleport Menu's!", 50, 0)
  455. Unit:GossipMenuAddItem(1, "Set Coordinates", 51, 0)
  456. Unit:GossipMenuAddItem(8, "Reset Coordinates", 997, 1)
  457. Unit:GossipMenuAddItem(7, "Nevermind", 999, 0)
  458. Unit:GossipSendMenu(player)
  459. end
  460.  
  461. if (intid == 99) then
  462. player:GossipComplete()
  463. end
  464. end
  465.  
  466.  
  467.  
  468. RegisterUnitGossipEvent(NPCID, 4, "Table_OnTalk")
  469. RegisterUnitGossipEvent(NPCID, 5, "Table_OnSelect")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement