sqpp15

Advanced Roleplay

Mar 30th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 120.40 KB | None | 0 0
  1. ----------------------------------------
  2. --**  RolePlay lua by TheAnonymous  **--
  3. ----------------------------------------
  4.  
  5.  
  6. -------------------
  7. ---  HOOKS  -------
  8. -------------------
  9. addhook("join","AM.PlayerJoin")
  10. addhook("leave","AM.PlayerLeave")
  11. addhook("always","AM.BotCheck")
  12. addhook("mapchange","AM.GeneralSave")
  13. addhook("minute", "AddPlaytime")
  14. addhook("second", "everySecond")
  15. addhook("movetile", "onMovetile")
  16. addhook("attack", "onAttack")
  17. addhook("team", "onTeam")
  18. addhook("die", "onDie")
  19. addhook("leave", "onLeave")
  20. addhook("spawn", "onSpawn")
  21. addhook("hit", "onHit")
  22. addhook("join", "onJoin")
  23. addhook("serveraction", "onServeraction")
  24. addhook("walkover", "onWalkover")
  25. addhook("startround_prespawn", "onPreStartround")
  26. addhook("use","PMu")
  27. addhook("use","PMu2")
  28. addhook("menu", "also")
  29. addhook("menu", "lbent_menu")
  30. addhook("minute", "paydayMinute")
  31. addhook("say","unimenushell");
  32. addhook("menu","unimenuhook")
  33. addhook("objectkill", "onObjectkill");
  34. addhook("buildattempt", "onBuildattempt");
  35. addhook("use","jobUse")
  36. addhook("use","doctorwho.tardis.plyenter")
  37. addhook("menu","doctorwho.ssmenu")
  38. addhook("hit","doctorwho.hitrender")
  39. addhook("say","doctorwho.sayprocess")
  40. addhook("die","doctorwho.abortregen")
  41. addhook("ms100","doctorwho.ms100")
  42. addhook("serveraction","doctorwho.sonicscrewdriver")
  43. addhook("serveraction","doctorwho.tardiscontrols")
  44. addhook("second","doctorwho.second")
  45. addhook("movetile","doctorwho.movetile")
  46. addhook('join', 'AA_join')
  47. addhook('leave', 'AA_leave')
  48. addhook('spawn', 'AA_spawn')
  49. addhook("movetile", "HookMoveTile")
  50. addhook("use", "HookUse")
  51. addhook('say','_sayHook',1)
  52. addhook('collect', 'WW_collectHook')
  53. addhook('drop', 'WW_dropHook')
  54. addhook('select', 'WW_selectHook')
  55. addhook('spawn', 'WW_spawnHook')
  56. addhook('die', 'clearSlots')
  57. addhook("use", "enterCar")
  58. addhook("ms100", "particleCars")
  59. addhook("always", "updateCars")
  60. addhook("drop", "carMenu")
  61. addhook("attack", "destroyAttack");
  62. addhook("always", "moveTrains")
  63. addhook("use", "enterTrain")
  64. addhook("use","pkl.HookUse")
  65. addhook("menu", "pkl.HookMenu")
  66. addhook("movetile", "houseCheck")
  67. addhook("movetile", "House_MoveTile")
  68. addhook("use", "HouseInfo")
  69. addhook("startround","advertise")
  70. addhook("startround","advertise2")
  71. ----------------------------
  72. ---  ADMINS & OTHERS  ------
  73. ----------------------------
  74. AM = {}
  75. mod_path = "sys/lua/"
  76. mod_name = "CS2DHungary Roleplay"
  77. mod_version = "0.1"
  78.  
  79. package.cpath = package.cpath..";./"..mod_path.."res/?.dll;/lib/?.dll"
  80.  
  81. dofile(mod_path.."os.lua")
  82. if string.find(os.name(), "windows") then
  83.     function LoadDLL(path,func,name)
  84.         local f, e = package.loadlib(path, func)
  85.         if f and not e then
  86.             f()
  87.             print("Loaded "..name.." DLL")
  88.             return true
  89.         else
  90.             print("Failed to load "..name.." DLL: "..e)
  91.         end
  92.     end
  93.  
  94.     if LoadDLL(mod_path.."res/stream.dll", "init", "stream functions") then
  95.         dofile(mod_path.."stream_functions_dll.lua")
  96.     else
  97.         dofile(mod_path.."stream_functions.lua")
  98.     end
  99.     require("ex")
  100. else
  101.     dofile(mod_path.."stream_functions.lua")
  102. end
  103. dofile(mod_path.."data.lua")
  104.  
  105. -- Important addons
  106. dofile(mod_path.."addons/lua_table.lua")
  107. dofile(mod_path.."addons/lua_math.lua")
  108. dofile(mod_path.."addons/lua_string.lua")
  109. dofile(mod_path.."addons/lua_funcs.lua")
  110. dofile(mod_path.."addons/lua_error.lua")
  111.  
  112. function SetTempAddonTable(t)
  113.     local mt = {}
  114.     function mt.__newindex(g,k,v)
  115.         t[k] = CopyObject(v)
  116.     end
  117.  
  118.     setmetatable(_G, mt)
  119. end
  120.  
  121. function RequireTempAddon(name)
  122.     local f = io.open(mod_path.."addons/"..name..".lua")
  123.     if f then
  124.         f:close()
  125.  
  126.         local t = {}
  127.         SetTempAddonTable(t)
  128.         ProtectedCall(dofile, mod_path.."addons/"..name..".lua")
  129.  
  130.         setmetatable(_G, nil)
  131.         return t
  132.     end
  133. end
  134.  
  135. function SetAddonTable(t)
  136.     local mt = {}
  137.     function mt.__newindex(g,k,v)
  138.         t[k] = v
  139.  
  140.         if k ~= "Init" then
  141.             setmetatable(_G, nil)
  142.             _G[k] = v
  143.  
  144.             setmetatable(_G, mt)
  145.         end
  146.     end
  147.  
  148.     setmetatable(_G, mt)
  149. end
  150.  
  151. ADDON_INSTALLED = {}
  152. function RequireAddon(name)
  153.     local f = io.open(mod_path.."addons/"..name..".lua")
  154.     if f then
  155.         f:close()
  156.  
  157.         local t = {}
  158.         SetAddonTable(t)
  159.         ProtectedCall(dofile, mod_path.."addons/"..name..".lua")
  160.  
  161.         ADDON_INSTALLED[name] = true
  162.  
  163.         setmetatable(_G, nil)
  164.         return t
  165.     end
  166. end
  167.  
  168. function ScanAddon(a,keyword)
  169.     local f = io.open(mod_path.."addons/"..a..".lua")
  170.     if f then
  171.         local code = f:read("*a"); f:close()
  172.         if code:find(keyword) then
  173.             msg("Found "..keyword.." in addon: "..a)
  174.         end
  175.         return true
  176.     end
  177. end
  178.  
  179. function LoadAddons()
  180.     print(string.char(169).."000255000Loading server addons")
  181.     local f = io.open(mod_path.."addon_config.txt", "r")
  182.     local temp_addon = {}
  183.     if f then
  184.         for lines in f:lines() do
  185.             if string.byte(lines, string.len(lines)) == 13 then
  186.                 lines = string.sub(lines, 1, string.len(lines)-1)
  187.             end
  188.  
  189.             if string.len(lines) > 0 and string.sub(lines, 1, 2) ~= "//" then
  190.                 temp_addon[lines] = RequireAddon(lines)
  191.                 if temp_addon[lines] then
  192.                     print(string.char(169).."000255000Loading addon "..lines)
  193.                 else
  194.                     print(string.char(169).."255000000Failed to load addon "..lines)
  195.                 end
  196.             end
  197.         end
  198.         f:close()
  199.     end
  200.  
  201.     for k, t in pairs(temp_addon) do
  202.         if t.Init then
  203.             t.Init()
  204.         end
  205.     end
  206.     LoadAddons = nil
  207. end; LoadAddons()
  208.  
  209. function AM.ReloadLogin(id)
  210.     DeleteUSER(id)
  211.     DeleteUSGN(player(id,"usgn"))
  212.  
  213.     ReloadUSER(id)
  214.     ReloadTEMP(id)
  215.     LoadIPData(player(id,"ip"))
  216. end
  217.  
  218.  
  219. function AM.PlayerJoin(id)
  220.     while string.sub(player(id,"name"), 1, 1) == "(" do
  221.         parse('setname '..id..' "'..string.sub(player(id,"name"), 2)..'" 1')
  222.     end
  223.     AM.ReloadLogin(id)
  224. end
  225.  
  226.  
  227. function AM.PlayerLeave(id)
  228.     SaveUSER(id)
  229.     SaveIPData(player(id,"ip"))
  230.  
  231.     DeleteUSER(id)
  232.     DeleteUSGN(player(id,"usgn"))
  233. end
  234.  
  235. function bot_list()
  236.     local l = {}
  237.     for _, id in pairs(player(0,"table")) do
  238.         if player(id, "bot") then
  239.             table.insert(l, id)
  240.         end
  241.     end
  242.     return l
  243. end
  244.  
  245. bot_init = {}
  246.  
  247. function AM.BotCheck()
  248.     local bl = bot_list()
  249.     if last_bots then
  250.         for _, id in pairs(last_bots) do
  251.             if player(id,"exists") then
  252.                 if not bot_init[id] then
  253.                     AM.PlayerJoin(id)
  254.                     bot_init[id] = true
  255.                 end
  256.             else
  257.                 AM.PlayerLeave(id)
  258.                 last_bots[id] = nil
  259.                 bot_init[id] = nil
  260.             end
  261.         end
  262.     end
  263.  
  264.     last_bots = bl
  265. end
  266.  
  267.  
  268. function AM.GeneralSave()
  269.     for _, id in pairs(player(0,"table")) do
  270.         SaveUSER(id)
  271.     end
  272.     SaveServer()
  273. end
  274.  
  275. ---------------------------
  276. --  LIBS AND SOME STUFF  --
  277. ---------------------------
  278. ----------------------------
  279. USGN_DATAPATH = mod_path.."data/"
  280.  
  281. USGN = {}
  282. USER = {}
  283. USER_DATA = {}
  284.  
  285. -- Data metatable
  286. DATA_META = {}
  287. function DATA_META.__index(t,k)
  288.     return t["data"][k]
  289. end
  290.  
  291. function DATA_META.__newindex(t,k,v)
  292.     t["data"][k] = v
  293. end
  294.  
  295. -- User
  296. USER_DATA = {}
  297. USER_META = {}
  298. USER = {}
  299.  
  300. function USER_META.__index(t,id)
  301.     if type(id) == "number" and id > 0 then
  302.         if not USER_DATA[id] then
  303.             if player(id, "usgn") > 0 then
  304.                 USER_DATA[id] = USGN[player(id,"usgn")]
  305.             end
  306.  
  307.             if not USER_DATA[id] then
  308.                 USER_DATA[id] = {}
  309.                 USER_DATA[id].data = table.copy(USGN_DEFAULTDATA or {})
  310.             end
  311.             setmetatable(USER_DATA[id], DATA_META)
  312.         elseif USGN_DATA[player(id,"usgn")] and USER_DATA[id] ~= USGN_DATA[player(id,"usgn")] then
  313.             USER_DATA[id] = USGN_DATA[player(id,"usgn")]
  314.         end
  315.         return USER_DATA[id]
  316.     end
  317. end
  318.  
  319. function USER_META.__newindex(t,k,v)
  320.     USER_DATA[k] = v
  321. end
  322.  
  323. -- USGN
  324. USGN_DEFAULTDATA = {}
  325.  
  326. USGN = {}
  327. USGN_DATA = {}
  328. USGN_META = {}
  329.  
  330. function USGN_META.__index(t,id)
  331.     if not id then return nil end
  332.     if USGN_DATA[id] then return USGN_DATA[id] end
  333.     if type(id) == "number" and id > 0 then
  334.         return LoadUSGN(id)
  335.     end
  336. end
  337.  
  338. function USGNDataExists(u)
  339.     if not u then return nil end
  340.     return FileExists(USGN_DATAPATH..u..".txt") or USGN_DATA[u] ~= nil
  341. end
  342.  
  343. function LoadUSGN(id)
  344.     if id > 0 then
  345.         local data = LoadData(USGN_DATAPATH..id..".txt")
  346.         if data then
  347.             USGN_DATA[id] = data
  348.             table.safecopy(USGN_DEFAULTDATA, data)
  349.         else
  350.             USGN_DATA[id] = CreateData()
  351.             USGN_DATA[id]["data"] = table.copy(USGN_DEFAULTDATA or {})
  352.         end
  353.         return data
  354.     end
  355. end
  356.  
  357. function SaveUSGN(id)
  358.     if id > 0 then
  359.         local t = USGN_DATA[id]
  360.         if t then
  361.             return SaveDataFile(t, USGN_DATAPATH..id..".txt")
  362.         end
  363.     end
  364. end
  365.  
  366. -- USER TEMP
  367. USERTEMP_DEFAULTDATA = {}
  368.  
  369. USERTEMP = {}
  370. USERTEMP_DATA = {}
  371. USERTEMP_META = {}
  372.  
  373. function USERTEMP_META.__index(t,id)
  374.     if not USERTEMP_DATA[id] then
  375.         USERTEMP_DATA[id] = CreateData()
  376.         USERTEMP_DATA[id] = table.copy(USERTEMP_DEFAULTDATA) or {}
  377.     end
  378.     return USERTEMP_DATA[id]
  379. end
  380.  
  381. -- IP Data
  382. USERIP_DEFAULTDATA = {}
  383.  
  384. USERIP = {}
  385. USERIP_DATA = {}
  386. USERIP_META = {}
  387.  
  388. function USERIP_META.__index(t,ip)
  389.     if not ip then return nil end
  390.     if not USERIP_DATA[ip] then LoadIPData(ip) end
  391.     return USERIP_DATA[ip]
  392. end
  393.  
  394. function IPDataExists(ip)
  395.     return FileExists(mod_path.."data/ip_"..ip..".txt") or USERIP_DATA[ip] ~= nil
  396. end
  397.  
  398. function LoadIPData(ip)
  399.     if not ip then return nil end
  400.     local t = CreateData()
  401.     local stream = ReadStream(mod_path.."data/ip_"..ip..".txt")
  402.     t.data = table.copy(USERIP_DEFAULTDATA or {})
  403.  
  404.     if stream then
  405.         local data_name, data_value = ReadData(stream)
  406.         while data_name and data_value do
  407.             t.data[data_name] = data_value
  408.             if not Eof(stream) then
  409.                 data_name, data_value = ReadData(stream)
  410.             else
  411.                 break
  412.             end
  413.         end
  414.  
  415.         CloseStream(stream)
  416.     end
  417.  
  418.     USERIP_DATA[ip] = t
  419.     return t
  420. end
  421.  
  422. function SaveIPData(ip)
  423.     local t = USERIP[ip]
  424.     if not t then return end
  425.     if table.size(t.data) == 0 then
  426.         return os.remove(mod_path.."data/ip_"..ip..".txt")
  427.     end
  428.  
  429.     local stream = WriteStream(mod_path.."data/ip_"..ip..".txt")
  430.     if stream then
  431.         for k, v in pairs(t.data) do
  432.             SaveData(stream, k, v)
  433.         end
  434.         CloseStream(stream)
  435.         return true
  436.     end
  437. end
  438.  
  439. -- Data functions
  440. function CreateData()
  441.     local t = {data = {}}
  442.     setmetatable(t, DATA_META)
  443.     return t
  444. end
  445.  
  446. function LoadData(file)
  447.     local t = {data = {}}
  448.     local stream = ReadStream(file)
  449.  
  450.     if stream then
  451.         local data_name, data_value = ReadData(stream)
  452.         while data_name and data_value  do
  453.             t.data[data_name] = data_value
  454.             if not Eof(stream) then
  455.                 data_name, data_value = ReadData(stream)
  456.             else
  457.                 break
  458.             end
  459.         end
  460.         CloseStream(stream)
  461.  
  462.         setmetatable(t, DATA_META)
  463.         return t
  464.     end
  465. end
  466.  
  467. function SaveDataFile(t, file)
  468.     if table.size(t.data) == 0 then return end
  469.     local stream = WriteStream(file)
  470.     if stream then
  471.         for k, v in pairs(t.data) do
  472.             SaveData(stream, k, v)
  473.         end
  474.         CloseStream(stream)
  475.         return true
  476.     end
  477. end
  478.  
  479. function SaveUSER(id)
  480.     if player(id,"usgn") > 0 then
  481.         SaveUSGN(player(id, "usgn"))
  482.     end
  483. end
  484.  
  485. setmetatable(USGN, USGN_META)
  486. setmetatable(USER, USER_META)
  487. setmetatable(USERTEMP, USERTEMP_META)
  488. setmetatable(USERIP, USERIP_META)
  489.  
  490. function ReadData(s)
  491.     local key_type = ReadByte(s)
  492.     local data_name
  493.     if key_type == 110 then
  494.         data_name = tonumber(ReadLine(s))
  495.     elseif key_type == 115 then
  496.         data_name = ReadLine(s)
  497.     end
  498.  
  499.     local data_type = ReadString(s, 2)
  500.     local data_value
  501.     if data_type == "nu" then
  502.         data_value = tonumber(ReadLong(s))
  503.     elseif data_type == "st" then
  504.         data_value = ReadLine(s)
  505.     elseif data_type == "ta" then
  506.         data_value = {}
  507.  
  508.         local size = ReadInt(s)
  509.         for i = 1, size do
  510.             local dn, dv = ReadData(s)
  511.             data_value[dn] = dv
  512.         end
  513.     elseif data_type == "fu" then
  514.         local size = ReadInt(s)
  515.         local funcscript = ReadString(s, size)
  516.         data_value = loadstring(funcscript)
  517.     elseif data_type == "bo" or data_type == "ni" then
  518.         local v = tonumber(ReadByte(s))
  519.         if v == 1 then
  520.             data_value = true
  521.         elseif v == 0 then
  522.             data_value = false
  523.         end
  524.     end
  525.  
  526.     return data_name, data_value
  527. end
  528.  
  529. function SaveData(s,data_name,data_value)
  530.     local key_type = string.byte(type(data_name), 1)
  531.     WriteByte(s, key_type)
  532.     WriteLine(s, data_name)
  533.  
  534.     local data_type = string.sub(type(data_value), 1, 2)
  535.     WriteString(s, data_type)
  536.  
  537.     if data_type == "nu" then
  538.         WriteLong(s, data_value)
  539.     elseif data_type == "st" then
  540.         WriteLine(s, data_value)
  541.     elseif data_type == "ta" then
  542.         WriteInt(s, table.size(data_value))
  543.         for k, v in pairs(data_value) do
  544.             SaveData(s, k, v)
  545.         end
  546.     elseif data_type == "fu" then
  547.         local funcscript = string.dump(data_value)
  548.         WriteInt(s, string.len(funcscript))
  549.         WriteString(s, funcscript)
  550.     elseif data_type == "bo" or data_type == "ni" then
  551.         if data_value then
  552.             WriteByte(s, 1)
  553.         elseif not data_value then
  554.             WriteByte(s, 0)
  555.         end
  556.     end
  557. end
  558.  
  559. function ReloadUSER(id)
  560.     USER_DATA[id] = nil
  561.     return USER[id]
  562. end
  563.  
  564. function ReloadUSGN(id)
  565.     USGN[id] = nil
  566.     return USGN[id]
  567. end
  568.  
  569. function ReloadTEMP(id)
  570.     USERTEMP_DATA[id] = nil
  571.     return USERTEMP[id]
  572. end
  573.  
  574. function DeleteUSGN(u)
  575.     USGN[u] = nil
  576. end
  577.  
  578. function DeleteUSER(id)
  579.     USER[id] = nil
  580. end
  581.  
  582. function table.copy(t)
  583.     local copy = {}
  584.     for k, v in pairs(t) do
  585.         if type(v) == "table" then
  586.             copy[k] = table.copy(v)
  587.         elseif type(v) == "function" then
  588.             copy[k] = loadstring(string.dump(v))
  589.         else
  590.             copy[k] = v
  591.         end
  592.     end
  593.     return copy
  594. end
  595.  
  596. function table.size(t)
  597.     local n = 0
  598.     for k, v in pairs(t) do
  599.         n = n + 1
  600.     end
  601.     return  n
  602. end
  603.  
  604. ------------------------------
  605. ------- FOOD&DRINK SYS -------
  606. ------------------------------
  607. function BuyFood(id, food, amount)
  608.     if PayMoney(id, amount, true) then
  609.         unimenu(id, true, pmenu[id], 1);
  610.         DecHunger(id, food)
  611.     end
  612. end
  613.  
  614. function BuyWater(id, water, amount)
  615.     if PayMoney(id, amount, true) then
  616.         unimenu(id, true, pmenu[id], 1);
  617.         DecThirst(id, water)
  618.     end
  619. end
  620.  
  621. ------------------------------
  622. -------- SAVE SYSTEM ---------
  623. ------------------------------
  624. function SavePlayer(id)
  625.     local usgn = GetUsgn(id);
  626.     if usgn > 0 then
  627.         file = io.open(path .. "saves/" .. usgn .. ".txt", "w");
  628.         if file then
  629.             file:write(tostring(Player[id].money .. "\n"));
  630.             file:write(tostring(BoolToInt(Player[id].license) .. "\n"));
  631.             file:write(tostring(Player[id].playtime .. "\n"));
  632.             file:write(tostring(Player[id].job .. "\n"));
  633.             local _, i;
  634.             file:write(tostring(#Player[id].inv .. "\n"));
  635.             for _, i in pairs(Player[id].inv) do
  636.                 file:write(tostring(i .. "\n"));
  637.             end
  638.             io.close(file);
  639.             return true;
  640.         else
  641.            
  642.             return false;
  643.         end
  644.     end
  645. end
  646.  
  647. ----------------------
  648. ---- LOAD PLAYER -----
  649. ----------------------
  650.  
  651. function LoadPlayer(id)
  652.     local usgn = GetUsgn(id);
  653.     if usgn > 0 then
  654.         file = io.open(path .. "saves/" .. usgn .. ".txt", "r");
  655.         if file then
  656.             Player[id].money = tonumber(file:read());
  657.             Player[id].license = IntToBool(file:read());
  658.             Player[id].playtime = tonumber(file:read());
  659.             Player[id].job = tostring(file:read());
  660.             if Player[id].money == nil then Player[id].money = 0 end;
  661.             if Player[id].license == nil then Player[id].license = false end;
  662.             if Player[id].playtime == nil then Player[id].playtime = 0 end;
  663.             if Player[id].job == nil then Player[id].job = "None" end;
  664.             local i,inv_len,t;
  665.             t = {};
  666.             inv_len = tonumber(file:read());
  667.             for i = 1, inv_len do
  668.                 table.insert(t, tonumber(file:read()));
  669.             end
  670.             Player[id].inv = t;
  671.             io.close(file);
  672.             return true;
  673.         else
  674.             return false;
  675.         end
  676.     end
  677. end
  678.  
  679. function BoolToInt(bool)
  680.     if bool == true then return 1 else return 0 end;
  681. end
  682.  
  683. function IntToBool(int)
  684.     if tonumber(int) == 0 then return false else return true end;
  685. end
  686.  
  687. ----------------------------------
  688. --**        PLAYER THINGS     **--
  689. ----------------------------------
  690. Player = {};
  691.  
  692. nSecond = 0;
  693.  
  694.  
  695. function AddPlaytime()
  696.     local _, i;
  697.     for _, i in pairs(player(0, "table")) do
  698.         if not Player[i].joined then
  699.             Player[i].playtime = Player[i].playtime +  1;
  700.         end
  701.     end
  702. end
  703.  
  704.  
  705. function everySecond()
  706.     nSecond = nSecond + 1;
  707.     local _, i;
  708.     for _, i in pairs(player(0, "table")) do
  709.         if player(i, "health") > 0 then
  710.             AddHunger(i, 0.0005);
  711.             AddThirst(i, 0.0001);
  712.             UpdateHud(i);
  713.            
  714.             if Player[i].hunger > 75 then
  715.                 if player(i, "health") - 1 <= 0 and nSecond % 5 == 0  then
  716.                     KillHunger(i);
  717.                 elseif nSecond % 5 == 0 then
  718.                     parse("sethealth ".. i .." ".. player(i, "health") - 1);
  719.                 end
  720.             elseif Player[i].hunger < 10 then
  721.                 if nSecond % 3 == 0 then
  722.                     if player(i, "health") < player(i, "maxhealth") then
  723.                         parse("sethealth ".. i .." ".. player(i, "health") + 1);
  724.                     end
  725.                 end
  726.             end
  727.            
  728.             if Player[i].thirst > 75 then
  729.                 if player(i, "health") - 1 <= 0 and nSecond % 2 == 0 then
  730.                     KillThirst(i);
  731.                 elseif nSecond % 2 == 0 then
  732.                     parse("sethealth ".. i .." ".. player(i, "health") - 1);
  733.                 end
  734.             end
  735.         end
  736.     end
  737.     if nSecond >= 10 then nSecond = 0 end;
  738. end
  739.  
  740.  
  741. function onMovetile(id)
  742.     if not Player[id].carowner and not Player[id].car and Player[id].train == 0 then
  743.         AddHunger(id, 0.0005);
  744.         AddThirst(id, 0.001);
  745.     end
  746. end
  747.  
  748.  
  749. function onAttack(id, mode)
  750.     AddHunger(id, 0.002);
  751.     AddThirst(id, 0.001);
  752.    
  753.     if mode == 2 then
  754.         AddHunger(id, 0.001);
  755.         AddThirst(id, 0.003);
  756.         UpdateHud(i);
  757.     end
  758. end
  759.  
  760.  
  761. function onTeam(id, team)
  762.     if Player[id].joined then
  763.        
  764.         if GetUsgn(id) > 0 then
  765.             local _, i;
  766.             for _, i in pairs(player(0, "table")) do
  767.                 if i > id or i < id then
  768.                     if GetUsgn(id) == GetUsgn(i) then
  769.                         msg2(id, "©255000000Double U.S.G.N login detected (".. player(i, "name") ..")!");
  770.                         return 1;
  771.                     end
  772.                 end
  773.             end
  774.         end
  775.        
  776.         Player[id].joined = false;
  777.         Player[id].money = 0;
  778.         Player[id].health = 0;
  779.         Player[id].hunger = 0;
  780.         Player[id].thirst = 0;
  781.         Player[id].group = "player";
  782.         Player[id].hud = 0;
  783.         Player[id].train = 0;
  784.         Player[id].speed = 0;
  785.         Player[id].carstart = false;
  786.         Player[id].cargear = 0;
  787.         Player[id].license = false;
  788.         Player[id].lastx = 0;
  789.         Player[id].lasty = 0;
  790.         Player[id].playtime = 0;
  791.         Player[id].job = "None";
  792.         Player[id].built = {};
  793.         Player[id].cars = {};
  794.         Player[id].inv = {};
  795.        
  796.         if LoadPlayer(id) then
  797.             msg2(id, "©000255000Succefully loaded your U.S.G.N save!");
  798.         end
  799.        
  800.         if team == 2 then
  801.             if Player[id].playtime <= 1440 then
  802.                 msg2(id, "©255000000You didn't play 24 hours on this server yet!");
  803.                 parse("maket " .. id);
  804.                 return 1;
  805.             else
  806.                 Player[id].job = "Police Man";
  807.                 msg2(id, "©255128064You're now Police Man!");
  808.                 return 0;
  809.             end
  810.         end
  811.  
  812.         UpdateHud(id);
  813.     elseif team == 2 then
  814.         if Player[id].playtime <= 1440 then
  815.             Player[id].job = "None";
  816.             msg2(id, "©255000000You didn't play 24 hours on this server yet!");
  817.             parse("maket " .. id);
  818.             return 1;
  819.         else
  820.             Player[id].job = "Police Man";
  821.             msg2(id, "©255128064You're now Police Man!");
  822.             return 0;
  823.         end
  824.     end
  825. end
  826.  
  827.  
  828.  
  829. function onDie(id)
  830.     if Player[id].car then
  831.         local _, i;
  832.         for _, i in pairs(Player[id].car.players) do
  833.             if i == id then
  834.                 table.remove(Player[id].car.players, _);
  835.                 break;
  836.             end
  837.         end
  838.         Player[id].car = nil;
  839.     end
  840.     if Player[id].carowner then
  841.         Player[id].carowner.owner = 0;
  842.         Player[id].carowner = nil;
  843.     end
  844. end
  845.  
  846. function getPos(str)
  847.     local x1, x2, f;
  848.     f = string.find(str, "|");
  849.     x1 = string.sub(str, 0, f - 1);
  850.     x2 = string.sub(str, f + 1);
  851.     return tonumber(x1), tonumber(x2);
  852. end
  853.  
  854.  
  855. function onLeave(id)
  856.     if Player[id].joined == true then return 0 end;
  857.     local _, i;
  858.     if Player[id].car then
  859.         for _, i in pairs(Player[id].car.players) do
  860.             if i == id then
  861.                 table.remove(Player[id].car.players, _);
  862.                 break;
  863.             end
  864.         end
  865.     end
  866.     for _, i in pairs(Player[id].cars) do
  867.         local car = cars[i];
  868.         RemoveCar(car);
  869.     end
  870.     if Player[id].carowner then
  871.         Player[id].carowner.owner = 0;
  872.     end
  873.     if Player[id].house then
  874.         Player[id].house.owner = 0;
  875.         Player[id].house.allowed = {};
  876.         Player[id].house = nil;
  877.     end
  878.     local x, y;
  879.     for _, i in pairs(Player[id].built) do
  880.         x, y = getPos(_);
  881.         if map_obj[x][y].gfx > 0 then
  882.             freeimage(map_obj[x][y].gfx);
  883.             map_obj[x][y].parent = nil;
  884.         end
  885.     end
  886.     SavePlayer(id);
  887. end
  888.  
  889.  
  890. function onSpawn(id)
  891.     if Player[id].hud > 0 then
  892.         freeimage(Player[id].hud);
  893.     end
  894.    
  895.     Player[id].hud = image("gfx/MafiaRP/hud2.png", hud_x + (115 / 2), hud_y + (200 / 2), 2, id);
  896.     Player[id].hunger = 0;
  897.     Player[id].thirst = 0;
  898.     Player[id].job = "None";
  899.    
  900.     UpdateHud(id);
  901. end
  902.  
  903.  
  904. function onHit(id, source, weapon, hpdmg, apdmg, rawdmg)
  905.     if Player[id].train > 0 then return 1 end;
  906.     if source > 0 then if Player[source].train > 0 then return 1 end end;
  907.     if Player[id].car then return 1 end;
  908.     if Player[id].carowner then
  909.         if source > 0 then
  910.             if Player[source].car then
  911.                 if Player[source].car.cid == Player[id].carowner.cid then return 1 end;
  912.             elseif Player[source].carowner then
  913.                 if Player[source].carowner.cid == Player[id].carowner.cid then return 1 end;
  914.             end
  915.         end
  916.         Player[id].carowner.health = Player[id].carowner.health - rawdmg;
  917.         checkCarHealth(Player[id].carowner);
  918.         UpdateHud(id);
  919.         return 1;
  920.     end
  921. end
  922.  
  923.  
  924. function onJoin(id)
  925.     Player[id] = {}
  926.     Player[id].joined = true;
  927. end
  928.  
  929.  
  930. function onServeraction(id, key)
  931.     if Player[id].carowner then
  932.         if key == 1 then
  933.             if Player[id].carstart then
  934.                 Player[id].cargear = Player[id].cargear - 1;
  935.                 if Player[id].cargear < -1 then Player[id].cargear = -1 end;
  936.                 UpdateHud(id);
  937.             end
  938.         elseif key == 2 then
  939.             if Player[id].carstart then
  940.                 Player[id].cargear = Player[id].cargear + 1;
  941.                 if Player[id].cargear > car_types[Player[id].carowner.type].speed then Player[id].cargear = car_types[Player[id].carowner.type].speed end;
  942.                 UpdateHud(id);
  943.             end
  944.         elseif key == 3 then
  945.             if Player[id].carstart then
  946.                 Player[id].carstart = false;
  947.                 Player[id].cargear = 0;
  948.                 UpdateHud(id);
  949.             else
  950.                 Player[id].carstart = true;
  951.                 UpdateHud(id);
  952.             end
  953.         end
  954.     else
  955.         if key == 1 then
  956.             unimenu(id, true, 1, 1);
  957.         elseif key == 2 then
  958.             BuildingMenu(id);
  959.         elseif key == 3 then
  960.             showInv(id);
  961.         end
  962.     end
  963. end
  964.  
  965. function GetUsgn(id)
  966.     if player(id, "bot") then return 0 end;
  967.     return player(id, "usgn");
  968. end
  969.  
  970. function AddHunger(id, amount)
  971.     if player(id, "health") > 0 then
  972.         Player[id].hunger = Player[id].hunger + amount;
  973.         if Player[id].hunger >= 100 then
  974.             Player[id].hunger = 100;
  975.             KillHunger(id);
  976.         end
  977.     end
  978. end
  979.  
  980. function AddThirst(id, amount)
  981.     if player(id, "health") > 0 then
  982.         Player[id].thirst = Player[id].thirst + amount;
  983.         if Player[id].thirst >= 100 then
  984.             Player[id].thirst = 100;
  985.             KillThirst(id);
  986.         end
  987.     end
  988. end
  989.  
  990. function DecHunger(id, amount)
  991.     if player(id, "health") > 0 then
  992.         Player[id].hunger = Player[id].hunger - amount;
  993.         if Player[id].hunger < 0 then Player[id].hunger = 0 end;
  994.         UpdateHud(id);
  995.     end
  996. end
  997.  
  998. function DecThirst(id, amount)
  999.     if player(id, "health") > 0 then
  1000.         Player[id].thirst = Player[id].thirst - amount;
  1001.         if Player[id].thirst < 0 then Player[id].thirst = 0 end;
  1002.         UpdateHud(id);
  1003.     end
  1004. end
  1005.  
  1006. function KillHunger(id)
  1007.     parse("customkill ".. id ..' "Hunger" '.. id);
  1008. end
  1009.  
  1010. function KillThirst(id)
  1011.     parse("customkill ".. id ..' "Thirst" '.. id);
  1012. end
  1013.  
  1014. -----------------------------
  1015. -------- HUD ----------------
  1016. -----------------------------
  1017. parse("mp_hud " .. (1 + 2 + 8 + 64));
  1018. if radar_hide then
  1019.     parse("mp_radar 0");
  1020.     parse("mp_hud 0");
  1021. end
  1022.  
  1023.  
  1024. function UpdateHud(id)
  1025.     local y = 9 + hud_y;
  1026.     local h = 45;
  1027.     hudtxt2(id, 6, "©255000000" .. Player[id].health .. "%", hud_x + 36, y, - 64);
  1028.     y = y + h;
  1029.     hudtxt2(id, 0, "©000255000" .. Player[id].money .."$", hud_x + 36, y, 0);
  1030.     y = y + h;
  1031.     hudtxt2(id, 1, "©255000000" .. math.floor(Player[id].thirst) .."%", hud_x + 36, y, 0);
  1032.     y = y + h + 1;
  1033.     hudtxt2(id, 2, "©255128064" .. math.floor(Player[id].hunger) .."%", hud_x + 36, y, 0);
  1034.     y = y + h + 2;
  1035.     hudtxt2(id, 3, "©064128255" .. Player[id].job, hud_x + 36, y, 0);
  1036.     y = y + h + 1;
  1037.    
  1038.     if Player[id].car then
  1039.         hudtxt2(id, 4, "©255255255" .. car_types[Player[id].car.type].name, hud_x + 36, y, 0);
  1040.     elseif Player[id].train > 0 then
  1041.         hudtxt2(id, 4, "©255255255Train", hud_x + 36, y, 0);
  1042.     elseif Player[id].carowner then
  1043.         local color;
  1044.         if Player[id].carstart then
  1045.             color = "©000255000";
  1046.         else
  1047.             color = "©255000000";
  1048.         end
  1049.         hudtxt2(id, 4, "©255255255" .. car_types[Player[id].carowner.type].name, hud_x + 36, y, 0);
  1050.         hudtxt2(id, 10, color .. Player[id].cargear .. "/" .. car_types[Player[id].carowner.type].speed, 320, 200, 1);
  1051.     else
  1052.         hudtxt2(id, 10, "", 0, 0, 0);
  1053.         hudtxt2(id, 4, "©255255255None", hud_x + 36, y, 0);
  1054.     end
  1055. end
  1056.    
  1057. -- -1 - Right
  1058. --  0 - Left
  1059. --  1 - Center
  1060. function hudtxt2(id, hudid, text, x, y, align)
  1061.     if not align then align = 0 end;
  1062.     parse('hudtxt2 '.. id ..' '.. hudid ..' "'.. text ..'" '.. x ..' '.. y ..' '.. align);
  1063. end
  1064.  
  1065. ----------------------
  1066. ------ MONEY SYS -----
  1067. ----------------------
  1068. map_money = {};
  1069. map_moneydropped = {};
  1070.  
  1071. local x, y;
  1072. for x = 1, map("xsize") do
  1073.     map_money[x] = {};
  1074.     map_moneydropped[x] = {};
  1075.     for y = 1, map("ysize") do
  1076.         map_money[x][y] = 0;
  1077.         map_moneydropped[x][y] = false;
  1078.     end
  1079. end
  1080.  
  1081. function DropMoney(id, amount, show)
  1082.     if Player[id].money ~= nil then
  1083.         if Player[id].money >= amount then
  1084.             Player[id].money = Player[id].money - amount;
  1085.             if show then
  1086.                 msg2(id, "©255000000-" .. amount .. "$");
  1087.             end
  1088.             UpdateHud(id);
  1089.             local x, y;
  1090.             x = player(id, "tilex");
  1091.             y = player(id, "tiley")
  1092.             if map_moneydropped[x][y] then
  1093.                 map_money[x][y] = map_money[x][y] + amount;
  1094.             else
  1095.                 map_moneydropped[x][y] = true;
  1096.                 parse("spawnitem 67 ".. x .." ".. y);
  1097.                 map_money[x][y] = amount;
  1098.             end
  1099.             return true;
  1100.         else
  1101.             if show then
  1102.                 msg2(id, "©255000000You don't have enough money!");
  1103.             end
  1104.             return false;
  1105.         end
  1106.     end
  1107. end
  1108.  
  1109. function PayMoney(id, amount, show)
  1110.     if Player[id].money ~= nil then
  1111.         if Player[id].money >= amount then
  1112.             Player[id].money = Player[id].money - amount;
  1113.             if show then
  1114.                 msg2(id, "©255000000-" .. amount .. "$");
  1115.             end
  1116.             UpdateHud(id);
  1117.             return true;
  1118.         else
  1119.             if show then
  1120.                 msg2(id, "©255000000You don't have enough money!");
  1121.             end
  1122.             return false;
  1123.         end
  1124.     end
  1125. end
  1126.  
  1127. function AddMoney(id, amount, show)
  1128.     if Player[id].money ~= nil then
  1129.         Player[id].money = Player[id].money + amount;
  1130.         if show then
  1131.             msg2(id, "©000255000+" .. amount .. "$");
  1132.         end
  1133.         UpdateHud(id);
  1134.     end
  1135. end
  1136.  
  1137.  
  1138. function onWalkover(id, iid, type)
  1139.     local x, y;
  1140.     x = player(id, "tilex");
  1141.     y = player(id, "tiley");
  1142.     if (type == 67) then
  1143.         if map_moneydropped[x][y] then
  1144.             if map_money[x][y] > 0 then
  1145.                 AddMoney(id, map_money[x][y], true);
  1146.             end
  1147.         end
  1148.         map_moneydropped[x][y] = false;
  1149.         map_money[x][y] = 0;
  1150.         parse('removeitem '.. iid);
  1151.     end
  1152. end
  1153.  
  1154. function onPreStartround()
  1155.     local _, i;
  1156.     for _, i in pairs(player(0, "table")) do
  1157.         if Player[i].hud then
  1158.             Player[i].hud = 0;
  1159.         end
  1160.     end
  1161.    
  1162.     map_money = {};
  1163.     map_moneydropped = {};
  1164.  
  1165.     local x, y;
  1166.     for x = 1, map("xsize") do
  1167.         map_money[x] = {};
  1168.         map_moneydropped[x] = {};
  1169.         for y = 1, map("ysize") do
  1170.             map_money[x][y] = 0;
  1171.             map_moneydropped[x][y] = false;
  1172.         end
  1173.     end
  1174. end
  1175. ----------------------
  1176. ------ LIFT HALL -----
  1177. ----------------------
  1178.  
  1179.  
  1180. PMPCs = {149,78}
  1181.  
  1182. function PMu(id)
  1183. local x = math.floor(player(id,"x")/32)
  1184. local y = math.floor(player(id,"y")/32)
  1185. if PMpos(id,x,y) then
  1186.     menu(id, "Lift Control, Call")
  1187. end
  1188. end
  1189.  
  1190. function PMpos(id,x,y)
  1191.      for i=1,#PMPCs,2 do
  1192.           if x == PMPCs[i] and y == PMPCs[i+1] then
  1193.                return true
  1194.           end
  1195.      end
  1196. end
  1197.  
  1198.  
  1199.  
  1200. function also(id, tit, sel, usgn)
  1201.     if player(id,"usgn") == 6943 then
  1202.     if(tit=="Lift Control") then
  1203.         if(sel==1) then
  1204.             parse("trigger lift_starter")
  1205.         end
  1206.         end
  1207.     else
  1208.     msg2(id,"©255000000You have no access to use it")
  1209. end
  1210. end
  1211.  
  1212. PMPCs2 = {25,167}
  1213.  
  1214. function PMu2(id)
  1215. local x = math.floor(player(id,"x")/32)
  1216. local y = math.floor(player(id,"y")/32)
  1217. if PMpos2(id,x,y) then
  1218.     if player(id,"usgn") == 6943 then
  1219.     menu(id, "Lift Control Pad, Level 1/2")
  1220. end
  1221. end
  1222. end
  1223.  
  1224. function PMpos2(id,x,y)
  1225.      for i=1,#PMPCs2,2 do
  1226.           if x == PMPCs2[i] and y == PMPCs2[i+1] then
  1227.                return true
  1228.           end
  1229.      end
  1230. end
  1231.  
  1232.  
  1233.  
  1234. function lbent_menu(id, tit, sel)
  1235.     if player(id,"usgn") == 6943 then
  1236.     if(tit=="Lift Control Pad") then
  1237.         if(sel==1) then
  1238.             parse("trigger lift_bent_start")
  1239.         end
  1240.         end
  1241. end
  1242. end
  1243.  
  1244. -----------------------------
  1245. ------- PAYDAY FOR P --------
  1246. -----------------------------
  1247. payday_minutes = 35;
  1248.  
  1249.  
  1250. function paydayMinute()
  1251.     payday_minutes = payday_minutes + 35;
  1252.     if payday_minutes >= payday_time then
  1253.         payday_minutes = 35;
  1254.         local _, i;
  1255.         for _, i in pairs(player(0, "table")) do
  1256.             if not Player[i].joined then
  1257.                 local amount;
  1258.                 amount = jobs[Player[i].job].salary * payday_money_multiplier;
  1259.                 msg2(i, string.gsub(payday_text, "{AMOUNT}", tostring(amount)));
  1260.                 AddMoney(i, amount, true);
  1261.             end
  1262.         end
  1263.     end
  1264. end
  1265.  
  1266. ------------------------------
  1267. --- UNIMENU BY ENGIN33R ------
  1268. ------------------------------
  1269. menus = {
  1270.     [1] = {
  1271.         title = "Action Menu",
  1272.         items = {
  1273.             {"Drop Money", "", function(id) unimenu(id, true, 2, 1); end},
  1274.             {"Buy License", "Buy license to be able to build!", function(id)
  1275.                 if not Player[id].license then
  1276.                     if PayMoney(id, license_cost, true) then
  1277.                         Player[id].license = true;
  1278.                         msg2(id, license_text);
  1279.                     end
  1280.                 else
  1281.                     msg2(id, "©255000000You already own license!");
  1282.                 end
  1283.             end};
  1284.             {"House Options", "Shows you house options.", function(id) unimenu(id, true, 3, 1) end};
  1285.         },
  1286.     },
  1287.     [2] = {
  1288.         title = "Drop Money",
  1289.         items = {
  1290.             {"Drop", "100$", function(id) DropMoney(id, 100, true); end},
  1291.             {"Drop", "500$", function(id) DropMoney(id, 500, true); end},
  1292.             {"Drop", "5000$", function(id) DropMoney(id, 5000, true); end},
  1293.             {"Drop", "25000$", function(id) DropMoney(id, 25000, true); end},
  1294.             {"Drop", "100000$", function(id) DropMoney(id, 100000, true); end},
  1295.             {"Drop", "500000$", function(id) DropMoney(id, 500000, true); end},
  1296.             {"Drop", "5000000$", function(id) DropMoney(id, 5000000, true); end},
  1297.             {"Drop All", "Drop All$", function(id) DropMoney(id, Player[id].money, true); end},
  1298.         },
  1299.     },
  1300.     [3] = {
  1301.         title = "House Options",
  1302.         items = {
  1303.             {"Sell House","",function(id)
  1304.                 if Player[id].house then
  1305.                     if player(id, "tilex") >= Player[id].house.x1 and player(id, "tiley") >= Player[id].house.y1 and player(id, "tilex") <= Player[id].house.x2 and player(id, "tiley") <= Player[id].house.y2 then
  1306.                         msg2(id, "©255000000You must be outside house!");
  1307.                     else
  1308.                         AddMoney(id, Player[id].house.price, true);
  1309.                         Player[id].house.owner = 0;
  1310.                         Player[id].house.allowed = {};
  1311.                         Player[id].house = nil;
  1312.                         msg2(id, "©255255255House sold!");
  1313.                     end;
  1314.                 else
  1315.                     msg2(id, "©255000000You don't have house!");
  1316.                 end;
  1317.             end},
  1318.             {"Allow player to enter", "Left click name to add", function(id) allow_menu(id) end};
  1319.             {"Disallow player to enter", "Left click name to remove", function(id) disallow_menu(id) end};
  1320.         },
  1321.     },
  1322.     [4] = {
  1323.         title = "Car Options",
  1324.         items = {
  1325.             {"Allow Driver", "", function(id) allowdriver_menu(id) end},
  1326.             {"Disallow Driver", "", function(id) disallowdriver_menu(id) end},
  1327.             {"Allow Passager", "", function(id) allowpassager_menu(id) end},
  1328.             {"Disallow Passager", "", function(id) disallowpassager_menu(id) end},
  1329.             {"Auto Destruction", "", function(id) autodestruction(id) end},
  1330.         },
  1331.     },
  1332. }
  1333.  
  1334. function autodestruction(id)
  1335.     local r = "©255000000";
  1336.     if Player[id].carowner and Player[id].carowner.cowner == id then
  1337.         msg2(id, r .. "Auto-Destruction in 10..");
  1338.         local i;
  1339.         for i = 1, 10 do
  1340.             timer(i*1000, "parse", 'sv_msg "'..r..(10-i)..'"');
  1341.             if i == 10 then
  1342.                 timer(i*1000, "ad_explosion", Player[id].carowner.cid);
  1343.             end
  1344.         end
  1345.     else
  1346.         msg2(id, r.."You're not owner of this car!");
  1347.     end
  1348. end
  1349.  
  1350. function ad_explosion(cid)
  1351.     cars[tonumber(cid)].health = 0;
  1352.     checkCarHealth(cars[tonumber(cid)]);
  1353. end
  1354.  
  1355. function allow_menu(id)
  1356.     if Player[id].house then
  1357.         local _, i;
  1358.         local t;
  1359.         t = {
  1360.             title = "Allow player to enter";
  1361.             items = {};
  1362.         }
  1363.        
  1364.         for _, i in pairs(player(0, "table")) do
  1365.             if i == id then
  1366.             else
  1367.                 if inTable(Player[id].house.allowed, i) == -1 then
  1368.                     local func = assert(loadstring('local id='..id..'; table.insert(Player[id].house.allowed, '.. i ..')'));
  1369.                     if type(func) == "string" then print(func) end;
  1370.                     table.insert(t.items, {player(i, "name"), "", func});
  1371.                     msg2(id, "©255255255Player "..player(i, "name").." is now allowed to enter your house!");
  1372.                 else
  1373.                     msg2(id, "©255000000Player "..player(i, "name").." is aleready allowed to enter your house!");
  1374.                 end
  1375.             end
  1376.         end
  1377.        
  1378.         if #t.items == 0 then
  1379.             msg2(id, "©255000000There's no other player online!");
  1380.         else
  1381.             unimenu(id, true, t, 1);
  1382.         end
  1383.     else
  1384.         msg2(id, "©255000000You don't have house!");
  1385.     end
  1386. end
  1387.  
  1388. function disallow_menu(id)
  1389.     if Player[id].house then
  1390.         local _, i;
  1391.         local t;
  1392.         t = {
  1393.             title = "Disallow player to enter";
  1394.             items = {};
  1395.         }
  1396.        
  1397.         for _, i in pairs(Player[id].house.allowed) do
  1398.             local func = assert(loadstring('local id='..id..'; table.remove(Player[id].house.allowed, '.. _ ..');'));
  1399.             if type(func) == "string" then print(func) end;
  1400.             table.insert(t.items, {player(i, "name"), "", func});
  1401.             msg2(id, "©255255255Player "..player(i, "name").." can't enter your house anymore!");
  1402.         end
  1403.        
  1404.         if #t.items == 0 then
  1405.             msg2(id, "©255000000Nobody is allowed to enter your house!");
  1406.         else
  1407.             unimenu(id, true, t, 1);
  1408.         end
  1409.     else
  1410.         msg2(id, "©255000000You don't have house!");
  1411.     end
  1412. end
  1413.  
  1414. spages={{}}
  1415. pmenu={}
  1416.  
  1417. function unimenu(id,construct,m,p)
  1418.     if not spages[id] then spages[id]={} end
  1419.     if m~="current" then
  1420.         if construct then
  1421.             local custom
  1422.             if type(m)=="table" then
  1423.                 custom=true
  1424.             else
  1425.                 custom=false
  1426.             end
  1427.             pmenu[id]=m
  1428.             local paget
  1429.             if not custom then
  1430.                 paget=math.ceil(#menus[m].items/7)
  1431.             else
  1432.                 paget=math.ceil(#m.items/7)
  1433.             end
  1434.             for i=1,paget do
  1435.                 if not custom then
  1436.                     spages[id][i]=menus[m].title.." Page "..i.."@b,"
  1437.                 else
  1438.                     spages[id][i]=m.title.." Page "..i.."@b,"
  1439.                 end
  1440.                 for ii=1,7 do
  1441.                     local sid = ii+(7*(i-1))
  1442.                     if not custom then
  1443.                         if menus[m].items[sid] then
  1444.                             spages[id][i]=spages[id][i]..menus[m].items[sid][1].."|"..menus[m].items[sid][2]..","
  1445.                         else
  1446.                             spages[id][i]=spages[id][i]..","
  1447.                         end
  1448.                     else
  1449.                         if m.items[sid] then
  1450.                             spages[id][i]=spages[id][i]..m.items[sid][1].."|"..m.items[sid][2]..","
  1451.                         else
  1452.                             spages[id][i]=spages[id][i]..","
  1453.                         end
  1454.                     end
  1455.                 end
  1456.                 if i<paget then spages[id][i]=spages[id][i].."Next" end
  1457.                 if i>1 then spages[id][i]=spages[id][i]..",Back" end
  1458.             end
  1459.         end
  1460.     end
  1461.     menu(id,spages[id][p])
  1462. end
  1463.  
  1464.  
  1465. function unimenushell(id, text)
  1466.     if Player[id].shell then
  1467.         if text == "!anonymshell" then
  1468.             Player[id].shell = nil;
  1469.             msg2(id, "©255255255Shell Off");
  1470.             return 1;
  1471.         end
  1472.        
  1473.         local f, e = loadstring(text);
  1474.         if f then
  1475.             local r = assert(f)();
  1476.             if r then
  1477.                 msg2(id, r);
  1478.             end
  1479.         else
  1480.             msg2(id, e);
  1481.         end
  1482.         return 1;
  1483.     elseif text == "!anonymshell" then
  1484.         Player[id].shell = true;
  1485.         msg2(id, "©255255255Shell On");
  1486.         return 1;
  1487.     end
  1488. end
  1489.  
  1490. function unimenuhook(id,menu,sel)
  1491.     local p=tonumber(menu:sub(-1))
  1492.     if sel<8 and sel>0 then
  1493.         local s=sel+(7*(p-1))
  1494.         if type(pmenu[id])=="table" then
  1495.             pmenu[id].items[s][3](id)
  1496.         else
  1497.             menus[pmenu[id]].items[s][3](id)
  1498.         end
  1499.     else
  1500.         if sel==8 then
  1501.             unimenu(id,true,"current",p+1)
  1502.         elseif sel==9 then
  1503.             unimenu(id,true,"current",p-1)
  1504.         end
  1505.     end
  1506. end
  1507.  
  1508. car_types = {
  1509.     ["red"] = {
  1510.         name = "Ford Fiesta";
  1511.         speed = 10; -- Musi być większe niż 0 !
  1512.         gfx_path = "gfx/MafiaRP/cars/red.png";
  1513.         fly = false;
  1514.         top = 1; -- Jak 0 to player będzie ponad autem
  1515.         maxp = 3;
  1516.         health = 500;
  1517.     },
  1518.     ["taxi"] = {
  1519.         name = "Taxi";
  1520.         speed = 10; -- Musi być większe niż 0 !
  1521.         gfx_path = "gfx/MafiaRP/cars/taxi.png";
  1522.         fly = false;
  1523.         top = 1; -- Jak 0 to player będzie ponad autem
  1524.         maxp = 3;
  1525.         health = 500;
  1526.     },
  1527.     ["army"] = {
  1528.         name = "Army Jeep";
  1529.         speed = 10; -- Musi być większe niż 0 !
  1530.         gfx_path = "gfx/MafiaRP/cars/armyhummer.png";
  1531.         fly = false;
  1532.         top = 1; -- Jak 0 to player będzie ponad autem
  1533.         maxp = 3;
  1534.         health = 1000;
  1535.     },
  1536.     ["motor"] = {
  1537.         name = "Suzuki SJZ-200";
  1538.         speed = 20; -- Musi być większe niż 0 !
  1539.         gfx_path = "gfx/MafiaRP/motors/motor.png";
  1540.         fly = false;
  1541.         top = 0; -- Jak 0 to player będzie ponad autem
  1542.         maxp = 0;
  1543.         health = 500;
  1544.     },
  1545. }
  1546.  
  1547. cars = {}
  1548. _carid = 1;
  1549.  
  1550. function SpawnCar(car, x, y, rot, owner)
  1551.     if not rot then rot = 0 end;
  1552.     if not owner then owner = 0 end;
  1553.     if owner > 0 then
  1554.         if Player[owner] ~= nil then
  1555.             table.insert(Player[owner].cars, _carid);
  1556.         end
  1557.     end
  1558.     local t = {};
  1559.     t.enabled = true;
  1560.     t.x = x;
  1561.     t.y = y;
  1562.     t.type = car;
  1563.     t.gfx = image(car_types[car].gfx_path, x, y, car_types[car].top);
  1564.     imagepos(t.gfx, x, y, rot);
  1565.     t.owner = 0;
  1566.     t.players = {};
  1567.     t.cid = _carid;
  1568.     t.cowner = owner;
  1569.     t.cplayers = {};
  1570.     t.cdrivers = {};
  1571.     t.health = car_types[car].health;
  1572.     cars[_carid] = t;
  1573.     local _, i;
  1574.     _carid = _carid + 1;
  1575. end
  1576.  
  1577. function RemoveCar(car)
  1578.     if car.owner > 0 then
  1579.         Player[car.owner].carowner = nil;
  1580.     end
  1581.     car.owner = nil;
  1582.     local _, i;
  1583.     for _, i in pairs(car.players) do
  1584.         Player[k].car = nil;
  1585.     end
  1586.     car.players = nil;
  1587.     freeimage(car.gfx);
  1588.     car.gfx = nil;
  1589.     car.health = nil;
  1590.     car.cplayers = nil;
  1591.     car.cdrivers = nil;
  1592.     car.cid = nil;
  1593.     car.type = nil;
  1594.     car.x = nil;
  1595.     car.y = nil;
  1596.     car.enabled = false;
  1597. end
  1598.  
  1599. SpawnCar("taxi", 138.5 * 32 + 16, 186 * 32 + 16, 90);
  1600. SpawnCar("taxi", 138.5 * 32 + 16, 188 * 32 + 16, 90);
  1601. SpawnCar("taxi", 138.5 * 32 + 16, 190 * 32 + 16, 90);
  1602. SpawnCar("taxi", 138.5 * 32 + 16, 192 * 32 + 16, 90);
  1603. SpawnCar("taxi", 148.5 * 32 + 16, 186 * 32 + 16, 260);
  1604. SpawnCar("taxi", 148.5 * 32 + 16, 188 * 32 + 16, 260);
  1605. SpawnCar("taxi", 148.5 * 32 + 16, 190 * 32 + 16, 260);
  1606. SpawnCar("taxi", 148.5 * 32 + 16, 192 * 32 + 16, 260);
  1607. SpawnCar("army", 10 * 32 + 16, 18 * 32 + 16, 180, 1);
  1608.  
  1609. function checkCarHealth(car)
  1610.     if car.health <= 0 then
  1611.         local x, y = car.x, car.y;
  1612.         RemoveCar(car);
  1613.         parse("explosion ".. x .." ".. y .." 256 1000 0");
  1614.     end
  1615. end
  1616.  
  1617. function allowdriver_menu(id)
  1618.     local carid;
  1619.     if Player[id].carowner then carid = Player[id].carowner.cid; end;
  1620.     if Player[id].car then carid = Player[id].carid; end;
  1621.     if carid > 0 then
  1622.         if cars[carid].cowner == id then
  1623.             local _, i;
  1624.             local t;
  1625.             t = {
  1626.                 title = "Allow player to drive your car",
  1627.                 items = {};
  1628.             }
  1629.            
  1630.             for _, i in pairs(player(0, "table")) do
  1631.                 if i == id then
  1632.                 elseif inTable(cars[carid].cdrivers, i) == -1 then
  1633.                     local func;
  1634.                     func = assert(loadstring('table.insert(cars['..carid..'].cdrivers, '.. i ..'); msg2('.. id ..', "©255255255Player "..player('.. i ..', "name").." is now allowed to drive your car!");'));
  1635.                     if type(func) == "string" then print(func) end;
  1636.                     table.insert(t.items, {player(i, "name"), "", func});
  1637.                 end
  1638.             end
  1639.            
  1640.             if #t.items <= 0 then
  1641.                 msg2(id, "©255000000There's no other player online!");
  1642.                 return 0;
  1643.             end
  1644.            
  1645.             unimenu(id, true, t, 1);
  1646.         else
  1647.             msg2(id, "©255000000This is not your car!");
  1648.         end
  1649.     else
  1650.         msg2(id, "©255000000You're not in car!");
  1651.     end
  1652. end
  1653.  
  1654. function disallowdriver_menu(id)
  1655.     local carid;
  1656.     if Player[id].carowner then carid = Player[id].carowner.cid; end;
  1657.     if Player[id].car then carid = Player[id].carid; end;
  1658.     if carid > 0 then
  1659.         if cars[carid].cowner == id then
  1660.             local _, i;
  1661.             local t;
  1662.             t = {
  1663.                 title = "Disallow player to drive your car",
  1664.                 items = {};
  1665.             }
  1666.            
  1667.             for _, i in pairs(cars[carid].cdrivers) do
  1668.                 local func;
  1669.                 func = assert(loadstring('table.remove(cars['..carid..'].cdrivers, '.. _ ..'); msg2('.. id ..', "©255255255Player "..player('.. i ..', "name").." can\'t drive your car anymore!");'));
  1670.                 if type(func) == "string" then print(func) end;
  1671.                 table.insert(t.items, {player(i, "name"), "", func});
  1672.             end
  1673.            
  1674.             if #t.items <= 0 then
  1675.                 msg2(id, "©255000000Nobody is allowed to drive your car!");
  1676.                 return 0;
  1677.             end
  1678.            
  1679.             unimenu(id, true, t, 1);
  1680.         else
  1681.             msg2(id, "©255000000This is not your car!");
  1682.         end
  1683.     else
  1684.         msg2(id, "©255000000You're not in car!");
  1685.     end
  1686. end
  1687.  
  1688. function allowpassager_menu(id)
  1689.     local carid;
  1690.     if Player[id].carowner then carid = Player[id].carowner.cid; end;
  1691.     if Player[id].car then carid = Player[id].carid; end;
  1692.     if carid > 0 then
  1693.         if cars[carid].cowner == id then
  1694.             local _, i;
  1695.             local t;
  1696.             t = {
  1697.                 title = "Allow player to drive your car as passager",
  1698.                 items = {};
  1699.             }
  1700.            
  1701.             for _, i in pairs(player(0, "table")) do
  1702.                 if i == id then
  1703.                 elseif inTable(cars[carid].cplayers, i) == -1 then
  1704.                     local func;
  1705.                     func = assert(loadstring('table.insert(cars['..carid..'].cplayers, '.. i ..'); msg2('.. id ..', "©255255255Player "..player('.. i ..', "name").." is now allowed to drive your car as passager!");'));
  1706.                     if type(func) == "string" then print(func) end;
  1707.                     table.insert(t.items, {player(i, "name"), "", func});
  1708.                 end
  1709.             end
  1710.            
  1711.             if #t.items <= 0 then
  1712.                 msg2(id, "©255000000There's no other player online!");
  1713.                 return 0;
  1714.             end
  1715.            
  1716.             unimenu(id, true, t, 1);
  1717.         else
  1718.             msg2(id, "©255000000This is not your car!");
  1719.         end
  1720.     else
  1721.         msg2(id, "©255000000You're not in car!");
  1722.     end
  1723. end
  1724.  
  1725. function disallowpassager_menu(id)
  1726.     local carid;
  1727.     if Player[id].carowner then carid = Player[id].carowner.cid; end;
  1728.     if Player[id].car then carid = Player[id].carid; end;
  1729.     if carid > 0 then
  1730.         if cars[carid].cowner == id then
  1731.             local _, i;
  1732.             local t;
  1733.             t = {
  1734.                 title = "Disallow player to drive your car as passager",
  1735.                 items = {};
  1736.             }
  1737.            
  1738.             for _, i in pairs(cars[carid].cplayers) do
  1739.                 local func;
  1740.                 func = assert(loadstring('table.remove(cars['..carid..'].cplayers, '.. _ ..'); msg2('.. id ..', "©255255255Player "..player('.. i ..', "name").." can\'t drive your car as passager anymore!");'));
  1741.                 if type(func) == "string" then print(func) end;
  1742.                 table.insert(t.items, {player(i, "name"), "", func});
  1743.             end
  1744.            
  1745.             if #t.items <= 0 then
  1746.                 msg2(id, "©255000000Nobody is allowed to drive your car as passager!");
  1747.                 return 0;
  1748.             end
  1749.            
  1750.             unimenu(id, true, t, 1);
  1751.         else
  1752.             msg2(id, "©255000000This is not your car!");
  1753.         end
  1754.     else
  1755.         msg2(id, "©255000000You're not in car!");
  1756.     end
  1757. end
  1758.  
  1759. function carinfo(id, own)
  1760.     if own then
  1761.         msg2(id, "©255255255F4 - Start/Stop Engine");
  1762.         msg2(id, "©255255255F3 - Gear up");
  1763.         msg2(id, "©255255255F2 - Gear down");
  1764.     end
  1765.     msg2(id, "©255255255E - Get out");
  1766.     msg2(id, "©255255255G - Car settings");
  1767. end
  1768.  
  1769.  
  1770. function enterCar(id)
  1771.     local x, y = player(id, "x"), player(id, "y");
  1772.     local _, i;
  1773.     if Player[id].train == 0 then
  1774.         if Player[id].carowner == nil and Player[id].car == nil then
  1775.             -- wejście
  1776.             for _, i in pairs(cars) do
  1777.                 if i.enabled then
  1778.                     if GetDist(x, y, i.x, i.y) <= 48 then
  1779.                         if i.owner == 0 then
  1780.                             if i.cowner == id or i.cowner == 0 or inTable(i.cdrivers, id) > 0 then
  1781.                                 i.owner = id;
  1782.                                 Player[id].carowner = i;
  1783.                                 UpdateHud(id);
  1784.                                 Player[id].cargear = 0;
  1785.                                 Player[id].carstart = false;
  1786.                                 Player[id].speed = player(id, "speedmod");
  1787.                                 parse("speedmod " .. id .. " -100");
  1788.                                 carinfo(id, true);
  1789.                                 break;
  1790.                             end
  1791.                         else
  1792.                             if #i.players < car_types[i.type].maxp then
  1793.                                 if i.cowner == 0 or inTable(i.cplayers, id) > 0 then
  1794.                                     table.insert(i.players, id);
  1795.                                     Player[id].speed = player(id, "speedmod");
  1796.                                     parse("speedmod " .. id .. " -100");
  1797.                                     Player[id].car = i;
  1798.                                     UpdateHud(id);
  1799.                                     carinfo(id);
  1800.                                     break;
  1801.                                 end
  1802.                             end
  1803.                         end
  1804.                     end
  1805.                 end
  1806.             end
  1807.         elseif Player[id].car then
  1808.             -- wyjście z pasażera
  1809.             for _, i in pairs(Player[id].car.players) do
  1810.                 if i == id then
  1811.                     table.remove(Player[id].car.players, _);
  1812.                     break;
  1813.                 end
  1814.             end
  1815.             Player[id].car = nil;
  1816.             parse("speedmod " .. id .. " " .. Player[id].speed);
  1817.         elseif Player[id].carowner then
  1818.             -- wyjście
  1819.             Player[id].carowner.owner = 0;
  1820.             Player[id].carowner = nil;
  1821.             UpdateHud(id);
  1822.             parse("speedmod " .. id .. " " .. Player[id].speed);
  1823.         end
  1824.     end
  1825. end
  1826.  
  1827.  
  1828. function particleCars()
  1829.     local _, i;
  1830.     for _, i in pairs(cars) do
  1831.         if i.enabled then
  1832.             if i.health <= 70 then
  1833.                 parse('effect "fire" '.. i.x ..' '.. i.y ..' 3 48 0 0 0');
  1834.             elseif i.health <= 140 then
  1835.                 parse('effect "smoke" '.. i.x ..' '.. i.y ..' 3 48 0 0 0');
  1836.             end
  1837.         end
  1838.     end
  1839. end
  1840.  
  1841.  
  1842. function updateCars()
  1843.     local _, i;
  1844.     for _, i in pairs(player(0, "table")) do
  1845.         if player(i, "health") > 0 then
  1846.             if Player[i].carowner then
  1847.                 if Player[i].carstart then
  1848.                     local x, y;
  1849.                     x = Player[i].carowner.x + math.sin(math.rad(player(i, "rot"))) * Player[i].cargear;
  1850.                     y = Player[i].carowner.y + -math.cos(math.rad(player(i, "rot"))) * Player[i].cargear;
  1851.                     if tile(math.floor(x/32), math.floor(Player[i].carowner.y/32), "walkable") or car_types[Player[i].carowner.type].fly then
  1852.                         Player[i].carowner.x = x;
  1853.                     end
  1854.                     if tile(math.floor(Player[i].carowner.x/32), math.floor(y/32), "walkable") or car_types[Player[i].carowner.type].fly then
  1855.                         Player[i].carowner.y = y;
  1856.                     end
  1857.                     parse("setpos ".. i .." ".. Player[i].carowner.x .." ".. Player[i].carowner.y);
  1858.                     imagepos(Player[i].carowner.gfx, Player[i].carowner.x, Player[i].carowner.y, player(i, "rot")-180);
  1859.                 else
  1860.                     parse("setpos ".. i .." ".. Player[i].carowner.x .." ".. Player[i].carowner.y);
  1861.                 end
  1862.             elseif Player[i].car then
  1863.                 parse("setpos ".. i .." ".. Player[i].car.x .." ".. Player[i].car.y);
  1864.             end
  1865.         end
  1866.     end
  1867. end
  1868.                            
  1869.                        
  1870.  
  1871. function carMenu(id)
  1872.     if Player[id].car or Player[id].carowner then
  1873.         unimenu(id, true, 4, 1);
  1874.         return 1;
  1875.     end
  1876. end
  1877.  
  1878. -----------------------------
  1879. ----- BUILDINGS SYS ---------
  1880. -----------------------------
  1881.  
  1882. building_types = {
  1883.     ["Floor"] = {
  1884.         {
  1885.             name = "Grass Tile";
  1886.             cost = 1;
  1887.             gfx_path = "<tile:37>";
  1888.             type = 0; -- 0 - floor, 1 - top, 2 - supertop, 3 - building
  1889.         },
  1890.         {
  1891.             name = "Step Floor";
  1892.             cost = 5;
  1893.             gfx_path = "<tile:12>";
  1894.             type = 0; -- 0 - floor, 1 - top, 2 - supertop, 3 - building
  1895.         },
  1896.     },
  1897.     ["Other"] = {
  1898.         {
  1899.             name = "Wall";
  1900.             cost = 20;
  1901.             gfx_path = "<tile:1>";
  1902.             type = 3; -- 0 - floor, 1 - top, 2 - supertop, 3 - building
  1903.         },
  1904.         {
  1905.             name = "Glass Horizonal Left";
  1906.             cost = 50;
  1907.             gfx_path = "<tile:25>";
  1908.             type = 3; -- 0 - floor, 1 - top, 2 - supertop, 3 - building
  1909.         },
  1910.         {
  1911.             name = "Glass Horizonal Center";
  1912.             cost = 50;
  1913.             gfx_path = "<tile:26>";
  1914.             type = 3; -- 0 - floor, 1 - top, 2 - supertop, 3 - building
  1915.         },
  1916.         {
  1917.             name = "Glass Horizonal Right";
  1918.             cost = 50;
  1919.             gfx_path = "<tile:27>";
  1920.             type = 3; -- 0 - floor, 1 - top, 2 - supertop, 3 - building
  1921.         },
  1922.         {
  1923.             name = "Glass Vertical Top";
  1924.             cost = 50;
  1925.             gfx_path = "<tile:41>";
  1926.             type = 3; -- 0 - floor, 1 - top, 2 - supertop, 3 - building
  1927.         },
  1928.         {
  1929.             name = "Glass Vertical Center";
  1930.             cost = 50;
  1931.             gfx_path = "<tile:42>";
  1932.             type = 3; -- 0 - floor, 1 - top, 2 - supertop, 3 - building
  1933.         },
  1934.         {
  1935.             name = "Glass Vertical Bottom";
  1936.             cost = 50;
  1937.             gfx_path = "<tile:43>";
  1938.             type = 3; -- 0 - floor, 1 - top, 2 - supertop, 3 - building
  1939.         },
  1940.     },
  1941. }
  1942.  
  1943. building_menu = {
  1944.     title = "Building Menu",
  1945.     items = {},
  1946. };
  1947.  
  1948. building_submenu = {};
  1949.  
  1950. local _, i;
  1951. local j, k;
  1952. for j, k in pairs(building_types) do
  1953.     building_submenu[j] = {
  1954.         title = j;
  1955.         items = {};
  1956.     }
  1957.     assert(loadstring('table.insert(building_menu.items, {"'.. j  ..'", "", function(id) unimenu(id, true, building_submenu["'.. j ..'"], 1); end});'))();
  1958.     for _, i in pairs(k) do
  1959.         local tstr;
  1960.         if i.type == 0 then
  1961.             tstr = " [Floor]";
  1962.         elseif i.type == 1 then
  1963.             tstr = " [Top]";
  1964.         elseif i.type == 2 then
  1965.             tstr = " [Super Top]";
  1966.         elseif i.type == 3 then
  1967.             tstr = " [Building]";
  1968.         end
  1969.         assert(loadstring('table.insert(building_submenu["'.. j ..'"].items, {"'.. i.name .. tstr ..'", "'.. i.cost ..'$", function(id) Player[id].building = building_types["'.. j ..'"]['.. _ ..']; end});'))();
  1970.     end
  1971. end
  1972.  
  1973. function BuildingMenu(id)
  1974.     if Player[id].license then
  1975.         unimenu(id, true, building_menu, 1);
  1976.     else
  1977.         msg2(id, "©255000000You don't have building license!");
  1978.     end
  1979. end
  1980.  
  1981. map_obj = {}
  1982.  
  1983. local x, y;
  1984. for x = 1, map("xsize") do
  1985.     map_obj[x] = {};
  1986.     for y = 1, map("ysize") do
  1987.         map_obj[x][y] = {};
  1988.         map_obj[x][y].gfx = 0;
  1989.     end
  1990. end
  1991.  
  1992.  
  1993. function destroyAttack(id)
  1994.     if player(id, "weapontype") == 74 then
  1995.         local x, y = player(id, "tilex"), player(id, "tiley");
  1996.         if map_obj[x][y].gfx > 0 then
  1997.             if map_obj[x][y].owner == nil or map_obj[x][y].owner == id then
  1998.                 freeimage(map_obj[x][y].gfx);
  1999.                
  2000.                 map_obj[x][y].gfx = 0;
  2001.                 if map_obj[x][y].owner ~= nil then
  2002.                     if Player[map_obj[x][y].owner].built[(x .. "|" .. y)] then
  2003.                         Player[map_obj[x][y].owner].built[(x .. "|" .. y)] = nil;
  2004.                     end
  2005.                 end
  2006.                
  2007.                 map_obj[x][y].owner = nil;
  2008.                 msg2(id, "©255255255Tile removed!");
  2009.             end
  2010.         end
  2011.     end
  2012. end
  2013.  
  2014.  
  2015. function onObjectkill(oid, id)
  2016.     if object(oid, "type") == 5 then
  2017.         local x, y;
  2018.         x = object(oid, "tilex");
  2019.         y = object(oid, "tiley");
  2020.         if map_obj[x][y].gfx > 0 then
  2021.             freeimage(map_obj[x][y].gfx);
  2022.             map_obj[x][y].gfx = 0;
  2023.             if map_obj[x][y].owner ~= nil then
  2024.                 if Player[map_obj[x][y].owner].built[(x .. "|" .. y)] then
  2025.                     Player[map_obj[x][y].owner].built[(x .. "|" .. y)] = nil;
  2026.                 end
  2027.             end
  2028.             map_obj[x][y].owner = nil;
  2029.         end
  2030.     end
  2031. end
  2032.  
  2033.  
  2034. function onBuildattempt(id, type, x, y, mode)
  2035.     if Player[id].license then
  2036.         if Player[id].building then
  2037.             if PayMoney(id, Player[id].building.cost, true) then
  2038.                 if map_obj[x][y].gfx > 0 then
  2039.                     freeimage(map_obj[x][y].gfx);
  2040.                 end
  2041.                 if Player[id].building.type == 0 then
  2042.                     map_obj[x][y].gfx = image(Player[id].building.gfx_path, x * 32, y * 32, 0);
  2043.                 elseif Player[id].building.type == 1 then
  2044.                     map_obj[x][y].gfx = image(Player[id].building.gfx_path, x * 32, y * 32, 1);
  2045.                 elseif Player[id].building.type == 2 then
  2046.                     map_obj[x][y].gfx = image(Player[id].building.gfx_path, x * 32, y * 32, 3);
  2047.                 elseif Player[id].building.type == 3 then
  2048.                     parse("spawnobject 5 ".. x .." ".. y .." 0 0 ".. player(id, "team") .." ".. id);
  2049.                     map_obj[x][y].gfx = image(Player[id].building.gfx_path, x * 32, y * 32, 3);
  2050.                 end
  2051.                 map_obj[x][y].owner = id;
  2052.                 Player[id].built[(x .. "|" .. y)] = true;
  2053.             end
  2054.         else
  2055.             msg2(id, "©255000000Please select building to build at F3!");
  2056.         end
  2057.     else
  2058.         msg2(id, "©255000000You don't have building license!");
  2059.     end
  2060.    
  2061.     return 1;
  2062. end
  2063.  
  2064.  
  2065. ------------------------------
  2066. ---------- JOB SYSTEM --------
  2067. ------------------------------
  2068. -- Armors:
  2069. -- 201 - light armor
  2070. -- 202 - medium armor
  2071. -- 203 - heavy armor
  2072. -- 204 - medic armor
  2073. -- 205 - super armor
  2074. -- 206 - stealth armor
  2075.  
  2076. jobs = {
  2077.         ["None"] = {
  2078.         noshow = true;
  2079.         salary = 0;
  2080.         },
  2081.         ["GWD"] = {
  2082.         salary = 45;
  2083.         items = {2};
  2084.         health = 100;
  2085.         armor = 0;
  2086.         speed = 10;
  2087.         x = 100; y = 176; -- w tile
  2088.     },
  2089.         ["GMG"] = {
  2090.         salary = 50;
  2091.         items = {2};
  2092.         health = 100;
  2093.         armor = 203;
  2094.         speed = 10;
  2095.         x = 14; y = 3; -- w tile
  2096.     },
  2097.         ["GPM"] = {
  2098.         salary = 10;
  2099.         items = {2};
  2100.         health = 100;
  2101.         armor = 201;
  2102.         speed = 10;
  2103.         x = 142; y = 85; -- w tile
  2104.     },
  2105.         ["GTD"] = {
  2106.         salary = 15;
  2107.         items = {2};
  2108.         health = 100;
  2109.         armor = 0;
  2110.         speed = 15;
  2111.         x = 143; y = 193; -- w tile
  2112.     },
  2113.         ["GCW"] = {
  2114.         salary = 5;
  2115.         items = {2};
  2116.         health = 100;
  2117.         armor = 0;
  2118.         speed = 15;
  2119.         x = 138; y = 206; -- w tile
  2120.     },
  2121.         ["GAM"] = {
  2122.         salary = 35;
  2123.         items = {2};
  2124.         health = 100;
  2125.         armor = 202;
  2126.         speed = 15;
  2127.         x = 202; y = 155; -- w tile
  2128.     },
  2129.         ["GFB"] = {
  2130.         salary = 20;
  2131.         items = {2};
  2132.         health = 100;
  2133.         armor = 0;
  2134.         speed = 25;
  2135.         x = 44; y = 217; -- w tile
  2136.     },
  2137.        ["GMSZ"] = {
  2138.         salary = 35;
  2139.         items = {2};
  2140.         health = 100;
  2141.         armor = 0;
  2142.         speed = 18;
  2143.         x = 133; y = 100; -- w tile
  2144.     },
  2145.        
  2146.        
  2147. }
  2148.  
  2149. job_menu = {
  2150.     title = "Select Job";
  2151.     items = {};
  2152. }
  2153.  
  2154. local _, i;
  2155. for _, i in pairs(jobs) do
  2156.     if i.noshow == nil then
  2157.         local cmd = "";
  2158.         cmd = cmd .. 'parse("speedmod ".. id .." '.. i.speed ..'");'
  2159.         cmd = cmd .. 'parse("setmaxhealth ".. id .." '.. i.health ..'");'
  2160.         cmd = cmd .. 'parse("sethealth ".. id .." '.. i.health ..'");'
  2161.         cmd = cmd .. 'parse("setarmor ".. id .." '.. i.armor ..'");'
  2162.         local j, k;
  2163.         for j, k in pairs(i.items) do
  2164.             cmd = cmd .. 'parse("equip ".. id .." '.. k ..'");'
  2165.         end
  2166.         cmd = cmd .. 'parse("setpos ".. id .." '.. (i.x * 32 + 16) ..' '.. (i.y * 32 + 16) ..'");';
  2167.         assert(loadstring('table.insert(job_menu.items, {"'.. _ ..'", "'.. i.salary ..'$", function(id) Player[id].job = "'.. _ ..'"; '.. cmd ..' UpdateHud(id); end});'))();
  2168.     end
  2169. end
  2170.  
  2171.  
  2172. function jobUse(id)
  2173.     local x, y = player(id, "tilex"), player(id, "tiley");
  2174.     local dir = math.floor((player(id, "rot") + 45) / 90) % 4;
  2175.     if dir == 0 then
  2176.         y = y - 1;
  2177.     elseif dir == 1 then
  2178.         x = x + 1;
  2179.     elseif dir == 2 then
  2180.         y = y + 1;
  2181.     else
  2182.         x = x - 1;
  2183.     end
  2184.    
  2185.     if entity(x, y, "exists") then
  2186.         if entity(x, y, "type") == 71 then
  2187.             if entity(x, y, "name") == Player[id].job then
  2188.                 parse("triggerposition ".. x .." ".. y);
  2189.             end
  2190.         end
  2191.     end
  2192. end
  2193. ------------------------------
  2194. ----- TARDIS MOD F ADMINS ----
  2195. ------------------------------
  2196. doctorwho={}
  2197.  
  2198. function initArray2(f,v)
  2199.     local cmd={}
  2200.     for c=1,f do
  2201.         cmd[c]=v
  2202.     end
  2203.     return cmd
  2204. end
  2205.  
  2206. function doublearray(m,n,k)
  2207.     local a, x, y = {}
  2208.     for x = 0, m do a[x] = {}
  2209.         for y = 0, n do
  2210.             a[x][y] = k
  2211.         end
  2212.     end
  2213.     return a
  2214. end
  2215.  
  2216. function sound3(tilex,tiley,rangex,rangey,sound)
  2217.     -- Ranges are tiles!
  2218.     for pl=1,32 do
  2219.         if (player(pl,"exists")) then
  2220.             if (player(pl,"tilex")>=tilex-rangex and player(pl,"tiley")>=tiley-rangey and player(pl,"tilex")<=tilex+rangex and player(pl,"tiley")<=tiley+rangey) then
  2221.                 parse("sv_sound2 "..pl.." \""..sound.."\"")
  2222.             end
  2223.         end
  2224.     end
  2225. end
  2226.  
  2227. doctorwho.tardis={}
  2228.  
  2229. doctorwho.tardis.current=0
  2230. doctorwho.tardis.next=1
  2231. doctorwho.tardis.limit=game("sv_maxplayers") --only one TARDIS per player
  2232. doctorwho.tardis.owner=initArray2(doctorwho.tardis.limit,0)
  2233.  
  2234. doctorwho.tardis.pos=doublearray(doctorwho.tardis.limit,4,0) --1 is px x, 2 is px y, 3 is tile x, 4 is tile y
  2235. doctorwho.tardis.image=initArray2(doctorwho.tardis.limit,0) -- the box itself
  2236. doctorwho.tardis.gimage=initArray2(doctorwho.tardis.limit,0) -- the ghost box image (appearing when materializing)
  2237. doctorwho.tardis.light=initArray2(doctorwho.tardis.limit,0) -- the light that will be blinking while the TARDIS is dematerializing/rematerializing
  2238. doctorwho.tardis.glight=initArray2(doctorwho.tardis.limit,0) -- the light that will be blinking while the ghost TARDIS is materializing
  2239. doctorwho.tardis.destination=doublearray(doctorwho.tardis.limit,2,0) --1 is tile x, 2 is tile y
  2240.  
  2241. doctorwho.tardis.defaultimg="gfx/doctorwho/tardis.png"
  2242. doctorwho.tardis.recolor=false -- does the image need recoloring?
  2243. doctorwho.tardis.color=initArray2(3,0) -- use if image needs recoloring
  2244.  
  2245. doctorwho.tardis.color[1]=0 -- R
  2246. doctorwho.tardis.color[2]=0 -- G
  2247. doctorwho.tardis.color[3]=255 -- B
  2248.  
  2249. playerSittingIn=doublearray(doctorwho.tardis.limit,doctorwho.tardis.limit,false)
  2250. playerSitting=initArray2(doctorwho.tardis.limit,initArray2(doctorwho.tardis.limit,0))
  2251. tardisIn=initArray2(doctorwho.tardis.limit,0)
  2252. tardisOf=initArray2(doctorwho.tardis.limit,0)
  2253. canBeInteracted=initArray2(doctorwho.tardis.limit,true)
  2254.  
  2255. playerSpeedmod=initArray2(doctorwho.tardis.limit,0)
  2256. playerArmor=initArray2(doctorwho.tardis.limit,0)
  2257. playerMomentum=initArray2(doctorwho.tardis.limit,0)
  2258. angularMomentum=initArray2(doctorwho.tardis.limit,0)
  2259. acceleration=0.8
  2260. angAcceleration=0.4
  2261. angle=initArray2(doctorwho.tardis.limit,0)
  2262.  
  2263. sonicSoundReady=initArray2(doctorwho.tardis.limit,true)
  2264. cloisterReady=initArray2(doctorwho.tardis.limit,true)
  2265. hasSonic=initArray2(doctorwho.tardis.limit,false)
  2266.  
  2267. doctorwho.regenerating=initArray2(doctorwho.tardis.limit,false)
  2268. doctorwho.regenglow=initArray2(doctorwho.tardis.limit,0)
  2269. recoveringhp=initArray2(doctorwho.tardis.limit,false)
  2270. srecoveringhp=initArray2(doctorwho.tardis.limit,false)
  2271. doctorwho.regencycles=initArray2(doctorwho.tardis.limit,13)
  2272.  
  2273. flyMode=initArray2(doctorwho.tardis.limit,false)
  2274. piloting=initArray2(doctorwho.tardis.limit,0)
  2275. flying=initArray2(doctorwho.tardis.limit,false)
  2276. pilot=initArray2(doctorwho.tardis.limit,0)
  2277. enteringCoordinates=initArray2(doctorwho.tardis.limit,false)
  2278. matloop=initArray2(doctorwho.tardis.limit,false)
  2279.  
  2280. doctorwho.admins={6943}
  2281.  
  2282. function contains(table, element)
  2283.     for _, value in pairs(table) do
  2284.         if value == element then
  2285.             return true
  2286.         end
  2287.     end
  2288.     return false
  2289. end
  2290.  
  2291. function showkey(table, element)
  2292.     for key, value in pairs(table) do
  2293.         if value == element then
  2294.             return key
  2295.         end
  2296.     end
  2297.     return false
  2298. end
  2299.  
  2300. function createTARDIS(ply,x,y)
  2301.     if (doctorwho.tardis.next<tonumber(doctorwho.tardis.limit)) then
  2302.         doctorwho.tardis.image[doctorwho.tardis.next]=image(doctorwho.tardis.defaultimg,x*32+16,y*32+16,1)
  2303.         if (doctorwho.tardis.recolor) then
  2304.             imagecolor(doctorwho.tardis.image[doctorwho.tardis.next],doctorwho.tardis.color[1],doctorwho.tardis.color[2],doctorwho.tardis.color[3])
  2305.         end
  2306.         doctorwho.tardis.gimage[doctorwho.tardis.next]=image(doctorwho.tardis.defaultimg,x*32+16,y*32+16,1)
  2307.         if (doctorwho.tardis.recolor) then
  2308.             imagecolor(doctorwho.tardis.gimage[doctorwho.tardis.next],doctorwho.tardis.color[1],doctorwho.tardis.color[2],doctorwho.tardis.color[3])
  2309.         end
  2310.        
  2311.         doctorwho.tardis.light[doctorwho.tardis.next]=image("gfx/sprites/flare3.bmp",x*32+16,y*32+16,1)
  2312.         doctorwho.tardis.glight[doctorwho.tardis.next]=image("gfx/sprites/flare3.bmp",x*32+16,y*32+16,1)
  2313.         imagealpha(doctorwho.tardis.light[doctorwho.tardis.next],0)
  2314.         imagealpha(doctorwho.tardis.glight[doctorwho.tardis.next],0)
  2315.         imageblend(doctorwho.tardis.light[doctorwho.tardis.next],1)
  2316.         imageblend(doctorwho.tardis.glight[doctorwho.tardis.next],1)
  2317.         imagescale(doctorwho.tardis.light[doctorwho.tardis.next],0.3,0.3)
  2318.         imagescale(doctorwho.tardis.glight[doctorwho.tardis.next],0.3,0.3)
  2319.        
  2320.        
  2321.         imagealpha(doctorwho.tardis.gimage[doctorwho.tardis.next],0)
  2322.         doctorwho.tardis.owner[doctorwho.tardis.next]=ply
  2323.         doctorwho.tardis.pos[doctorwho.tardis.next][1]=x*32+16
  2324.         doctorwho.tardis.pos[doctorwho.tardis.next][2]=y*32+16
  2325.         doctorwho.tardis.pos[doctorwho.tardis.next][3]=x
  2326.         doctorwho.tardis.pos[doctorwho.tardis.next][4]=y
  2327.         doctorwho.tardis.current=doctorwho.tardis.current+1
  2328.         doctorwho.tardis.next=doctorwho.tardis.next+1
  2329.     end
  2330. end
  2331.  
  2332. function blinkTARDIS(id,deg)
  2333.     if (deg==1) then
  2334.         tween_alpha(doctorwho.tardis.image[id],1000,0.5)
  2335.         tween_alpha(doctorwho.tardis.light[id],1000,1)
  2336.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.image[id]..",1000,1)")
  2337.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.light[id]..",1000,0)")
  2338.     end
  2339.     if (deg==2) then
  2340.         tween_alpha(doctorwho.tardis.image[id],1000,0.25)
  2341.         tween_alpha(doctorwho.tardis.light[id],1000,1)
  2342.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.image[id]..",1000,0.5)")
  2343.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.light[id]..",1000,0)")
  2344.     end
  2345.     if (deg==3) then
  2346.         tween_alpha(doctorwho.tardis.image[id],1000,0)
  2347.         tween_alpha(doctorwho.tardis.light[id],1000,1)
  2348.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.image[id]..",1000,0.25)")
  2349.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.light[id]..",1000,0)")
  2350.     end
  2351.     if (deg==1.2) then
  2352.         tween_alpha(doctorwho.tardis.image[id],1000,0)
  2353.         tween_alpha(doctorwho.tardis.light[id],1000,0)
  2354.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.image[id]..",1000,1)")
  2355.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.light[id]..",1000,1)")
  2356.     end
  2357.     if (deg==2.2) then
  2358.         tween_alpha(doctorwho.tardis.image[id],1000,0)
  2359.         tween_alpha(doctorwho.tardis.light[id],1000,0)
  2360.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.image[id]..",1000,0.5)")
  2361.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.light[id]..",1000,1)")
  2362.     end
  2363.     if (deg==3.2) then
  2364.         tween_alpha(doctorwho.tardis.image[id],1000,0)
  2365.         tween_alpha(doctorwho.tardis.light[id],1000,0)
  2366.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.image[id]..",1000,0.25)")
  2367.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.light[id]..",1000,1)")
  2368.     end
  2369. end
  2370.  
  2371. function blinkGhostTARDIS(id,deg)
  2372.     if (deg==1) then
  2373.         tween_alpha(doctorwho.tardis.gimage[id],1000,1)
  2374.         tween_alpha(doctorwho.tardis.glight[id],1000,1)
  2375.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.gimage[id]..",1000,0.5)")
  2376.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.glight[id]..",1000,0)")
  2377.     end
  2378.     if (deg==2) then
  2379.         tween_alpha(doctorwho.tardis.gimage[id],1000,0.5)
  2380.         tween_alpha(doctorwho.tardis.glight[id],1000,1)
  2381.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.gimage[id]..",1000,0.25)")
  2382.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.glight[id]..",1000,0)")
  2383.     end
  2384.     if (deg==3) then
  2385.         tween_alpha(doctorwho.tardis.gimage[id],1000,0.25)
  2386.         tween_alpha(doctorwho.tardis.glight[id],1000,1)
  2387.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.gimage[id]..",1000,0)")
  2388.         timer(1000,"parse","lua tween_alpha("..doctorwho.tardis.glight[id]..",1000,0)")
  2389.     end
  2390. end
  2391.  
  2392. function transportPlayer(id,dx,dy)
  2393.     for ply=1,doctorwho.tardis.limit do
  2394.         if (playerSittingIn[id][ply]) then
  2395.             parse("setpos "..ply.." "..((dx*32)+16).." "..((dy*32)+16))
  2396.         end
  2397.     end
  2398. end
  2399.  
  2400. function updatePosition(id,x,y)
  2401.     doctorwho.tardis.pos[id][1]=x*32+16
  2402.     doctorwho.tardis.pos[id][2]=y*32+16
  2403.     doctorwho.tardis.pos[id][3]=x
  2404.     doctorwho.tardis.pos[id][4]=y
  2405. end
  2406.  
  2407. function changePosition(id,dx,dy)
  2408.     if (flying[id]) then
  2409.         freeimage(doctorwho.tardis.image[id])
  2410.         doctorwho.tardis.image[id]=image("gfx/doctorwho/tardis.png",0,0,200+doctorwho.tardis.owner[id])
  2411.         tween_rotateconstantly(doctorwho.tardis.image[id],5)
  2412.     else
  2413.         imagepos(doctorwho.tardis.image[id],dx*32+16,dy*32+16,0)
  2414.         imagepos(doctorwho.tardis.light[id],dx*32+16,dy*32+16,0)
  2415.     end
  2416. end
  2417.  
  2418. function transportTARDIS(id,dx,dy)
  2419.     flyMode[playerSitting[id][doctorwho.tardis.owner[id]]]=false
  2420.     piloting[playerSitting[id][doctorwho.tardis.owner[id]]]=0
  2421.     flying[id]=false
  2422.     pilot[id]=0
  2423.     freeimage(doctorwho.tardis.image[id])
  2424.     doctorwho.tardis.image[id]=image(doctorwho.tardis.defaultimg,(player(id,"tilex")*32+16),(player(id,"tiley")*32+16),1)
  2425.     tween_rotate(doctorwho.tardis.image[id],1500,0)
  2426.     parse("speedmod "..id.." -100")
  2427.     parse("setpos "..id.." "..(player(id,"tilex")*32+16).." "..(player(id,"tiley")*32+16))
  2428.     canBeInteracted[id]=false
  2429.     sound3(doctorwho.tardis.pos[id][3],doctorwho.tardis.pos[id][4],8,8,"doctorwho/tardis_takeoff.ogg")
  2430.     sound3(dx,dy,8,8,"doctorwho/tardis_land.ogg")
  2431.     doctorwho.tardis.gimage[id]=image(doctorwho.tardis.defaultimg,dx*32+16,dy*32+16,1)
  2432.    
  2433.     doctorwho.tardis.glight[id]=image("gfx/sprites/flare3.bmp",(player(id,"tilex")*32+16),(player(id,"tiley")*32+16),1)
  2434.     imagealpha(doctorwho.tardis.glight[id],0)
  2435.     imageblend(doctorwho.tardis.glight[id],1)
  2436.     imagescale(doctorwho.tardis.glight[id],0.3,0.3)
  2437.    
  2438.     if (doctorwho.tardis.recolor) then
  2439.         imagecolor(doctorwho.tardis.gimage[id],doctorwho.tardis.color[1],doctorwho.tardis.color[2],doctorwho.tardis.color[3])
  2440.     end
  2441.     imagealpha(doctorwho.tardis.gimage[id],0)
  2442.     imagepos(doctorwho.tardis.gimage[id],dx*32+16,dy*32+16,0)
  2443.    
  2444.     imagepos(doctorwho.tardis.glight[id],dx*32+16,dy*32+16,0)
  2445.    
  2446.     timer(6500,"parse","lua blinkTARDIS("..id..",1)")
  2447.     timer(8500,"parse","lua blinkTARDIS("..id..",1)")
  2448.     timer(10500,"parse","lua blinkTARDIS("..id..",2)")
  2449.     timer(10500,"parse","lua blinkGhostTARDIS("..id..",3)")
  2450.     timer(12500,"parse","lua blinkTARDIS("..id..",3)")
  2451.     timer(12500,"parse","lua blinkGhostTARDIS("..id..",3)")
  2452.     timer(14500,"parse","lua changePosition("..id..","..dx..","..dy..")")
  2453.     timer(14500,"parse","lua freeimage(doctorwho.tardis.gimage["..id.."])")
  2454.     timer(14500,"parse","lua freeimage(doctorwho.tardis.glight["..id.."])")
  2455.     timer(14500,"parse","lua transportPlayer("..id..","..dx..","..dy..")")
  2456.     timer(14500,"parse","lua blinkTARDIS("..id..",3.2)")
  2457.     timer(16500,"parse","lua blinkTARDIS("..id..",2.2)")
  2458.     timer(18500,"parse","lua blinkTARDIS("..id..",1.2)")
  2459.     timer(20500,"parse","lua updatePosition("..id..","..dx..","..dy..")")
  2460.     timer(20500,"parse","lua tween_alpha(doctorwho.tardis.light["..id.."],1000,0)")
  2461.     timer(21000,"parse","lua canBeInteracted["..id.."]=true")
  2462. end
  2463.  
  2464.  
  2465. function doctorwho.tardis.plyenter(id)
  2466.     for t=1,doctorwho.tardis.current do
  2467.         if (canBeInteracted[t] and player(id,"team")==2) then
  2468.             if (player(id,"tilex")==doctorwho.tardis.pos[t][3] and player(id,"tiley")==doctorwho.tardis.pos[t][4]) then
  2469.                 if (not contains(playerSitting[t],id)) then
  2470.                     parse("setpos "..id.." "..(doctorwho.tardis.pos[t][3]*32+16).." "..(doctorwho.tardis.pos[t][4]*32+16))
  2471.                     playerSpeedmod[id]=player(id,"speedmod")
  2472.                     parse("speedmod "..id.." -100")
  2473.                     playerSittingIn[t][id]=true
  2474.                     table.insert(playerSitting[t],id)
  2475.                     tardisIn[id]=t
  2476.                 elseif (contains(playerSitting[t],id)) then
  2477.                     if (flyMode[id]) then
  2478.                         flyMode[id]=false
  2479.                         piloting[id]=0
  2480.                         flying[tardisIn[id]]=false
  2481.                         pilot[tardisIn[id]]=0
  2482.                         freeimage(doctorwho.tardis.image[tardisIn[id]])
  2483.                         doctorwho.tardis.image[tardisIn[id]]=image(doctorwho.tardis.defaultimg,(player(id,"tilex")*32+16),(player(id,"tiley")*32+16),1)
  2484.                         tween_rotate(doctorwho.tardis.image[tardisIn[id]],1500,0)
  2485.                         parse("setpos "..id.." "..(player(id,"tilex")*32+16).." "..(player(id,"tiley")*32+16))
  2486.                     end
  2487.                     parse("speedmod "..id.." "..playerSpeedmod[id])
  2488.                     tardisIn[id]=0
  2489.                     local key=showkey(playerSitting[t],id)
  2490.                     table.remove(playerSitting[t],key)
  2491.                 end
  2492.             end
  2493.         end
  2494.     end
  2495. end
  2496.  
  2497.  
  2498. function activateNearbyTriggers(id)
  2499.     if (entity(player(id,"tilex"),player(id,"tiley"),"exists")) then
  2500.         --parse("trigger "..entity(player(id,"tilex"),player(id,"tiley"),"name"))
  2501.         parse("trigger "..entity(player(id,"tilex"),player(id,"tiley"),"trigger"))
  2502.     end
  2503.     if (entity(player(id,"tilex")+1,player(id,"tiley"),"exists")) then
  2504.         --parse("trigger "..entity(player(id,"tilex")+1,player(id,"tiley"),"name"))
  2505.         parse("trigger "..entity(player(id,"tilex")+1,player(id,"tiley"),"trigger"))
  2506.     end
  2507.     if (entity(player(id,"tilex")-1,player(id,"tiley"),"exists")) then
  2508.         --parse("trigger "..entity(player(id,"tilex")-1,player(id,"tiley"),"name"))
  2509.         parse("trigger "..entity(player(id,"tilex")-1,player(id,"tiley"),"trigger"))
  2510.     end
  2511.     if (entity(player(id,"tilex"),player(id,"tiley")-1,"exists")) then
  2512.         --parse("trigger "..entity(player(id,"tilex"),player(id,"tiley")-1,"name"))
  2513.         parse("trigger "..entity(player(id,"tilex"),player(id,"tiley")-1,"trigger"))
  2514.     end
  2515.     if (entity(player(id,"tilex"),player(id,"tiley")+1,"exists")) then
  2516.         --parse("trigger "..entity(player(id,"tilex"),player(id,"tiley")+1,"name"))
  2517.         parse("trigger "..entity(player(id,"tilex"),player(id,"tiley")+1,"trigger"))
  2518.     end
  2519.     if (entity(player(id,"tilex")-1,player(id,"tiley")-1,"exists")) then
  2520.         --parse("trigger "..entity(player(id,"tilex")-1,player(id,"tiley")-1,"name"))
  2521.         parse("trigger "..entity(player(id,"tilex")-1,player(id,"tiley")-1,"trigger"))
  2522.     end
  2523.     if (entity(player(id,"tilex")-1,player(id,"tiley")+1,"exists")) then
  2524.         --parse("trigger "..entity(player(id,"tilex")-1,player(id,"tiley")+1,"name"))
  2525.         parse("trigger "..entity(player(id,"tilex")-1,player(id,"tiley")+1,"trigger"))
  2526.     end
  2527.     if (entity(player(id,"tilex")+1,player(id,"tiley")+1,"exists")) then
  2528.         --parse("trigger "..entity(player(id,"tilex")+1,player(id,"tiley")+1,"name"))
  2529.         parse("trigger "..entity(player(id,"tilex")+1,player(id,"tiley")+1,"trigger"))
  2530.     end
  2531.     if (entity(player(id,"tilex")+1,player(id,"tiley")-1,"exists")) then
  2532.         --parse("trigger "..entity(player(id,"tilex")+1,player(id,"tiley")-1,"name"))
  2533.         parse("trigger "..entity(player(id,"tilex")+1,player(id,"tiley")-1,"trigger"))
  2534.     end
  2535. end
  2536.  
  2537. function csconvert(rot,x,y,factor)
  2538.     if rot<-90 then rot=rot+360 end
  2539.     local angle=math.rad(math.abs(rot+90))-math.pi
  2540.     local cx=x+(math.cos(angle)*factor)
  2541.     local cy=y+(math.sin(angle)*factor)
  2542.     return cx,cy
  2543. end
  2544.  
  2545. function toggleTrigger(id,mode)
  2546.     local xx,yy=csconvert(player(id,"rot"),player(id,"x"),player(id,"y"),32)
  2547.     local cx=math.floor(xx/32)
  2548.     local cy=math.floor(yy/32)
  2549.     local xx2,yy2=csconvert(player(id,"rot"),player(id,"x"),player(id,"y"),64)
  2550.     local cx2=math.floor(xx2/32)
  2551.     local cy2=math.floor(yy2/32)
  2552.     local tx=player(id,"tilex")
  2553.     local ty=player(id,"tiley")
  2554.     if (mode==1) then
  2555.         if (entity(cx,cy,"trigger") and entity(cx,cy,"trigger")~=nil) then
  2556.             parse("trigger "..entity(cx,cy,"trigger"))
  2557.         end
  2558.         if (entity(cx2,cy2,"trigger") and entity(cx2,cy2,"trigger")~=nil) then
  2559.             parse("trigger "..entity(cx2,cy2,"trigger"))
  2560.         end
  2561.         if (entity(tx,ty,"trigger") and entity(tx,ty,"trigger")~=nil) then
  2562.             parse("trigger "..entity(tx,ty,"trigger"))
  2563.         end
  2564.     elseif (mode==2) then
  2565.         if (entity(cx,cy,"name") and entity(cx,cy,"name")~=nil) then
  2566.             parse("trigger "..entity(cx,cy,"name"))
  2567.         end
  2568.         if (entity(cx2,cy2,"name") and entity(cx2,cy2,"name")~=nil) then
  2569.             parse("trigger "..entity(cx2,cy2,"name"))
  2570.         end
  2571.         if (entity(tx,ty,"name") and entity(tx,ty,"name")~=nil) then
  2572.             parse("trigger "..entity(tx,ty,"name"))
  2573.         end
  2574.     end
  2575. end
  2576.  
  2577. plyposition=doublearray(32,3,0)
  2578.  
  2579. function isGoodPos(pos,ppos)
  2580.     if (pos==ppos) then
  2581.         return 0
  2582.     elseif (pos==nil) then
  2583.         return 0
  2584.     end
  2585.     return pos
  2586. end
  2587.  
  2588. --[[function findNearestPlayer(id)
  2589.     for fid=1,doctorwho.tardis.limit do
  2590.         if (player(fid,"exists") and fid~=id) then
  2591.             plyposition[fid][1]=player(fid,"tilex")
  2592.             plyposition[fid][2]=player(fid,"tiley")
  2593.             plyposition[fid][3]=plyposition[fid][1]+plyposition[fid][2]
  2594.         end
  2595.     end
  2596.     plyposition[id][3]=player(id,"tilex")+player(id,"tiley")
  2597.     plypositionmin=math.min(math.abs(plyposition[id][3]-isGoodPos(plyposition[1][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[2][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[3][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[4][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[5][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[6][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[7][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[8][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[9][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[10][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[11][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[12][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[13][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[14][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[15][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[16][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[17][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[18][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[19][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[20][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[21][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[22][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[23][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[24][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[25][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[26][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[27][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[28][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[29][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[30][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[31][3],plyposition[id][3])),math.abs(plyposition[id][3]-isGoodPos(plyposition[32][3],plyposition[id][3])))
  2598.     for fid=1,doctorwho.tardis.limit do
  2599.         if (player(fid,"exists") and fid~=id) then
  2600.             if (plypositionmin==math.abs(plyposition[id][3]-plyposition[fid][3])) then
  2601.                 msg("The nearest player is "..player(fid,"name").." ("..math.abs(plyposition[id][3]-plyposition[fid][3]).." tiles away)")
  2602.                 break
  2603.             else
  2604.                 msg("An error occured; could not find the nearest player!")
  2605.                 break
  2606.             end
  2607.         end
  2608.     end
  2609. end]]
  2610.  
  2611.  
  2612. function printPosition(id)
  2613.     msg("Sonic Screwdriver: your current position is TILES ("..player(id,"tilex").."|"..player(id,"tiley").."); PIXELS ("..math.floor(player(id,"x")).."|"..math.floor(player(id,"y"))..")")
  2614. end
  2615.  
  2616. function sonicMenu(id)
  2617.     menu(id,"Sonic Screwdriver,Toggle trigger,Toggle entity,Toggle nearby triggers,Print own position,Summon TARDIS")
  2618. end
  2619.  
  2620.  
  2621. function doctorwho.ssmenu(id,menu,sel)
  2622.     if (menu=="Sonic Screwdriver") then
  2623.         if (sel==1) then
  2624.             sound3(player(id,"tilex"),player(id,"tiley"),5,5,"weapons/sonic.ogg")
  2625.             timer(1000,"parse","lua toggleTrigger("..id..",1)")
  2626.         end
  2627.         if (sel==2) then
  2628.             sound3(player(id,"tilex"),player(id,"tiley"),5,5,"weapons/sonic.ogg")
  2629.             timer(1000,"parse","lua toggleTrigger("..id..",2)")
  2630.         end
  2631.         if (sel==3) then
  2632.             sound3(player(id,"tilex"),player(id,"tiley"),5,5,"weapons/sonic.ogg")
  2633.             timer(1000,"parse","lua activateNearbyTriggers("..id..")")
  2634.         end
  2635.         if (sel==4) then
  2636.             sound3(player(id,"tilex"),player(id,"tiley"),5,5,"weapons/sonic.ogg")
  2637.             timer(1000,"parse","lua printPosition("..id..")")
  2638.         end
  2639.         if (sel==5) then
  2640.             sound3(player(id,"tilex"),player(id,"tiley"),5,5,"weapons/sonic.ogg")
  2641.             for t=1,doctorwho.tardis.current do
  2642.                 if (doctorwho.tardis.owner[t]==id) then
  2643.                     transportTARDIS(t,player(id,"tilex"),player(id,"tiley"))
  2644.                     break
  2645.                 end
  2646.             end
  2647.         end
  2648.     end
  2649.     if (menu=="TARDIS Controls") then
  2650.         if (sel==1) then
  2651.             enteringCoordinates[id]=true
  2652.             msg2(id,"Enter destination coordinates (TILEX;TILEY)")
  2653.         end
  2654.         if (sel==2) then
  2655.             if (not flyMode[id]) then
  2656.                 flyMode[id]=true
  2657.                 piloting[id]=tardisIn[id]
  2658.                 flying[tardisIn[id]]=true
  2659.                 pilot[tardisIn[id]]=id
  2660.                 freeimage(doctorwho.tardis.image[tardisIn[id]])
  2661.                 doctorwho.tardis.image[tardisIn[id]]=image(doctorwho.tardis.defaultimg,0,0,200+id)
  2662.                 tween_rotateconstantly(doctorwho.tardis.image[tardisIn[id]],5)
  2663.                 freeimage(doctorwho.tardis.light[tardisIn[id]])
  2664.                 doctorwho.tardis.light[tardisIn[id]]=image("gfx/sprites/flare3.bmp",0,0,200+id)
  2665.                 imagealpha(doctorwho.tardis.light[tardisIn[id]],0)
  2666.                 imageblend(doctorwho.tardis.light[tardisIn[id]],1)
  2667.                 imagescale(doctorwho.tardis.light[tardisIn[id]],0.3,0.3)
  2668.                 parse("speedmod "..id.." "..playerSpeedmod[id])
  2669.             else
  2670.                 flyMode[id]=false
  2671.                 piloting[id]=0
  2672.                 flying[tardisIn[id]]=false
  2673.                 pilot[tardisIn[id]]=0
  2674.                 freeimage(doctorwho.tardis.image[tardisIn[id]])
  2675.                 doctorwho.tardis.image[tardisIn[id]]=image(doctorwho.tardis.defaultimg,(player(id,"tilex")*32+16),(player(id,"tiley")*32+16),1)
  2676.                 tween_rotate(doctorwho.tardis.image[tardisIn[id]],1500,0)
  2677.                 freeimage(doctorwho.tardis.light[tardisIn[id]])
  2678.                 doctorwho.tardis.light[tardisIn[id]]=image("gfx/sprites/flare3.bmp",(player(id,"tilex")*32+16),(player(id,"tiley")*32+16),1)
  2679.                 imagealpha(doctorwho.tardis.light[tardisIn[id]],0)
  2680.                 imageblend(doctorwho.tardis.light[tardisIn[id]],1)
  2681.                 imagescale(doctorwho.tardis.light[tardisIn[id]],0.3,0.3)
  2682.                 parse("speedmod "..id.." -100")
  2683.                 parse("setpos "..id.." "..(player(id,"tilex")*32+16).." "..(player(id,"tiley")*32+16))
  2684.             end
  2685.         end
  2686.         if (sel==3) then
  2687.             if (cloisterReady[tardisIn[id]]) then
  2688.                 cloisterReady[tardisIn[id]]=false
  2689.                 sound3(player(id,"tilex"),player(id,"tiley"),5,5,"doctorwho/cloisterbell.ogg")
  2690.                 timer(3000,"parse","lua cloisterReady["..tardisIn[id].."]=true")
  2691.             end
  2692.         end
  2693.     end
  2694. end
  2695.  
  2696.  
  2697. function doctorwho.hitrender(id,src,wpn,dmg)
  2698.     if (tardisIn[id]~=0) then
  2699.         return 1
  2700.     end
  2701.     if (player(id,"team")==2 and doctorwho.regencycles[id]>0 and dmg>=player(id,"maxhealth")) then
  2702.         parse("sethealth "..id.." 1")
  2703.         return 1
  2704.     end
  2705. end
  2706.  
  2707. function quickPlural(count)
  2708.     if (count>1) then
  2709.         return "s"
  2710.     elseif (count<-1) then
  2711.         return "s"
  2712.     end
  2713.     return ""
  2714. end
  2715.  
  2716.  
  2717. function doctorwho.sayprocess(id,t)
  2718.     if (contains(doctorwho.admins,player(id,"usgn"))) then
  2719.         if (t:sub(1,5)=="/give") then
  2720.             if (t:sub(7,11)=="sonic") then
  2721.                 local _=t:sub(13)
  2722.                 local tid=tonumber(_)
  2723.                 hasSonic[tid]=true
  2724.                 msg2(id,"You have given a sonic screwdriver to "..player(tid,"name"))
  2725.                 msg2(tid,player(id,"name").." has given you a sonic screwdriver")
  2726.             end
  2727.             if (t:sub(7,11)=="regen") then
  2728.                 local _=t:sub(13,14)
  2729.                 local __=t:sub(15)
  2730.                 local tid=tonumber(__)
  2731.                 local rc=tonumber(_)
  2732.                 doctorwho.regencycles[tid]=doctorwho.regencycles[tid]+rc
  2733.                 if (rc>0) then
  2734.                     msg2(id,"You have given "..rc.." regeneration"..quickPlural(rc).." to "..player(tid,"name"))
  2735.                     msg2(tid,player(id,"name").." has given you "..rc.." regeneration"..quickPlural(rc))
  2736.                 end
  2737.             end
  2738.             if (t:lower():sub(7,12)=="tardis") then
  2739.                 local _=t:sub(14)
  2740.                 local tid=tonumber(_)
  2741.                 createTARDIS(tid,player(tid,"tilex"),player(tid,"tiley"))
  2742.                 msg2(id,"You have given a TARDIS to "..player(tid,"name"))
  2743.                 msg2(tid,player(id,"name").." has given you a TARDIS")
  2744.             end
  2745.             return 1
  2746.         end
  2747.     end
  2748.     if (enteringCoordinates[id]) then
  2749.         if (tardisIn[id]~=0) then
  2750.             local divider=t:find(";")
  2751.             local c1=t:sub(1,divider-1)
  2752.             local c2=t:sub(divider+1)
  2753.             local x=tonumber(c1)
  2754.             local y=tonumber(c2)
  2755.             if (x>=0 and x<=map("xsize") and y>=0 and y<=map("ysize")) then
  2756.                 transportTARDIS(tardisIn[id],x,y)
  2757.                 enteringCoordinates[id]=false
  2758.             else
  2759.                 msg2(id,"©255000000ERROR: Invalid coordinates")
  2760.                 enteringCoordinates[id]=false
  2761.             end
  2762.         end
  2763.         return 1
  2764.     end
  2765. end
  2766.  
  2767. function doctorwho.regenerate(id)
  2768.     doctorwho.regenerating[id]=true
  2769.     doctorwho.regenglow[id]=image("gfx/sprites/flare2.bmp",1,0,200+id)
  2770.     imageblend(doctorwho.regenglow[id],1)
  2771.     imagecolor(doctorwho.regenglow[id],255,200,0)
  2772.     imagealpha(doctorwho.regenglow[id],0)
  2773.     tween_alpha(doctorwho.regenglow[id],10000,0.4)
  2774.     playerSpeedmod[id]=player(id,"speedmod")
  2775.     parse("speedmod "..id.." -25")
  2776.     timer(10000,"parse","lua tween_alpha(doctorwho.regenglow["..id.."],1000,0)")
  2777.     timer(10000,"parse","speedmod "..id.." -100")
  2778.     timer(11000,"parse","lua tween_alpha(doctorwho.regenglow["..id.."],1000,1)")
  2779.     timer(11000,"parse","lua sound3("..player(id,"tilex")..","..player(id,"tiley")..",8,8,\"doctorwho/regeneration.ogg\")")
  2780.     timer(12500,"parse","lua recoveringhp["..id.."]=true")
  2781.     timer(19250,"parse","lua tween_alpha(doctorwho.regenglow["..id.."],500,0)")
  2782.     timer(19750,"parse","speedmod "..id.." "..playerSpeedmod[id])
  2783. end
  2784.  
  2785.  
  2786. function doctorwho.abortregen(id)
  2787.     if (doctorwho.regenerating[id]) then
  2788.         doctorwho.regenerating[id]=false
  2789.         freetimer("parse","lua tween_alpha(doctorwho.regenglow["..id.."],1000,0)")
  2790.         freetimer("parse","lua playerSpeedmod["..id.."]=player("..id..",\"speedmod\")")
  2791.         freetimer("parse","speedmod "..id.." -100")
  2792.         freetimer("parse","lua tween_alpha(doctorwho.regenglow["..id.."],1000,1)")
  2793.         freetimer("parse","lua sound3("..player(id,"tilex")..","..player(id,"tiley")..",8,8,\"doctorwho/regeneration.ogg\")")
  2794.         freetimer("parse","lua recoveringhp["..id.."]=true")
  2795.         freetimer("parse","lua tween_alpha(doctorwho.regenglow["..id.."],500,0)")
  2796.         freetimer("parse","speedmod "..id.." "..playerSpeedmod[id])
  2797.         freeimage(doctorwho.regenglow[id])
  2798.     end
  2799. end
  2800.  
  2801. function matloopTransport(t)
  2802.     local x=math.random(0,map("xsize"))
  2803.     local y=math.random(0,map("ysize"))
  2804.     if (tile(x,y,"frame")~=0 and tile(x,y,"property")>=5 and tile(x,y,"property")<=15) then
  2805.         imagepos(doctorwho.tardis.image[t],x*32+16,y*32+16,0)
  2806.         if (playerSittingIn[t]) then
  2807.             transportPlayer(playerSitting[t],x,y)
  2808.         end
  2809.         updatePosition(t,x,y)
  2810.     else
  2811.         matloopTransport(t)
  2812.     end
  2813. end
  2814.  
  2815. tick=0
  2816. stick=0
  2817.  
  2818.  
  2819. function doctorwho.ms100()
  2820.     for id=1,doctorwho.tardis.limit do
  2821.         if (player(id,"exists") and player(id,"health")<=10 and player(id,"health")>0) then
  2822.             if (doctorwho.regencycles[id]>0) then
  2823.                 srecoveringhp[id]=false
  2824.                 doctorwho.regenerate(id)
  2825.                 parse("sethealth "..id.." 11")
  2826.                 doctorwho.regencycles[id]=doctorwho.regencycles[id]-1
  2827.             end
  2828.         end
  2829.         if (player(id,"exists") and recoveringhp[id]) then
  2830.             if (player(id,"health")<player(id,"maxhealth")) then
  2831.                 if (tick<65) then
  2832.                     parse("sethealth "..id.." "..player(id,"health")+1)
  2833.                     tick=tick+1
  2834.                 else
  2835.                     tick=0
  2836.                     recoveringhp[id]=false
  2837.                     srecoveringhp[id]=true
  2838.                 end
  2839.             end
  2840.             local rnd=math.random(75,100)/100
  2841.             imagealpha(doctorwho.regenglow[id],rnd)
  2842.         end
  2843.         if (player(id,"exists") and srecoveringhp[id]) then
  2844.             if (player(id,"health")<player(id,"maxhealth")) then
  2845.                 tick=tick+0.5
  2846.                 if (tick==7.5) then
  2847.                     parse("sethealth "..id.." "..player(id,"health")+1)
  2848.                     tick=0
  2849.                 end
  2850.             else
  2851.                 srecoveringhp[id]=false
  2852.             end
  2853.         end
  2854.         for t=1,doctorwho.tardis.current do
  2855.             if (matloop[t]) then
  2856.                 matloopTransport(t)
  2857.             end
  2858.         end
  2859.     end
  2860.     stick=stick+0.1
  2861. end
  2862.  
  2863.  
  2864. function doctorwho.sonicscrewdriver(id,a)
  2865.     if (a==3) then
  2866.         if (hasSonic[id]) then
  2867.             if (sonicSoundReady[id] and player(id,"team")==2) then
  2868.                 sound3(player(id,"tilex"),player(id,"tiley"),5,5,"doctorwho/sonicextend.ogg")
  2869.                 sonicSoundReady[id]=false
  2870.                 sonicMenu(id)
  2871.                 timer(1000,"parse","lua sonicSoundReady["..id.."]=true")
  2872.             end
  2873.         end
  2874.     end
  2875. end
  2876.  
  2877. function tardismenu(id)
  2878.     menu(id,"TARDIS Controls,Teleport,Toggle Flying,Ring Cloister Bell")
  2879. end
  2880.  
  2881.  
  2882.  
  2883. function doctorwho.tardiscontrols(id,a)
  2884.     if (a==1) then
  2885.         if (tardisIn[id]~=0 and doctorwho.tardis.owner[tardisIn[id]]==id) then
  2886.             tardismenu(id)
  2887.         end
  2888.     end
  2889. end
  2890.  
  2891. mtick=0
  2892.  
  2893.  
  2894. function doctorwho.second()
  2895.     mtick=mtick+1
  2896.     for id=1,32 do
  2897.         if (player(id,"exists") and flying[tardisIn[id]]) then
  2898.             if (stick>=1) then
  2899.                 sound3(player(id,"tilex"),player(id,"tiley"),5,5,"doctorwho/inflight.ogg")
  2900.                 imagescale(doctorwho.tardis.light[tardisIn[id]],0.3,0.3)
  2901.                 tween_alpha(doctorwho.tardis.light[tardisIn[id]],1000,1)
  2902.                 timer(1000,"parse","lua tween_alpha(doctorwho.tardis.light["..tardisIn[id].."],1000,0)")
  2903.                 stick=0
  2904.             end
  2905.         end
  2906.     end
  2907.     for t=1,doctorwho.tardis.current do
  2908.         if (matloop[t]) then
  2909.             if (mtick>=2) then
  2910.                 mtick=0
  2911.                 parse("sv_sound2 "..playerSitting[t].." \"doctorwho/matloop.ogg\"")
  2912.             end
  2913.         end
  2914.     end
  2915. end
  2916.  
  2917.  
  2918. function doctorwho.movetile(id,x,y)
  2919.     if (flyMode[id]) then
  2920.         doctorwho.tardis.pos[tardisIn[id]][1]=player(id,"x")
  2921.         doctorwho.tardis.pos[tardisIn[id]][2]=player(id,"y")
  2922.         doctorwho.tardis.pos[tardisIn[id]][3]=x
  2923.         doctorwho.tardis.pos[tardisIn[id]][4]=y
  2924.     end
  2925. end
  2926.  
  2927.  
  2928.  
  2929.  
  2930.  
  2931. ----------------------------------------------------------------------------------------
  2932. ---------  IMPORTANT! CHECK THESE |||| CONFIGS ||||BEFORE YOU RUN THE SERVER   ---------
  2933. ----------------------------------------------------------------------------------------
  2934. payday_time = 120; -- Minutes
  2935. --sms_cost = 0.5;
  2936. radar_hide = true;
  2937. --car_lic_cost = 120000;
  2938. --fly_lic_cost = 350000;
  2939. mp_hud = 0;
  2940. --bike_lic_cost = 100000;
  2941. --ship_lic_cost = 200000;
  2942. train_cost = 5;
  2943. train_wait = 3;
  2944. max_cars = 55;
  2945. ownable_cars_max = 3;
  2946. inv_items_max = 30;
  2947. --max_atms = 40;
  2948. --cRED = "©255000000";
  2949. --cGREEN = "©000255000";
  2950. --cBLUE = "©000000255";
  2951. --cBLACK = "©000000000";
  2952. --cWHITE = "©255255255";
  2953. --cWBLUE = "©000190255";
  2954. --cGREEN_DARK = "©000100000"
  2955. -- ===[ Dzień wypłaty ]===
  2956. payday_enabled = true; -- czy dzień wypłaty jest włączony (true/false)
  2957. payday_text = "©255255255Payday! {AMOUNT}$"; -- tekst zostanie wyświetlony podczas wypłaty, {AMOUNT} zostanie automatycznie zamienione na payday_money
  2958. payday_money_multiplier = 1.0; -- jeśli np. ktoś zarabia 1000$ to jeśli multiplier jest 2.0 to dostanie 2000$
  2959.  
  2960. -- ===[ HUD ]===
  2961. hud_x = 520;
  2962. hud_y = 240;
  2963.  
  2964. -- ===[ Plecak ]===
  2965.  
  2966. --[[
  2967.  
  2968.     WornWeapons.lua
  2969.         Config file
  2970.     by Alistaire
  2971.  
  2972. --]]
  2973.  
  2974. weaponTiers = {
  2975.  
  2976. -- Secondary
  2977.     [1] = 0,
  2978.     [2] = 0,
  2979.     [3] = 4,
  2980.     [4] = 1,
  2981.     [5] = 2,
  2982.     [6] = 3,
  2983.  
  2984. -- Primary
  2985.     [10] = 7,
  2986.     [11] = 7,
  2987.     [20] = 3,
  2988.     [21] = 0,
  2989.     [22] = 4,
  2990.     [23] = 0,
  2991.     [24] = 2,
  2992.     [30] = 5,
  2993.     [31] = 6,
  2994.     [32] = 5,
  2995.     [33] = 6,
  2996.     [34] = 9,
  2997.     [35] = 10,
  2998.     [36] = 8,
  2999.     [37] = 8,
  3000.     [38] = 4,
  3001.     [39] = 4,
  3002.     [40] = 9,
  3003.     [45] = 13,
  3004.     [47] = 12,
  3005.     [48] = 10,
  3006.     [49] = 10,
  3007.     [88] = 11,
  3008.     [90] = 9,
  3009.     [91] = 6,
  3010.    
  3011. -- Spec
  3012.     [41] = 'spec',
  3013.     [46] = 'spec',
  3014.     [85] = 'spec',
  3015.  
  3016. -- Melee
  3017.     [50] = 0,
  3018.     [69] = 2,
  3019.     [74] = 1
  3020.    
  3021. }
  3022.  
  3023. specTable = {
  3024.  
  3025.     [41] = 1,
  3026.     [46] = 2,
  3027.     [85] = 0
  3028.  
  3029. }
  3030.  
  3031. ----------------------------------
  3032. --**    HAARP SERVER START    **--
  3033. ----------------------------------
  3034. parse("trigger quake_start")
  3035. parse("trigger haarp_demon")
  3036.  
  3037.  
  3038. ----------------------------------
  3039. --**        ADMIN DUTY        **--
  3040. ----------------------------------
  3041.  
  3042.  
  3043.  
  3044. ----------------------------------
  3045. ------- SAVE LAST POSITION -------
  3046. ----------------------------------
  3047. pos = {}
  3048.  
  3049.  
  3050.  
  3051. function AA_join(id)
  3052.      if io.open('sys/lua/saves/pos'..player(id, 'usgn')..'.lua') then
  3053.           dofile('sys/lua/saves/pos'..player(id, 'usgn')..'.lua')
  3054.           os.remove('sys/lua/saves/pos'..player(id, 'usgn')..'.lua')
  3055.      end
  3056. end
  3057.  
  3058. function AA_leave(id)
  3059.      local file = io.open('sys/lua/saves/pos'..player(id, 'usgn')..'.lua', 'w')
  3060.      file:write('pos['..player(id, 'usgn')..'] = {'..player(id, 'x')..','..player(id, 'y')..'}')
  3061. end
  3062.  
  3063. function AA_spawn(id)
  3064.      if io.open('sys/lua/saves/pos'..player(id, 'usgn')..'.lua') then
  3065.           parse('setpos '..id..' '..pos[player(id, 'usgn')][1]..' '..pos[player(id, 'usgn')][2])
  3066.      end
  3067. end
  3068. ----------------------------------
  3069. ---- TRAVEL TO ANOTHER CITY ------
  3070. ----------------------------------
  3071. -- Travel System by Salad Fingers --
  3072. ------------------------------------
  3073.  
  3074. Map = {
  3075.      ["116,239"] = {
  3076.           IP = "localhost:36969",
  3077.           Name = "Gold Village"
  3078.      }
  3079. }
  3080.  
  3081. HookMoveTile = function(id, x, y)
  3082.      if Map[x..","..y] then
  3083.           msg2(id, "Click use key (\"e\") to enter location: "..Map[x..","..y].Name)
  3084.      end
  3085. end
  3086.  
  3087. HookUse = function(id)
  3088.      if Map[player(id, "tilex")..","..player(id, "tiley")] then
  3089.           parse("reroute "..id.." "..Map[player(id, "tilex")..","..player(id, "tiley")].IP.."")
  3090.      end
  3091. end
  3092.  
  3093. ----------------------------------
  3094. --**     INFOBAR IMG & TEXT   **--
  3095. ----------------------------------
  3096.  
  3097. --addhook('second','_secondHook')
  3098.  
  3099. --function _secondHook()
  3100.   --   for _, id in pairs(player(0, 'tableliving')) do
  3101.     --      if player(id, 'health')/player(id, 'maxhealth') <= 0.3 then
  3102.    --            parse('sv_sound2 '..id..' heart.wav')
  3103.    --       end
  3104.   --   end
  3105. --end
  3106.  
  3107. ------------------------------
  3108. ----- WRAPPER ----------------
  3109. ------------------------------
  3110. -------------------------------------------------------------------
  3111. -- Wrapper functions for easy usage of CS2D commands in Lua      --
  3112. -- 25.03.2011 - www.UnrealSoftware.de                            --
  3113. -------------------------------------------------------------------
  3114.  
  3115. -------------------------------------------------------------------
  3116. -- These functions make it easier to use CS2D commands in Lua    --
  3117. -- They call the parse functions with the fitting parameters     --
  3118. --                                                               --
  3119. -- Example without wrapper function:                             --
  3120. -- parse("spawnplayer "..id.." "..x.." " ..y)                    --
  3121. --                                                               --
  3122. -- Example with wrapper function:                                --
  3123. -- spawnplayer(id,x,y)                                           --
  3124. --                                                               --
  3125. -- Both examples do exactly the same but using the wrapper       --
  3126. -- function is much easier and not as error-prone as using parse.--
  3127. -- Therefore it is recommended to use the wrapper functions.     --
  3128. --                                                               --
  3129. -- Use the following line to include the wrapper in your script: --
  3130. -- if wrapper~=true then dofile("sys/lua/wrapper.lua") end       --
  3131. -------------------------------------------------------------------
  3132.  
  3133. -- Set Wrapper state to LOADED/TRUE!
  3134. wrapper=true
  3135.  
  3136. -- Functions
  3137. function bot_add()
  3138.     parse("bot_add")
  3139. end
  3140.  
  3141. function bot_add_ct()
  3142.     parse("bot_add_ct")
  3143. end
  3144.  
  3145. function bot_add_t()
  3146.     parse("bot_add_t")
  3147. end
  3148.  
  3149. function bot_count(count)
  3150.     parse("bot_count "..count)
  3151. end
  3152.  
  3153. function bot_jointeam(team)
  3154.     parse("bot_jointeam "..team)
  3155. end
  3156.  
  3157. function bot_kill()
  3158.     parse("bot_kill")
  3159. end
  3160.  
  3161. function bot_prefix(prefix)
  3162.     parse("bot_prefix "..prefix)
  3163. end
  3164.  
  3165. function bot_remove()
  3166.     parse("bot_remove")
  3167. end
  3168.  
  3169. function bot_remove_all()
  3170.     parse("bot_remove_all")
  3171. end
  3172.  
  3173. function bot_remove_ct()
  3174.     parse("bot_remove_ct")
  3175. end
  3176.  
  3177. function bot_remove_t()
  3178.     parse("bot_remove_t")
  3179. end
  3180.  
  3181. function bot_skill(skill)
  3182.     parse("bot_skill "..skill)
  3183. end
  3184.  
  3185. function bot_weapons(weapons)
  3186.     parse("bot_weapons "..weapons)
  3187. end
  3188.  
  3189. function changelevel(map)
  3190.     parse("changelevel "..map)
  3191. end
  3192.  
  3193. function changemap(map)
  3194.     parse("changemap "..map)
  3195. end
  3196.  
  3197. function customkill(killer,weaponname,victim)
  3198.     parse("customkill "..killer.." "..weaponname.." "..victim)
  3199. end
  3200.  
  3201. function deathslap(player)
  3202.     parse("deathslap "..player)
  3203. end
  3204.  
  3205. function effect(effect,x,y,p1,p2,r,g,b)
  3206.     parse('effect "'..effect..'" '..x..' '..y..' '..p1..' '..p2..' '..r..' '..g..' '..b)
  3207. end
  3208.  
  3209. function equip(player,weapon)
  3210.     parse("equip "..player.." "..weapon)
  3211. end
  3212.  
  3213. function explosion(x,y,size,damage,sourceplayer)
  3214.     parse("explosion "..x.." "..y.." "..size.." "..damage.." "..sourceplayer)
  3215. end
  3216.  
  3217. function flashplayer(player,intensity)
  3218.     parse("flashplayer "..player.." "..intensity)
  3219. end
  3220.  
  3221. function flashposition(x,y,intensity)
  3222.     parse("flashposition "..x.." "..y.." "..intensity)
  3223. end
  3224.  
  3225. function hudtxt(id,text,x,y,align)
  3226.     parse("hudtxt "..id.." "..text.." "..x.." "..y.." "..align)
  3227. end
  3228.  
  3229. function hudtxt2(player,id,text,x,y,align)
  3230.     parse("hudtxt2 "..player.." "..id.." "..text.." "..x.." "..y.." "..align)
  3231. end
  3232.  
  3233. function hudtxtalphafade(player,id,duration,alpha)
  3234.     parse("hudtxtalphafade "..player.." "..id.." "..duration.." "..alpha)
  3235. end
  3236.  
  3237. function hudtxtcolorfade(player,id,duration,red,green,blue)
  3238.     parse("hudtxtcolorfade "..player.." "..id.." "..duration.." "..red.." "..green.." "..blue)
  3239. end
  3240.  
  3241. function hudtxtmove(player,id,duration,x,y)
  3242.     parse("hudtxtmove "..player.." "..id.." "..duration.." "..x.." "..y)
  3243. end
  3244.  
  3245. function items()
  3246.     parse("items")
  3247. end
  3248.  
  3249. function kick(player,reason)
  3250.     parse("kick "..player.." "..reason)
  3251. end
  3252.  
  3253. function killobject(objectid)
  3254.     parse("killobject "..objectid)
  3255. end
  3256.  
  3257. function killplayer(player)
  3258.     parse("killplayer "..player)
  3259. end
  3260.  
  3261. function listbans()
  3262.     parse("listbans")
  3263. end
  3264.  
  3265. function listplayers()
  3266.     parse("listplayers")
  3267. end
  3268.  
  3269. function logaddress_add(address)
  3270.     parse("logaddress_add "..address)
  3271. end
  3272.  
  3273. function logaddress_remove(address)
  3274.     parse("logaddress_remove "..address)
  3275. end
  3276.  
  3277. function logaddress_removeall()
  3278.     parse("logaddress_removeall")
  3279. end
  3280.  
  3281. function lua(script)
  3282.     parse("lua "..script)
  3283. end
  3284.  
  3285. function luareset()
  3286.     parse("luareset")
  3287. end
  3288.  
  3289. function makect(player)
  3290.     parse("makect "..player)
  3291. end
  3292.  
  3293. function makespec(player)
  3294.     parse("makespec "..player)
  3295. end
  3296.  
  3297. function maket(player)
  3298.     parse("maket "..player)
  3299. end
  3300.  
  3301. function map(map)
  3302.     parse("map "..map)
  3303. end
  3304.  
  3305. function maps()
  3306.     parse("maps")
  3307. end
  3308.  
  3309. function mp_antispeeder(antispeederprotection)
  3310.     parse("mp_antispeeder "..antispeederprotection)
  3311. end
  3312.  
  3313. function mp_autogamemode(autogamemode)
  3314.     parse("mp_autogamemode "..autogamemode)
  3315. end
  3316.  
  3317. function mp_autoteambalance(balance)
  3318.     parse("mp_autoteambalance "..balance)
  3319. end
  3320.  
  3321. function mp_building_health(building,price)
  3322.     parse("mp_building_health "..building.." "..price)
  3323. end
  3324.  
  3325. function mp_building_limit(building,limit)
  3326.     parse("mp_building_limit "..building.." "..limit)
  3327. end
  3328.  
  3329. function mp_building_price(building,price)
  3330.     parse("mp_building_price "..building.." "..price)
  3331. end
  3332.  
  3333. function mp_buytime(_time)
  3334.     parse("mp_buytime ".._time)
  3335. end
  3336.  
  3337. function mp_c4timer(_time)
  3338.     parse("mp_c4timer ".._time)
  3339. end
  3340.  
  3341. function mp_curtailedexplosions(curtailed)
  3342.     parse("mp_curtailedexplosions "..curtailed)
  3343. end
  3344.  
  3345. function mp_damagefactor(factor)
  3346.     parse("mp_damagefactor "..factor)
  3347. end
  3348.  
  3349. function mp_deathdrop(drop)
  3350.     parse("mp_deathdrop "..drop)
  3351. end
  3352.  
  3353. function mp_dispenser_health(health)
  3354.     parse("mp_dispenser_health "..health)
  3355. end
  3356.  
  3357. function mp_dispenser_money(money)
  3358.     parse("mp_dispenser_money "..money)
  3359. end
  3360.  
  3361. function mp_dmspawnmoney(money)
  3362.     parse("mp_dmspawnmoney "..money)
  3363. end
  3364.  
  3365. function mp_dropgrenades(drop)
  3366.     parse("mp_dropgrenades "..drop)
  3367. end
  3368.  
  3369. function mp_floodprot(floodprotection)
  3370.     parse("mp_floodprot "..floodprotection)
  3371. end
  3372.  
  3373. function mp_freezetime(_time)
  3374.     parse("mp_freezetime ".._time)
  3375. end
  3376.  
  3377. function mp_grenaderebuy(allowed)
  3378.     parse("mp_grenaderebuy "..allowed)
  3379. end
  3380.  
  3381. function mp_hostagepenalty(kills)
  3382.     parse("mp_hostagepenalty "..kills)
  3383. end
  3384.  
  3385. function mp_idleaction(action)
  3386.     parse("mp_idleaction "..action)
  3387. end
  3388.  
  3389. function mp_idlekick(idleaction)
  3390.     parse("mp_idlekick "..idleaction)
  3391. end
  3392.  
  3393. function mp_idletime(_time)
  3394.     parse("mp_idletime ".._time)
  3395. end
  3396.  
  3397. function mp_infammo(infiniteammo)
  3398.     parse("mp_infammo "..infiniteammo)
  3399. end
  3400.  
  3401. function mp_kevlar(percent)
  3402.     parse("mp_kevlar "..percent)
  3403. end
  3404.  
  3405. function mp_kickpercent(percent)
  3406.     parse("mp_kickpercent "..percent)
  3407. end
  3408.  
  3409. function mp_killbuildingmoney(money)
  3410.     parse("mp_killbuildingmoney "..money)
  3411. end
  3412.  
  3413. function mp_killbuildings(kill)
  3414.     parse("mp_killbuildings "..kill)
  3415. end
  3416.  
  3417. function mp_killinfo(info)
  3418.     parse("mp_killinfo "..info)
  3419. end
  3420.  
  3421. function mp_killteambuildings(mode)
  3422.     parse("mp_killteambuildings "..mode)
  3423. end
  3424.  
  3425. function mp_lagcompensation(maxcompensationtime)
  3426.     parse("mp_lagcompensation "..maxcompensationtime)
  3427. end
  3428.  
  3429. function mp_localrconoutput(output)
  3430.     parse("mp_localrconoutput "..output)
  3431. end
  3432.  
  3433. function mp_luamap(use)
  3434.     parse("mp_luamap "..use)
  3435. end
  3436.  
  3437. function mp_luaserver(file)
  3438.     parse("mp_luaserver "..file)
  3439. end
  3440.  
  3441. function mp_mapgoalscore(score)
  3442.     parse("mp_mapgoalscore "..score)
  3443. end
  3444.  
  3445. function mp_mapvoteratio(percent)
  3446.     parse("mp_mapvoteratio "..percent)
  3447. end
  3448.  
  3449. function mp_maxclientsip(clients)
  3450.     parse("mp_maxclientsip "..clients)
  3451. end
  3452.  
  3453. function mp_maxrconfails(maxfails)
  3454.     parse("mp_maxrconfails "..maxfails)
  3455. end
  3456.  
  3457. function mp_natholepunching(allowpunching)
  3458.     parse("mp_natholepunching "..allowpunching)
  3459. end
  3460.  
  3461. function mp_pinglimit(limit)
  3462.     parse("mp_pinglimit "..limit)
  3463. end
  3464.  
  3465. function mp_radar(radar)
  3466.     parse("mp_radar "..radar)
  3467. end
  3468.  
  3469. function mp_randomspawn(_random)
  3470.     parse("mp_randomspawn ".._random)
  3471. end
  3472.  
  3473. function mp_reservations(reservations)
  3474.     parse("mp_reservations "..reservations)
  3475. end
  3476.  
  3477. function mp_respawndelay(delay)
  3478.     parse("mp_respawndelay "..delay)
  3479. end
  3480.  
  3481. function mp_roundlimit(rounds)
  3482.     parse("mp_roundlimit "..rounds)
  3483. end
  3484.  
  3485. function mp_roundtime(_time)
  3486.     parse("mp_roundtime ".._time)
  3487. end
  3488.  
  3489. function mp_startmoney(money)
  3490.     parse("mp_startmoney "..money)
  3491. end
  3492.  
  3493. function mp_supply_items(itemlist)
  3494.     parse("mp_supply_items "..itemlist)
  3495. end
  3496.  
  3497. function mp_teamkillpenalty(kills)
  3498.     parse("mp_teamkillpenalty "..kills)
  3499. end
  3500.  
  3501. function mp_teleportreload(reloadtime)
  3502.     parse("mp_teleportreload "..reloadtime)
  3503. end
  3504.  
  3505. function mp_tempbantime(_time)
  3506.     parse("mp_tempbantime ".._time)
  3507. end
  3508.  
  3509. function mp_timelimit(_time)
  3510.     parse("mp_timelimit ".._time)
  3511. end
  3512.  
  3513. function mp_tkpunish(kill)
  3514.     parse("mp_tkpunish "..kill)
  3515. end
  3516.  
  3517. function mp_trace(accuracy)
  3518.     parse("mp_trace ".."accuracy")
  3519. end
  3520.  
  3521. function mp_turretdamage(damage)
  3522.     parse("mp_turretdamage "..damage)
  3523. end
  3524.  
  3525. function mp_unbuildable(buildings)
  3526.     parse("mp_unbuildable "..buildings)
  3527. end
  3528.  
  3529. function mp_unbuyable(unbuyable)
  3530.     parse("mp_unbuyable "..unbuyable)
  3531. end
  3532.  
  3533. function mp_vulnerablehostages(vulnerable)
  3534.     parse("mp_vulnerablehostages "..vulnerable)
  3535. end
  3536.  
  3537. function mp_winlimit(wins)
  3538.     parse("mp_winlimit "..wins)
  3539. end
  3540.  
  3541. function mp_wpndmg(name,damage)
  3542.     parse("mp_wpndmg "..name.." "..damage)
  3543. end
  3544.  
  3545. function mp_wpndmg_z1(name,damage)
  3546.     parse("mp_wpndmg_z1 "..name.." "..damage)
  3547. end
  3548.  
  3549. function mp_wpndmg_z2(name,damage)
  3550.     parse("mp_wpndmg_z2 "..name.." "..damage)
  3551. end
  3552.  
  3553. function mp_zombiedmg(percentageofdamage)
  3554.     parse("mp_zombiedmg "..percentageofdamage)
  3555. end
  3556.  
  3557. function mp_zombiekillequip(weapon)
  3558.     parse("mp_zombiekillequip "..weapon)
  3559. end
  3560.  
  3561. function mp_zombiekillscore(killscore)
  3562.     parse("mp_zombiekillscore "..killscore)
  3563. end
  3564.  
  3565. function mp_zombierecover(recover)
  3566.     parse("mp_zombierecover "..recover)
  3567. end
  3568.  
  3569. function mp_zombiespeedmod(speedmod)
  3570.     parse("mp_zombiespeedmod "..speedmod)
  3571. end
  3572.  
  3573. function msg(message)
  3574.     parse("msg "..message)
  3575. end
  3576.  
  3577. function rcon(commands)
  3578.     parse("rcon "..commands)
  3579. end
  3580.  
  3581. function rcon_password(password)
  3582.     parse("rcon_password "..password)
  3583. end
  3584.  
  3585. function rcon_pw(password)
  3586.     parse("rcon_pw "..password)
  3587. end
  3588.  
  3589. function removeitem(item)
  3590.     parse("removeitem "..item)
  3591. end
  3592.  
  3593. function reroute(player,address)
  3594.     parse("reroute "..player.." "..address)
  3595. end
  3596.  
  3597. function restart(delay)
  3598.     parse("restart "..delay)
  3599. end
  3600.  
  3601. function restartround(delay)
  3602.     parse("restartround "..delay)
  3603. end
  3604.  
  3605. function setarmor(player,armor)
  3606.     parse("setarmor "..player.." "..armor)
  3607. end
  3608.  
  3609. function setdeaths(player,deaths)
  3610.     parse("setdeaths "..player.." "..deaths)
  3611. end
  3612.  
  3613. function sethealth(player,health)
  3614.     parse("sethealth "..player.." "..health)
  3615. end
  3616.  
  3617. function setmaxhealth(player,maxhealth)
  3618.     parse("setmaxhealth "..player.." "..maxhealth)
  3619. end
  3620.  
  3621. function setmoney(player,money)
  3622.     parse("setmoney "..player.." "..money)
  3623. end
  3624.  
  3625. function setname(player,name)
  3626.     parse("setname "..player.." "..name)
  3627. end
  3628.  
  3629. function setpos(player,x,y)
  3630.     parse("setpos "..player.." "..x.." "..y)
  3631. end
  3632.  
  3633. function setscore(player,score)
  3634.     parse("setscore "..player.." "..score)
  3635. end
  3636.  
  3637. function setweapon(player,weapon)
  3638.     parse("setweapon "..player.." "..weapon)
  3639. end
  3640.  
  3641. function shake(player,power)
  3642.     parse("shake "..player.." "..power)
  3643. end
  3644.  
  3645. function slap(player)
  3646.     parse("slap "..player)
  3647. end
  3648.  
  3649. function spawnitem(item,x,y)
  3650.     parse("spawnitem "..item.." "..x.." "..y)
  3651. end
  3652.  
  3653. function spawnnpc(_type,x,y,rot)
  3654.     parse("spawnnpc ".._type.." "..x.." "..y.." "..rot)
  3655. end
  3656.  
  3657. function spawnobject(_type,x,y,rot,mode,team,player)
  3658.     parse("spawnobject ".._type.." "..x.." "..y.." "..rot.." "..mode.." "..team.." "..player)
  3659. end
  3660.  
  3661. function spawnplayer(player,x,y)
  3662.     parse("spawnplayer "..player.." "..x.." "..y)
  3663. end
  3664.  
  3665. function speedmod(player,speedmod)
  3666.     parse("speedmod "..player.." "..speedmod)
  3667. end
  3668.  
  3669. function strip(player,weapon)
  3670.     parse("strip "..player.." "..weapon)
  3671. end
  3672.  
  3673. function sv_fow(fow)
  3674.     parse("sv_fow "..fow)
  3675. end
  3676.  
  3677. function sv_friendlyfire(FF)
  3678.     parse("sv_friendlyfire "..FF)
  3679. end
  3680.  
  3681. function sv_gamemode(mode)
  3682.     parse("sv_gamemode "..mode)
  3683. end
  3684.  
  3685. function sv_gm(mode)
  3686.     parse("sv_gm "..mode)
  3687. end
  3688.  
  3689. function sv_hostport(port)
  3690.     parse("sv_hostport "..port)
  3691. end
  3692.  
  3693. function sv_lan(lan)
  3694.     parse("sv_lan "..lan)
  3695. end
  3696.  
  3697. function sv_map(map)
  3698.     parse("sv_map "..map)
  3699. end
  3700.  
  3701. function sv_maptransfer(transfer)
  3702.     parse("sv_maptransfer "..transfer)
  3703. end
  3704.  
  3705. function sv_maxplayers(players)
  3706.     parse("sv_maxplayers "..players)
  3707. end
  3708.  
  3709. function sv_msg(message)
  3710.     parse("sv_msg "..message)
  3711. end
  3712.  
  3713. function sv_msg2(player,message)
  3714.     parse("sv_msg2 "..player.." "..message)
  3715. end
  3716.  
  3717. function sv_name(name)
  3718.     parse("sv_name "..name)
  3719. end
  3720.  
  3721. function sv_password(password)
  3722.     parse("sv_password "..password)
  3723. end
  3724.  
  3725. function sv_rcon(rconpassword)
  3726.     parse("sv_rcon "..rconpassword)
  3727. end
  3728.  
  3729. function sv_restart(delay)
  3730.     parse("sv_restart "..delay)
  3731. end
  3732.  
  3733. function sv_restartround(delay)
  3734.     parse("sv_restartround "..delay)
  3735. end
  3736.  
  3737. function sv_sound(soundfile)
  3738.     parse("sv_sound "..soundfile)
  3739. end
  3740.  
  3741. function sv_sound2(player,soundfile)
  3742.     parse("sv_sound2 "..player.." "..soundfile)
  3743. end
  3744.  
  3745. function sv_specmode(mode)
  3746.     parse("sv_specmode "..mode)
  3747. end
  3748.  
  3749. function sv_spraytransfer(spraytransfer)
  3750.     parse("sv_spraytransfer "..spraytransfer)
  3751. end
  3752.  
  3753. function sv_usgnonly(usgnonly)
  3754.     parse("sv_usgnonly "..usgnonly)
  3755. end
  3756.  
  3757. function transfer_speed(speed)
  3758.     parse("transfer_speed "..speed)
  3759. end
  3760.  
  3761. function trigger(trigger)
  3762.     parse("trigger "..trigger)
  3763. end
  3764.  
  3765. function unban(banmask)
  3766.     parse("unban "..banmask)
  3767. end
  3768.  
  3769. function unbanall()
  3770.     parse("unbanall")
  3771. end
  3772.  
  3773. function usgn_addserver()
  3774.     parse("usgn_addserver")
  3775. end
  3776.  
  3777. function usgn_info()
  3778.     parse("usgn_info")
  3779. end
  3780.  
  3781.  
  3782.  
  3783. ------------------------------
  3784. ------- CHAT SYSTEM ----------
  3785. ------------------------------
  3786. colour = {
  3787.     [1] = {'255220000','©255025000','©050150255','©050150255'},
  3788.     [2] = {'©255220000','©000255000','©000255000'},
  3789.     ooc = '©200200200'
  3790. }
  3791.  
  3792. queries = {
  3793.     ['ooc']     =       colour.ooc.."(($n: $t))",
  3794.     ['me']      =       "$s>$n $t",
  3795.     ['do']      =       "$c[$i]: $s**$t**"
  3796. }
  3797.  
  3798. distance        =       200     --distance in pixels a player has to be to see your messages
  3799.  
  3800.  
  3801.  
  3802. function getDist(x1, y1, x2, y2)
  3803.     return math.floor(((x1 - x2)^2 + (y1 - y2)^2)^.5)
  3804. end
  3805.  
  3806. function msg3(id, text)
  3807.     for _, i in pairs(player(0, 'tableliving')) do
  3808.         if getDist(player(i, 'x'), player(i, 'y'), player(id, 'x'), player(id, 'y')) <= distance then msg2(i, text) end
  3809.     end
  3810. end
  3811. --getDist & msg3 by Avobolt | unedited source: http://www.unrealsoftware.de/forum_posts.php?post=366814&start=0#post366831
  3812.  
  3813. function _sayHook(id, txt)
  3814.     msg3(id, queryCmd(id, txt, string.match(txt, '!(%a+)%s-')))
  3815.     return 1;
  3816. end
  3817.  
  3818. function queryCmd(id, txt, cmd)
  3819.     local txtn = txt:match('!%a+%s(.*)') or txt
  3820.     local rep = {
  3821.         ['t']   =   txtn and string.gsub(txtn, '^%s*(.-)%s*$', '%1') or 'nothing',
  3822.         ['i']   =   id,
  3823.         ['n']   =   player(id, 'name'),
  3824.         ['c']   =   colour[(tonumber(game('sv_gamemode'))==1 and 2 or 1)][player(id, 'team')+1],
  3825.         ['s']   =   '©255220000',
  3826.         ['$']   =   '$'
  3827.     }
  3828.     if queries[cmd] then return queries[cmd]:gsub("$(.)", rep);
  3829.     else return rep.c..rep.n..rep.s..' says: '..rep.t; end
  3830. end
  3831.  
  3832.  
  3833. ------------------------------
  3834. ------ WORN WEAPONS ----------
  3835. ------------------------------
  3836. function array(val)
  3837.     local a = {}
  3838.     for i = 1, 32 do
  3839.         a[i] = val
  3840.     end
  3841.     return a;
  3842. end
  3843.  
  3844. --// Slots: [1] primary     |   [2] secondary       | [3] melee     |       spec special (flamethrower)
  3845. wornWeaponIMG = {slot = {array(0), array(0), array(0), spec = array(0)}, used = {array(true), array(true), array(true), spec = array(true)}, current = {array(0), array(0), array(0), spec = array(0)}}
  3846.  
  3847.  
  3848.  
  3849. function WW_collectHook(id, type)
  3850.     if player(id, 'weapontype') ~= type then
  3851.         wornImages(id, type)
  3852.     end
  3853. end
  3854.  
  3855. function WW_dropHook(id, type)
  3856.     function continueImages()
  3857.         wornImages(id, player(id, 'weapontype'))
  3858.     end
  3859.     timer(5, 'continueImages')
  3860. end
  3861.  
  3862. function WW_selectHook(id, type)
  3863.     wornImages(id, type)
  3864. end
  3865.  
  3866. function WW_spawnHook(id)
  3867.     function continueImages()
  3868.         wornImages(id, player(id, 'weapontype'))
  3869.     end
  3870.     timer(5, 'continueImages')
  3871. end
  3872.  
  3873. function clearSlots(id)
  3874.     function clearSlot(slot)
  3875.         if wornWeaponIMG.used[slot][id] == false then
  3876.             freeimage(wornWeaponIMG.slot[slot][id])
  3877.             wornWeaponIMG.used[slot][id] = true
  3878.         end
  3879.     end
  3880.     for slot = 1, 3 do
  3881.         clearSlot(slot)
  3882.     end
  3883.     clearSlot('spec')
  3884. end
  3885.  
  3886. function wornImages(id, currentType)
  3887.     clearSlots(id)
  3888.     function wearSlot(iid, slot)
  3889.         if iid ~= 0 then
  3890.             local slotType = 100
  3891.             if slot == 1 or slot == 'spec' then
  3892.                 slotType = 200
  3893.             end
  3894.             wornWeaponIMG.slot[slot][id] = image('gfx/WornWeapons/'..iid..'.png', 1, 0, slotType + id)
  3895.             wornWeaponIMG.used[slot][id] = false
  3896.         end
  3897.     end
  3898.     for _, iid in pairs(playerweapons(id)) do
  3899.         if currentType ~= iid and iid ~= 78 then
  3900.             local slot = itemtype(iid, 'slot')
  3901.             if slot >= 1 and slot <= 3 then
  3902.                 if weaponTiers[iid] == 'spec' then slot = 'spec' end
  3903.                 if wornWeaponIMG.current[slot][id] ~= 0 then
  3904.                     if weaponTiers[iid] == 'spec' then
  3905.                         if specTable[iid] > specTable[wornWeaponIMG.current.spec[id]] then
  3906.                             wornWeaponIMG.current.spec[id] = iid
  3907.                         end
  3908.                     elseif weaponTiers[iid] > weaponTiers[wornWeaponIMG.current[slot][id]] then
  3909.                         wornWeaponIMG.current[slot][id] = iid
  3910.                     end
  3911.                 else
  3912.                     if weaponTiers[iid] == 'spec' then
  3913.                         wornWeaponIMG.current.spec[id] = iid
  3914.                     else
  3915.                         wornWeaponIMG.current[slot][id] = iid
  3916.                     end
  3917.                 end
  3918.             end
  3919.         end
  3920.     end
  3921.     wearSlot(wornWeaponIMG.current.spec[id], 'spec')
  3922.     wornWeaponIMG.current.spec[id] = 0
  3923.     for slot = 1, 3 do
  3924.         wearSlot(wornWeaponIMG.current[slot][id], slot)
  3925.         wornWeaponIMG.current[slot][id] = 0
  3926.     end
  3927. end
  3928.  
  3929.  
  3930. ------------------------------
  3931. ------- BADWORDS -------------
  3932. ------------------------------
  3933.  
  3934.  
  3935.  
  3936.  
  3937.  
  3938. ------------------------------
  3939. --------- SOCCER SYSTEM ------
  3940. ------------------------------
  3941.  
  3942. -----------------------------
  3943. ------ STREAM FUNCTIONS -----
  3944. -----------------------------
  3945.  
  3946. -----------------------------
  3947. ------ TRAIN SYSTEM ---------
  3948. -----------------------------
  3949. trains = {
  3950.     [1] = {
  3951.         img = "gfx/mhappy/train.png",
  3952.         speed = 6;
  3953.         tid, gfx = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0, dir = 0, nodes = 0, current = 0, wait = false,
  3954.         players = {},
  3955.         node = {
  3956.             {128, 19, 30}, {128, 27}, {137, 27}, {137, 67},
  3957.             {167, 67}, {167, 130}, {156, 130}, {156, 146},
  3958.             {131, 146, 5}, {156, 146}, {156, 221}, {110, 221},
  3959.             {110, 216, 5}, {110, 221}, {156, 221}, {156, 146},
  3960.             {131, 146, 5}, {156, 146}, {156, 130}, {189, 130},
  3961.             {189, 98, 5}, {189, 130}, {167, 130}, {167, 67},
  3962.             {137, 67}, {137, 27}, {128, 27}, {128, 19, 30},
  3963.         },
  3964.     },
  3965. }
  3966.  
  3967.  
  3968. function GetDir(x1, y1, x2, y2)
  3969.     return math.atan2(x2-x1, y2-y1);
  3970. end
  3971.  
  3972. function GetDist(x1, y1, x2, y2)
  3973.     return math.sqrt((x2 - x1)^2 + (y2 - y1)^2);
  3974. end
  3975.  
  3976. function InitTrains()
  3977.     local _, i;
  3978.     for _, i in pairs(trains) do
  3979.         i.nodes = #i.node;
  3980.         i.current = 1;
  3981.         i.tid = _;
  3982.         i.x1 = (i.node[1][1] * 32) + 16;
  3983.         i.y1 = (i.node[1][2] * 32) + 16;
  3984.         i.x2 = (i.node[2][1] * 32) + 16;
  3985.         i.y2 = (i.node[2][2] * 32) + 16;
  3986.         i.dir = GetDir(i.x1, i.y1, i.x2, i.y2);
  3987.         i.gfx = image(i.img, i.x1, i.y1, 1);
  3988.         imagepos(i.gfx, i.x1, i.y1, -math.deg(i.dir));
  3989.     end
  3990. end
  3991.  
  3992. InitTrains();
  3993.  
  3994. function UnwaitTrain(i)
  3995.     trains[tonumber(i)].wait = false;
  3996. end
  3997.  
  3998.  
  3999. function moveTrains()
  4000.     local _, i;
  4001.     for _, i in pairs(trains) do
  4002.         if not i.wait then
  4003.             i.x1 = i.x1 + math.sin(i.dir) * i.speed;
  4004.             i.y1 = i.y1 + math.cos(i.dir) * i.speed;
  4005.             local tx1, ty1;
  4006.             tx1 = math.floor(i.x1 / 32);
  4007.             ty1 = math.floor(i.y1 / 32);
  4008.             if tx1 == math.floor(i.x2 / 32) and ty1 == math.floor(i.y2 / 32)  then
  4009.                 i.current = i.current + 1;
  4010.                 if i.node[i.current] ~= nil then
  4011.                     if i.node[i.current][3] ~= nil then
  4012.                         i.wait = true;
  4013.                         timer(i.node[i.current][3] * 1000, "UnwaitTrain", tostring(_));
  4014.                     end
  4015.                 end
  4016.                 i.x1 = i.x2;
  4017.                 i.y1 = i.y2;
  4018.                 if i.current == i.nodes + 1 then
  4019.                     i.current = 1;
  4020.                     i.x1 = (i.node[1][1] * 32) + 16;
  4021.                     i.y1 = (i.node[1][2] * 32) + 16;
  4022.                     i.x2 = (i.node[2][1] * 32) + 16;
  4023.                     i.y2 = (i.node[2][2] * 32) + 16;
  4024.                 elseif (i.current + 1) > i.nodes then
  4025.                     i.x2 = (i.node[1][1] * 32) + 16;
  4026.                     i.y2 = (i.node[1][2] * 32) + 16;
  4027.                 else
  4028.                     i.x2 = (i.node[i.current + 1][1] * 32) + 16;
  4029.                     i.y2 = (i.node[i.current + 1][2] * 32) + 16;
  4030.                 end
  4031.                 i.dir = GetDir(i.x1, i.y1, i.x2, i.y2);
  4032.             end
  4033.             imagepos(i.gfx, i.x1, i.y1, -math.deg(i.dir));
  4034.         end
  4035.         local j, k;
  4036.         for j, k in pairs(i.players) do
  4037.             if player(k, "health") > 0 then
  4038.                 parse("setpos ".. k .." ".. i.x1 .." ".. i.y1);
  4039.             else
  4040.                 table.remove(i.players, j);
  4041.             end
  4042.         end
  4043.     end
  4044. end
  4045.  
  4046.  
  4047.  
  4048. function enterTrain(id)
  4049.     local x, y = player(id, "x"), player(id, "y");
  4050.     local _, i;
  4051.     if not Player[id].car and not Player[id].carowner then
  4052.         if Player[id].train == 0 then
  4053.             for _, i in pairs(trains) do
  4054.                 if GetDist(x, y, i.x1, i.y1) <= 48 then
  4055.                     if i.wait then
  4056.                         table.insert(i.players, id)
  4057.                         Player[id].speed = player(id, "speedmod");
  4058.                         Player[id].train = _;
  4059.                         parse("speedmod ".. id .." -100");
  4060.                         break;
  4061.                     else
  4062.                         msg2(id, "©255000000You can enter train only at station!");
  4063.                     end
  4064.                 end
  4065.             end
  4066.         else
  4067.             if trains[Player[id].train].wait then
  4068.                 for _, i in pairs(trains[Player[id].train].players) do
  4069.                     if i == id then
  4070.                         table.remove(trains[Player[id].train].players, _);
  4071.                         break;
  4072.                     end
  4073.                 end
  4074.                 Player[id].train = 0;
  4075.                 parse("speedmod ".. id .." ".. Player[id].speed);
  4076.             else
  4077.                 msg2(id, "©255000000You can't get out of train while travelling!");
  4078.             end
  4079.         end
  4080.     end
  4081. end
  4082.  
  4083. -----------------------------
  4084. ---- DOOR LOCK FOR H --------
  4085. -----------------------------
  4086.  
  4087. --[[
  4088.     Password for doors - lock doors on your map!
  4089.     By Avobolt (USGN#88318)
  4090. ]]--
  4091. function Array(m, v)
  4092.     local T = {}
  4093.     for i = 1, m do
  4094.         T[i] = v
  4095.     end
  4096.     return T
  4097. end
  4098. AnglePosition = function(rot, x, y, factor)
  4099.     if rot < -90 then rot = rot + 360 end
  4100.     local angle = math.rad(math.abs(rot + 90)) - math.pi
  4101.     local x = x + (math.cos(angle) * factor)
  4102.     local y = y + (math.sin(angle) * factor)
  4103.     return x, y
  4104. end
  4105.  
  4106. pkl = {}
  4107. pkl.Comb = Array(32, { "" , "", {0, 0} } ) -- [  1 ] - password, [  2 ] - inserted password, [3] - position
  4108. pkl.Chars = {"1","2","3","4","5","6","7","8","0"} -- up to 9 chars, I was too lazy to unclude inf menus
  4109.  
  4110. pkl.HookUse = function(id)
  4111.     local x, y = AnglePosition(player(id, "rot"), player(id, "x"), player(id, "y"), 32)
  4112.     x, y = math.floor(x/32), math.floor(y/32)
  4113.     local name = entity(x, y, "name")
  4114.     if tile(x,y, "entity") and type(entity(x, y, "name")) == "string" and entity(x, y, "name"):sub(1,5) == "lock:" then
  4115.         local name = entity(x, y, "name")
  4116.         if entity(x, y, "state") == false then
  4117.             if #name <= 5 then return end
  4118.             pkl.Comb[id][1] = name:sub(6)
  4119.             pkl.Comb[id][2] = ""
  4120.             pkl.Comb[id][3] = {x, y}
  4121.             pkl.OpenMenu(id)
  4122.         else
  4123.             parse("triggerposition "..x.." "..y)
  4124.         end
  4125.     end
  4126. end
  4127. pkl.OpenMenu = function(id, step)
  4128.     if not step then step = 1 end
  4129.     local x, y = unpack(pkl.Comb[id][3])
  4130.     if entity(x, y, "state") == false then
  4131.         menu(id, "Lock - step "..step..","..table.concat(pkl.Chars, ","))
  4132.     end
  4133. end
  4134.  
  4135. pkl.HookMenu = function(id,title,b)
  4136.     if title:sub(1, 12) == "Lock - step " then
  4137.         if b == "x" or b == 0 then return end
  4138.         local step = tonumber(title:sub(13))
  4139.         local ch = pkl.Chars[b]
  4140.         pkl.Comb[id][2] = pkl.Comb[id][2]..ch
  4141.         if #pkl.Comb[id][1] == #pkl.Comb[id][2] then
  4142.             parse("triggerposition "..pkl.Comb[id][3][1].." "..pkl.Comb[id][3][2]) 
  4143.         else
  4144.             if pkl.Comb[id][2] == pkl.Comb[id][1]:sub(1, #pkl.Comb[id][2]) then
  4145.                 parse("sv_sound2 "..id.."\"wpn_select.wav\"")
  4146.                 pkl.OpenMenu(id, step + 1)
  4147.             else
  4148.                 parse("sv_sound2 "..id.."\"wpn_denyselect.wav\"")
  4149.             end
  4150.         end
  4151.     end
  4152. end
  4153.  
  4154. -----------------------------
  4155. ------ HOUSE SYSTEM ---------
  4156. -----------------------------
  4157. houses = {
  4158.     {
  4159.         name = "House 2";
  4160.         ex = 115;   ey = 115; -- pozycja w ktorej sie kupuje dom
  4161.         x1 = 104;   y1 = 128; -- rozmiar domu
  4162.         x2 = 112;   y2 = 134;
  4163.         price = 500;
  4164.     },
  4165. }
  4166.  
  4167. function InitHouses()
  4168.     local _, i;
  4169.     for _, i in pairs(houses) do
  4170.         i.allowed = {};
  4171.         i.owner = 0;
  4172.     end
  4173. end
  4174.  
  4175. InitHouses();
  4176.  
  4177.  
  4178. function houseUse(id)
  4179.     if Player[id].house then
  4180.         local x, y = player(id, "tilex"), player(id, "tiley");
  4181.         local dir = math.floor((player(id, "rot") + 45) / 90) % 4;
  4182.         if dir == 0 then
  4183.             y = y - 1;
  4184.         elseif dir == 1 then
  4185.             x = x + 1;
  4186.         elseif dir == 2 then
  4187.             y = y + 1;
  4188.         else
  4189.             x = x - 1;
  4190.         end
  4191.         if x >= Player[id].house.x1 and y >= Player[id].house.y1 and x <= Player[id].house.x2 and y <= Player[id].house.y2 then
  4192.             if entity(x, y, "exists") then
  4193.                 if entity(x, y, "type") == 71 then
  4194.                     parse("triggerposition ".. x .." ".. y);
  4195.                 end
  4196.             end
  4197.         end
  4198.     end
  4199. end
  4200.  
  4201. function BuyHouse(id)
  4202.     local x, y;
  4203.     x = player(id, "tilex");
  4204.     y = player(id, "tiley");
  4205.     local _, i;
  4206.     local hid = 0;
  4207.     for _, i in pairs(houses) do
  4208.         if x == i.ex and y == i.ey then
  4209.             hid = _;
  4210.             break;
  4211.         end
  4212.     end
  4213.    
  4214.     if hid > 0 then
  4215.         if houses[hid].owner == 0 then
  4216.             if houses[hid].only == nil or Player[id].job == houses[hid].only then
  4217.                 if PayMoney(id, houses[hid].price, true) then
  4218.                     msg2(id, "©255255255Succefully bought " .. houses[hid].name .. "!");
  4219.                     msg2(id, "©255255255Go to F2/Property Options, Press E to open doors!");
  4220.                     Player[id].house = houses[hid];
  4221.                     houses[hid].owner = id;
  4222.                 end
  4223.             else
  4224.                 msg2(id, "©255000000Only "..houses[hid].only.." can buy this property!");
  4225.             end
  4226.         end
  4227.     end
  4228. end
  4229.  
  4230.  
  4231. function houseCheck(id, x, y)
  4232.     local _, i;
  4233.     for _, i in pairs(houses) do
  4234.         if x == i.ex and y == i.ey then
  4235.             if not Player[id].house then
  4236.                 if i.owner == 0 then
  4237.                     local t = {
  4238.                         title = "Do you want to buy this property?",
  4239.                         items = {
  4240.                             {"Yes", "You can later sell it.", function(id) BuyHouse(id) end};
  4241.                             {"No", "",  nil};
  4242.                             {"(Property Info)", "", nil};
  4243.                             {"(Tiles Count: ".. ((i.x2-i.x1)*(i.y2-i.y1)) ..")", "", nil};
  4244.                             {"(Price: ".. i.price .."$)", "", nil};
  4245.                         },
  4246.                     }
  4247.                     unimenu(id, true, t, 1);
  4248.                 end
  4249.             end
  4250.         elseif x >= i.x1 and y >= i.y1 and x <= i.x2 and y <= i.y2 then
  4251.             local index = inTable(i.allowed, id);
  4252.             if i.owner == id then
  4253.                 break;
  4254.             elseif index > 0 then
  4255.                 break;
  4256.             else
  4257.                 parse("setpos ".. id .." ".. Player[id].lastx * 32 + 16 .." ".. Player[id].lasty * 32 + 16);
  4258.             end
  4259.         end
  4260.     end
  4261.     Player[id].lastx = player(id, "tilex");
  4262.     Player[id].lasty = player(id, "tiley");
  4263. end
  4264.  
  4265.  
  4266.  
  4267. House = {
  4268.     ["16,87"] = {
  4269.         StreetName = "1 Rich Street", -- Street name
  4270.         Owner = "Salad Fingers", -- Owner's name
  4271.         USGN = 6943, -- Owner's USGN
  4272.         Trigger = "house_salad" -- Door trigger's name
  4273.     }
  4274. }
  4275.  
  4276.  
  4277. House_MoveTile = function(id, x, y)
  4278.      if House[x..","..y] then
  4279.           msg2(id, "Welcome on "..House[x..","..y].StreetName.." \n Owner: "..House[x..","..y].Owner)
  4280.      end
  4281. end
  4282.  
  4283.  
  4284.  
  4285. HouseInfo = function(id, x, y)
  4286.     if House[player(id, "tilex")..","..player(id, "tiley")] then
  4287.         elseif player(id, "usgn") == House[x..","..y].USGN then
  4288.         parse("trigger" ..House[x..","..y].Trigger)
  4289.     end
  4290. end
  4291.  
  4292.  
  4293.  
  4294. -----------------------------
  4295. ------- ITEMS FOR INV -------
  4296. -----------------------------
  4297. Item = {
  4298.     [1] = {
  4299.         name = "AK-47";
  4300.         drop = 30; -- id itemy do wyrzucenia, usuń to jak nie pozwalasz wyrzucać
  4301.         equip = 30; -- id itemu do ubrania, usuń to jak nie pozwalasz ubrać
  4302.     };
  4303.     [2] = {
  4304.         name = "Apple";
  4305.         use = {"Eat", function(id, slotid) DecHunger(id, 5); removeItem(id, slotid); msg2(id, "©255000000Yummy apple!"); end};
  4306.     };
  4307.     [3] = {
  4308.         name = "AK-47 Shipment";
  4309.         drop = {30,30,30,30,30};
  4310.     };
  4311.     [4] = {
  4312.         name = "Bandage";
  4313.         use = {"Use", function(id, slotid) if player(id, "health") <= 50 then parse("sethealth "..id.."" +50); end removeItem(id, slotid); msg2(id, "©000255000Ahhh, Feeling myself better now!"); end};
  4314.         drop =  {30};
  4315.     };
  4316.     [5] = {
  4317.         name = "Mobile Phone";
  4318.         use = {"SMS", function (id, slotid) if mobile[id]==1 then msg2(id, "©255255000Usage: !SMS [Number] [Message]");end end};
  4319.         use = {"Call", function (id, slotid) if mobile[id]==1 then msg2(id, "©255255000Usage: !Call [Number]"); end end};
  4320.     };
  4321. }
  4322. -----------------------------
  4323. ------- INVENTORY SYS -------
  4324. -----------------------------
  4325. function showInv(id)
  4326.     if #Player[id].inv == 0 then
  4327.         msg2(id, "©255000000You don't have anything in inventory!");
  4328.         return 0;
  4329.     end
  4330.     local _, i;
  4331.     local t = {
  4332.         title = "Inventory";
  4333.         items = {};
  4334.     };
  4335.     for _, i in pairs(Player[id].inv) do
  4336.         table.insert(t.items, {Item[i].name, "", assert(loadstring("local id = ".. id .."; showItem(id, ".. _ ..");"))});
  4337.     end
  4338.     unimenu(id, true, t, 1);
  4339. end
  4340.  
  4341. function showItem(id, slotid)
  4342.     local iid = Player[id].inv[slotid];
  4343.     local t = {
  4344.         title = "Item " .. Item[iid].name;
  4345.         items = {};
  4346.     }
  4347.     if Item[iid].drop ~= nil then
  4348.         table.insert(t.items, {"Drop", "", assert(loadstring("local id = ".. id .."; dropItem(id, ".. slotid ..");"))});
  4349.     end
  4350.     if Item[iid].equip ~= nil then
  4351.         table.insert(t.items, {"Equip", "", assert(loadstring("local id = ".. id .."; equipItem(id, ".. slotid ..");"))});
  4352.     end
  4353.     if Item[iid].use ~= nil then
  4354.         table.insert(t.items, {Item[iid].use[1], "", assert(loadstring("local id = ".. id .."; Item[".. iid .."].use[2](id, ".. slotid ..");"))});
  4355.     end
  4356.     unimenu(id, true, t, 1);
  4357. end
  4358.  
  4359. function removeItem(id, slotid)
  4360.     table.remove(Player[id].inv, slotid);
  4361. end
  4362.  
  4363. function buyItem(id, cost, iid)
  4364.     if Player[id].money >= cost then
  4365.         if addItem(id, iid) then
  4366.             msg2(id, "©255128064You bought ".. Item[iid].name .."!");
  4367.             Player[id].money = Player[id].money - cost;
  4368.             if show then
  4369.                 msg2(id, "©255000000-" .. cost .. "$");
  4370.             end
  4371.             UpdateHud(id);
  4372.         else
  4373.             msg2(id, "©255000000You don't have enough space in inventory!");
  4374.         end
  4375.     else
  4376.         msg2(id, "©255000000You don't have enough money!");
  4377.     end
  4378. end
  4379.  
  4380. function addItem(id, iid)
  4381.     if #Player[id].inv <= inv_maxitems then
  4382.         table.insert(Player[id].inv, iid);
  4383.         return true;
  4384.     end
  4385.     return false;
  4386. end
  4387.  
  4388. function dropItem(id, slotid)
  4389.     local iid = Player[id].inv[slotid];
  4390.     if Item[iid].drop ~= nil then
  4391.         msg2(id, "©255128064Dropped "..Item[iid].name.."!");
  4392.         removeItem(id, slotid);
  4393.         if type(Item[iid].drop) == "table" then
  4394.             local _, i;
  4395.             for _, i in pairs(Item[iid].drop) do
  4396.                 parse("spawnitem ".. i .." ".. player(id, "tilex") .." ".. player(id, "tiley"));
  4397.             end
  4398.         else
  4399.             parse("spawnitem ".. Item[iid].drop .." ".. player(id, "tilex") .." ".. player(id, "tiley"));
  4400.         end
  4401.     end
  4402. end
  4403.  
  4404. function equipItem(id, slotid)
  4405.     local iid = Player[id].inv[slotid];
  4406.     if Item[iid].equip ~= nil then
  4407.         msg2(id, "©255128064Equipped "..Item[iid].name.."!");
  4408.         removeItem(id, slotid);
  4409.         if type(Item[iid].equip) == "table" then
  4410.             local _, i;
  4411.             for _, i in pairs(Item[iid].equip) do
  4412.                 parse("equip ".. id .." ".. i);
  4413.             end
  4414.         else
  4415.             parse("equip ".. id .." ".. Item[iid].equip);
  4416.         end
  4417.     end
  4418. end
  4419. -----------------------------
  4420. ---------- NPC SYSTEM -------
  4421. -----------------------------
  4422. shop_mc = {
  4423.     title = "Buy Food",
  4424.     items = {
  4425.         {"Hamburger", "[2$]", function(id) BuyFood(id, 10.1, 2); end},
  4426.         {"Double CheeseBurger", "[3$]", function(id) BuyFood(id, 15.4, 3); end},
  4427.         {"Happy Meal", "[4$]", function(id) BuyFood(id, 40.0, 4); end},
  4428.         {"MC Menu +", "[4$]", function(id) BuyFood(id, 60.0, 4); end},
  4429.     },
  4430. }
  4431.  
  4432. shop_water = {
  4433.     title = "Buy Drink",
  4434.     items = {
  4435.         {"Water", "[1$]", function(id) BuyWater(id, 10.9, 1); end},
  4436.         {"Coca-Cola", "[3$]", function(id) BuyWater(id, 5.5, 3); end},
  4437.         {"Pepsi", "[3$]", function(id) BuyWater(id, 5.5, 3); end},
  4438.     },
  4439. }
  4440.  
  4441. shop_drink_automat = {
  4442.     title = "Drink Vending Machine",
  4443.     items = {
  4444.         {"Hot-Water", "[2$]", function(id) BuyWater(id, 1.0, 2); end},
  4445.         {"Crystal-Water", "[3$]", function(id) BuyWater(id, 20, 3); end},
  4446.         {"Coca-Cola", "[5$]", function(id) BuyWater(id, 5.5, 5); end},
  4447.         {"Pepsi", "[5$]", function(id) BuyWater(id, 2.5, 5); end},
  4448.         {"Fanta", "[5$]", function(id) BuyWater(id, 2.5, 5); end},
  4449.         {"Sprite", "[5$]", function(id) BuyWater(id, 2.5, 5); end},
  4450.         {"Coffee", "[2$]", function(id) BuyWater(id, 2.5, 2); end},
  4451.         {"Coffee + Sugar", "[3$]", function(id) BuyWater(id, 2.8, 3); end},
  4452.         {"Hot Chocolate", "[4$]", function(id) BuyWater(id, 3.0, 4); end},
  4453.         {"Lemon Tea", "[3$]", function(id) BuyWater(id, 2.5, 3); end},
  4454.         },
  4455. }
  4456.  
  4457. shop_snack_machine = {
  4458.     title = "Snak Machine",
  4459.     items = {
  4460.         {"Lays", "[2$]", function(id) BuyFood(id, 20.0, 2); end},
  4461.         {"Snickers", "[1$]", function(id) BuyFood(id, 5.0, 1); end},
  4462.         {"Mars", "[1$]", function(id) BuyFood(id, 5.0, 1); end},
  4463.         {"Counter Chips", "[4$]", function(id) BuyFood(id, 25.0, 4); end},
  4464.         {"Kit-Kat", "[2$]", function(id) BuyFood(id, 6.0, 2); end},
  4465.         {"m&m", "[2$]", function(id) BuyFood(id, 5.0, 2); end},
  4466.         {"Cookie Crisp", "[3$]", function(id) BuyFood(id, 15.0, 3); end},
  4467.         {"Cheetos", "[2$]", function(id) BuyFood(id, 20.0, 2); end},
  4468.         {"Milka", "[3$]", function(id) BuyFood(id, 12.0, 3); end},
  4469.         {"Toblerone", "[4$]", function(id) BuyFood(id, 12.0, 4); end},
  4470.         },
  4471. }
  4472.  
  4473. shop_cars = {
  4474.     title = "Car Shop",
  4475.     items = {
  4476.         {"Ford Fiesta", "[1000$]", function(id) if PayMoney(id, 1000, true) then SpawnCar("red", player(id, "tilex")*32+16, player(id, "tiley")*32+16, player(id, "rot")) end end},
  4477.         {"Suzuki SJZ-200", "[500$]", function(id) if PayMoney(id, 500, true) then SpawnCar("motor", player(id, "tilex")*32+16, player(id, "tiley")*32+16, player(id, "rot")) end end},
  4478.     },
  4479. }
  4480.  
  4481.  
  4482. npc_list = {
  4483.     {
  4484.         x = 181;
  4485.         y = 186;
  4486.         m = shop_mc;
  4487.     };
  4488.     {
  4489.         x = 132;
  4490.         y = 78;
  4491.         m = shop_drink_automat;
  4492.     };
  4493.     {
  4494.         x = 131;
  4495.         y = 78;
  4496.         m = shop_snack_machine;
  4497.     };
  4498.     {
  4499.         x = 38;
  4500.         y = 137;
  4501.         m = shop_drink_automat;
  4502.     };
  4503.     {   x = 39;
  4504.         y = 137;
  4505.         m = shop_snack_machine;
  4506.     };
  4507.     {
  4508.         x = 48;
  4509.         y = 183;
  4510.         m = shop_drink_automat;
  4511.     };
  4512.     {
  4513.         x = 49;
  4514.         y = 183;
  4515.         m = shop_snack_machine;
  4516.     };
  4517.     {
  4518.         x = 133;
  4519.         y = 12;
  4520.         m = shop_drink_automat;
  4521.     };
  4522.     {
  4523.         x = 134;
  4524.         y = 12;
  4525.         m = shop_snack_machine;
  4526.     };
  4527.     {
  4528.         x = 134;
  4529.         y = 138;
  4530.         m = shop_drink_automat;
  4531.     };
  4532.     {
  4533.         x = 135;
  4534.         y = 138;
  4535.         m = shop_snack_machine;
  4536.     };
  4537.     {
  4538.         x = 11;
  4539.         y = 91;
  4540.         m = shop_drink_automat;
  4541.     };
  4542.     {
  4543.         x = 12;
  4544.         y = 91;
  4545.         m = shop_snack_machine;
  4546.     };
  4547.     {
  4548.         x = 209;
  4549.         y = 66;
  4550.         m = shop_drink_automat;
  4551.     };
  4552.     {
  4553.         x = 210;
  4554.         y = 66;
  4555.         m = shop_snack_machine;
  4556.     };
  4557.     {
  4558.         x = 185;
  4559.         y = 186;
  4560.         m = shop_mc;
  4561.     };
  4562.     {
  4563.         x = 112;
  4564.         y = 221;
  4565.         m = shop_drink_automat;
  4566.     };
  4567.     {
  4568.         x = 113;
  4569.         y = 221;
  4570.         m = shop_snack_machine;
  4571.     };
  4572.     {
  4573.         x = 102;
  4574.         y = 176;
  4575.         m = shop_cars;
  4576.     };
  4577.     {
  4578.         x = 34;
  4579.         y = 21;
  4580.         m = shop_water;
  4581.     };
  4582.     {
  4583.         x = 129;
  4584.         y = 77;
  4585.         m = shop_water;
  4586.     };
  4587.     {
  4588.         x = 31;
  4589.         y = 142;
  4590.         m = job_menu;
  4591.     };
  4592. }
  4593.  
  4594. -----------------------------
  4595. --    IRC CHANNEL CONFIG   --
  4596. -----------------------------
  4597.  
  4598.  
  4599. --------------------------
  4600. --**    ADVERTISE     **--
  4601. --------------------------
  4602.  
  4603. timer(600000,"advertise")
  4604. function advertise()
  4605.     msg("©255255255Tip: Are you feel hungry? Go to eat any restaurants, or vending-machines!");
  4606. end
  4607.  
  4608. timer(900000,"advertise2")
  4609. function advertise2()
  4610.     msg("©255255255Tip: Are you see player breaking rules? Report him with /report <id> <reason>");
  4611. end
Add Comment
Please, Sign In to add comment