Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.76 KB | None | 0 0
  1. function removeSummons(cid)
  2. if #getCreatureSummons(cid) > 0 then
  3. for x=1,#getCreatureSummons(cid) do
  4. doRemoveCreature(getCreatureSummons(cid)[x])
  5. end
  6. end
  7. end
  8. function doCreateChannelTVs(cid)
  9. if not isCreature(cid) then return true end
  10. doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_TV_CAM, "doCreate")
  11. end
  12.  
  13. function doOpenChannelTVs(cid)
  14. if not isCreature(cid) then return true end
  15. doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_TV_CAM, "openAllTVS|" .. getAllChannelsTvs())
  16. end
  17.  
  18. function createChannel(cid, buffer)
  19. if getGlobalStorageValue(storages.globalsTV) == -1 then setGlobalStorageValue(storages.globalsTV, "") end
  20. if buffer:explode("/")[2]:len() < 6 then
  21. doSendMsg(cid, "O canal deve ter no minimo 6 caracteres.")
  22. return true
  23. elseif buffer:explode("/")[2]:len() > 11 then
  24. doSendMsg(cid, "O canal deve ter no maximo 11 caracteres.")
  25. return true
  26. end
  27. setGlobalStorageValue(storages.globalsTV, getGlobalStorageValue(storages.globalsTV) .. "/" .. getCreatureName(cid))
  28. if not isCreature(cid) then return true end
  29. doCreatePrivateChannel(cid)
  30. local horas, mins, secs = os.date("*t").hour, os.date("*t").min, os.date("*t").sec
  31. setPlayerStorageValue(cid, storages.TVHoras, horas)
  32. setPlayerStorageValue(cid, storages.TVMins, mins)
  33. setPlayerStorageValue(cid, storages.TVSecs, secs)
  34. setPlayerStorageValue(cid, storages.playerTVName, buffer:explode("/")[2])
  35. setPlayerStorageValue(cid, storages.playerTVPass, buffer:explode("/")[3])
  36. doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_TV_CAM, "contar:" .. buffer:explode("/")[2])
  37. end
  38.  
  39. function doResetPlayerTVSystem(cid)
  40. setPlayerStorageValue(cid, storages.TVHoras, -1)
  41. setPlayerStorageValue(cid, storages.TVMins, -1)
  42. setPlayerStorageValue(cid, storages.TVSecs, -1)
  43. setPlayerStorageValue(cid, storages.playerIsTvWatching, -1)
  44. setPlayerStorageValue(cid, storages.playerTVName, -1)
  45. setPlayerStorageValue(cid, storages.playerTVPass, -1)
  46. setPlayerStorageValue(cid, storages.playerListWatchs, -1)
  47. setPlayerStorageValue(cid, storages.playerIsTvWatching, -1)
  48. setPlayerStorageValue(cid, storages.playerIsTvWhosWatching, -1)
  49. setPlayerStorageValue(cid, storages.playerIsTvInitialPos, -1)
  50. doSendPlayerExtendedOpcode(cid, 126, "nao")
  51. end
  52.  
  53. function closeInClientChannmel(cid)
  54. if not isCreature(cid) then return true end
  55. removeAllPlayerInTheChannel(cid)
  56. doRemoveIntoPrivateChannel(cid, getCreatureName(cid))
  57. removePlayerInTheChannel(cid)
  58. doSendMsg(cid, "Você fechou seu canal.")
  59. doResetPlayerTVSystem(cid)
  60. end
  61.  
  62. function closeInServerChannmel(cid)
  63. if not isCreature(cid) then return true end
  64. removeAllPlayerInTheChannel(cid)
  65. --doRemoveIntoPrivateChannel(cid, getCreatureName(cid))
  66. removePlayerInTheChannel(cid)
  67. doSendPlayerExtendedOpcode(cid, opcodes.OPCODE_TV_CAM, "closeGraveando")
  68. doSendMsg(cid, "Você fechou seu canal.")
  69. doResetPlayerTVSystem(cid)
  70. end
  71.  
  72. function isInChannelsArray(cid)
  73. if not isCreature(cid) then return false end
  74. local name = getCreatureName(cid)
  75. local channelsArray = getGlobalStorageValue(storages.globalsTV)
  76. local ret = false
  77. if channelsArray == -1 then return ret end
  78. channelsArray = channelsArray:explode("/")
  79. for i = 1, #channelsArray do
  80. if name == channelsArray[i] then
  81. ret = true
  82. break
  83. end
  84. end
  85. return ret
  86. end
  87.  
  88. function removePlayerInTheChannel(cid)
  89. if not isCreature(cid) then return false end
  90. local name = getCreatureName(cid)
  91. local channelsArray = getGlobalStorageValue(storages.globalsTV)
  92. local ret = ""
  93. if channelsArray == -1 then return ret end
  94. channelsArray = channelsArray:explode("/")
  95. for i = 1, #channelsArray do
  96. if name ~= channelsArray[i] then
  97. ret = ret .. "/" .. channelsArray[i]
  98. end
  99. end
  100. setGlobalStorageValue(storages.globalsTV, ret)
  101. end
  102.  
  103. function getPlayerChannelName(cid)
  104. if getPlayerStorageValue(cid, storages.playerTVName) ~= -1 then
  105. return getPlayerStorageValue(cid, storages.playerTVName)
  106. end
  107. return ""
  108. end
  109.  
  110. function getAllChannelsTvs()
  111. local channelsArray = getGlobalStorageValue(storages.globalsTV)
  112. local ret = ""
  113. if channelsArray == -1 then return ret end
  114. channelsArray = channelsArray:explode("/")
  115.  
  116. for i = 1, #channelsArray do
  117. local player = getCreatureByName(channelsArray[i])
  118. if isCreature(player) then
  119. ret = ret .. channelsArray[i] .. "/" .. getPlayerChannelName(player).. "/" .. getPlayerStorageValue(player, storages.playerTVPass) .. "|"
  120. end
  121. end
  122. return ret
  123. end
  124.  
  125. function isRecording(cid)
  126. if not isCreature(cid) then return true end
  127. if getPlayerStorageValue(cid, storages.playerTVName) ~= -1 then
  128. return true
  129. end
  130. return false
  131. end
  132.  
  133. function isWatchingTv(cid)
  134. if not isCreature(cid) then return true end
  135. if getPlayerStorageValue(cid, storages.playerIsTvWatching) == -1 then
  136. return false
  137. end
  138. return true
  139. end
  140.  
  141. function movePlayerListWatchingMe(cid, toPos)
  142. if type(getPlayerStorageValue(cid, storages.playerListWatchs)) ~= "string" then return true end
  143. local listWatchs = getPlayerStorageValue(cid, storages.playerListWatchs):explode("/")
  144. for i = 1, #listWatchs do
  145. local player = getCreatureByName(listWatchs[i])
  146. if isCreature(player) then
  147. doTeleportThing(player, toPos, true)
  148. end
  149. end
  150. end
  151.  
  152. function doWatch(cid, watched)
  153. if not isCreature(cid) or not isCreature(watched) then return true end
  154. local listWatchs = getPlayerStorageValue(watched, storages.playerListWatchs)
  155. local myName = getCreatureName(cid)
  156. if type(listWatchs) ~= "string" then
  157. setPlayerStorageValue(watched, storages.playerListWatchs, "")
  158. listWatchs = getPlayerStorageValue(watched, storages.playerListWatchs)
  159. end
  160. setPlayerStorageValue(watched, storages.playerListWatchs, addStringIntoString(listWatchs, myName))
  161. if isPlayer(watched) then
  162. doInviteToPrivateChannel(watched, myName)
  163. doSendMsg(watched, myName .." is now watching you.")
  164. end
  165. setPlayerStorageValue(cid, storages.playerIsTvWatching, 1)
  166. setPlayerStorageValue(cid, storages.playerIsTvWhosWatching, getCreatureName(watched))
  167. local pos = getThingPos(cid)
  168. setPlayerStorageValue(cid, storages.playerIsTvInitialPos, "/" .. pos.x .. "," .. pos.y .. "," .. pos.z .. "/")
  169.  
  170. local out, oldDir, oldPos = getCreatureOutfit(cid), getCreatureLookDir(cid), getThingPos(cid)
  171.  
  172. doCreatureSetHideHealth(cid, true)
  173. doSetCreatureOutfit(cid, {lookType = 6}, -1)
  174. doSendPlayerExtendedOpcode(cid, 126, "sim")
  175. if not isGod(cid) then
  176. setPlayerGroupId(cid, 4)
  177. end
  178. removeSummons(cid)
  179. doChangeSpeed(cid, -getCreatureSpeed(cid))
  180. doChangeSpeed(cid, getCreatureSpeed(watched))
  181. doSendPlayerExtendedOpcode(watched, opcodes.OPCODE_TV_CAM, "add")
  182. doCreatureSetNoMove(cid, true)
  183. doTeleportThing(cid, getThingPos(watched), false)
  184. doSummonNPCWatch(cid, out, oldDir, oldPos)
  185. end
  186.  
  187. function removeAllPlayerInTheChannel2(cid)
  188. if type(getPlayerStorageValue(cid, storages.playerListWatchs)) ~= "string" then return true end
  189. local listWatchs = getPlayerStorageValue(cid, storages.playerListWatchs):explode("/")
  190. for i = 1, #listWatchs do
  191. local player = getCreatureByName(listWatchs[i])
  192. if isCreature(player) then
  193. doRetirePlayerToChannel(player)
  194. end
  195. end
  196. end
  197.  
  198. function removeAllPlayerInTheChannel(cid)
  199. if type(getPlayerStorageValue(cid, storages.playerListWatchs)) ~= "string" then return true end
  200. local listWatchs = getPlayerStorageValue(cid, storages.playerListWatchs):explode("/")
  201. for i = 1, #listWatchs do
  202. local player = getCreatureByName(listWatchs[i])
  203. if isCreature(player) then
  204. doRetirePlayerToChannel(player)
  205. end
  206. end
  207. doResetPlayerTVSystem(cid)
  208. end
  209.  
  210. function doRetirePlayerToChannel(cid)
  211. setPlayerStorageValue(cid, storages.playerIsTvWatching, -1)
  212. doSendPlayerExtendedOpcode(cid, 126, "nao")
  213. doRemoveCondition(cid, CONDITION_OUTFIT)
  214. doCreatureSetHideHealth(cid, false)
  215. doRegainSpeed(cid)
  216. if not isGod(cid) then
  217. setPlayerGroupId(cid, 1)
  218. end
  219. doCreatureSetNoMove(cid, false)
  220. doRegainSpeed(cid)
  221. local npc = getCreatureByName(getCreatureName(cid).." ")
  222. local olddir = 0
  223. if isCreature(npc) then
  224. olddir = getCreatureLookDir(npc)
  225. local pos = getThingPos(npc)
  226. doRemoveCreature(npc)
  227. end
  228. local initialPos = getPlayerStorageValue(cid, storages.playerIsTvInitialPos):explode("/")
  229. local pos = initialPos[1]:explode(",")
  230. doTeleportThing(cid, {x = pos[1], y = pos[2], z = pos[3]}, false)
  231. doCreatureSetLookDir(cid, olddir)
  232. local PlayerWatched = getCreatureByName(getPlayerStorageValue(cid, storages.playerIsTvWhosWatching))
  233. if isCreature(PlayerWatched) then
  234. local watchers = getPlayerStorageValue(PlayerWatched, storages.playerListWatchs)
  235. local removeString = removeStringIntoString(watchers, getCreatureName(cid))
  236. setPlayerStorageValue(PlayerWatched, storages.playerListWatchs, removeString)
  237. doSendPlayerExtendedOpcode(PlayerWatched, opcodes.OPCODE_TV_CAM, "remove")
  238. if isPlayer(PlayerWatched) then -- tournament channel não
  239. doRemoveIntoPrivateChannel(PlayerWatched, getCreatureName(cid))
  240. doSendMsg(PlayerWatched, getCreatureName(cid) .." is not watching you anymore.")
  241. end
  242. end
  243. end
  244.  
  245. function removeStringIntoString(str1, str2)
  246. local channelsArray = str1
  247. local ret = ""
  248. if channelsArray == -1 then return ret end
  249. channelsArray = channelsArray:explode("/")
  250. for i = 1, #channelsArray do
  251. if str2 ~= channelsArray[i] then
  252. ret = ret .. "/" .. channelsArray[i]
  253. end
  254. end
  255. return ret
  256. end
  257.  
  258. function addStringIntoString(str1, str2)
  259. local ret = str1
  260. if ret == -1 then return "/" end
  261. ret = ret .. "/" .. str2
  262. return ret
  263. end
  264.  
  265. function doSummonNPCWatch(cid, out, oldDir, oldPos)
  266. if isGod(cid) then return true end
  267. local dir = "data/npc/TVNPC.xml"
  268. --local a = io.open(dir, "a+")
  269. --local b = a:read("*all")
  270. --a:close()
  271. local o = out
  272. local olddir = oldDir
  273. local oldpos = oldPos
  274.  
  275. local b = '<?xml version="1.0" encoding="UTF-8"?><npc name="TVNPC" speed="0"><health now="645" max="645"/><look type="510" head="75" body="93" legs="92" feet="42"/><parameters></parameters></npc>'
  276. local npcname = 'name="'..getCreatureName(cid)..' "'
  277. local npchealth = 'health now="'..getCreatureHealth(cid)..'" max="'..getCreatureMaxHealth(cid)..'"'
  278. local npcoutfit = 'look type="'..o.lookType..'" head="'..o.lookHead..'" body="'..o.lookBody..'" legs="'..o.lookLegs..'" feet="'..o.lookFeet..'"'
  279. b = string.gsub(b, 'name="(.-)"', npcname)
  280. b = string.gsub(b, 'health now="(.-)" max="(.-)"', npchealth)
  281. b = string.gsub(b, 'look type="(.-)" head="(.-)" body="(.-)" legs="(.-)" feet="(.-)"', npcoutfit)
  282.  
  283. local c = io.open(dir, "w")
  284. c:write(b)
  285. c:close()
  286.  
  287. local n = doCreateNpc("TVNPC", oldpos)
  288. doCreatureSetLookDir(n, olddir)
  289. setPlayerStorageValue(n, 9891, getPlayerSex(cid))
  290. setPlayerStorageValue(n, 697548, getPlayerDesc(n, cid, true)) --alterado v1.7
  291. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement