Advertisement
Guest User

Untitled

a guest
Jul 19th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.99 KB | None | 0 0
  1. function doPlayerWatchOther(cid, target)
  2.  
  3.     if not isCreature(cid) then return true end
  4.  
  5.     local hasOutfitCond = getCreatureCondition(cid, CONDITION_OUTFIT) and getCreatureOutfit(cid).lookType or -1
  6.     setPlayerStorageValue(cid, 99282, getCreatureSpeed(cid))
  7.     setPlayerStorageValue(cid, 99283, hasOutfitCond)
  8.  
  9.     setPlayerStorageValue(cid, 99285, target)
  10.     doCreatureSetNick(cid, "") --, " ")
  11.  
  12.     local o = getCreatureOutfit(cid)
  13.     local olddir = getCreatureLookDir(cid)
  14.     local oldpos = getThingPos(cid)
  15.  
  16.     doCreatureSetHideHealth(cid, true)
  17.     doPlayerLock(cid)
  18.  
  19.     local dir = "data/npc/TVNPC.xml"
  20.     local a = io.open(dir, "a+")
  21.     local b = a:read("*all")
  22.     a:close()
  23.  
  24.     local npcname = 'name="'..getCreatureName(cid)..'  "'
  25.     local npchealth = 'health now="'..getCreatureHealth(cid)..'" max="'..getCreatureMaxHealth(cid)..'"'
  26.     local npcoutfit = 'look type="'..o.lookType..'" head="'..o.lookHead..'" body="'..o.lookBody..'" legs="'..o.lookLegs..'" feet="'..o.lookFeet..'"'
  27.  
  28.     b = string.gsub(b, 'name="(.-)"', npcname)
  29.     b = string.gsub(b, 'health now="(.-)" max="(.-)"', npchealth)
  30.     b = string.gsub(b, 'look type="(.-)" head="(.-)" body="(.-)" legs="(.-)" feet="(.-)"', npcoutfit)
  31.  
  32.     local c = io.open(dir, "w")
  33.     c:write(b)
  34.     c:close()
  35.  
  36.     o.lookType = 814
  37.  
  38.     doCreatureSetOutfit(cid, o, -1)
  39.     doTeleportThing(cid, getThingPos(target), false)
  40.  
  41.     local n = doCreateNpc("TVNPC", oldpos)
  42.     doCreatureSetLookDir(n, olddir)
  43.     setPlayerStorageValue(n, 9891, getPlayerSex(cid))
  44.     doPlayerSetVocation(cid, getPlayerVocation(cid))
  45.     doChangeSpeed(cid, -getCreatureSpeed(cid))
  46.     doChangeSpeed(cid, getCreatureSpeed(target))
  47.  
  48. end
  49.  
  50. function doPlayerStopWatching(cid)
  51.  
  52.     if not isCreature(cid) then return true end
  53.  
  54.     doPlayerUnlock(cid)
  55.     doCreatureSetNick(cid, "") --, getCreatureName(cid))
  56.  
  57.     local pos = {}
  58.     local speed = getPlayerStorageValue(cid, 99282)
  59.     local npc = getCreatureByName(getCreatureName(cid).."  ")
  60.     local olddir = 0
  61.         if isCreature(npc) then
  62.             olddir = getCreatureLookDir(npc)
  63.             local pos = getThingPos(npc)
  64.             doRemoveCreature(npc)
  65.             doTeleportThing(cid, pos, false)
  66.         end
  67.     doChangeSpeed(cid, -getCreatureSpeed(cid))
  68.     doChangeSpeed(cid, speed)
  69.     doCreatureSetHideHealth(cid, false)
  70.     doCreatureSetLookDir(cid, olddir)
  71.     doCreatureSetNick(cid, getCreatureName(cid))
  72.     setPlayerStorageValue(cid, 99285, -1)
  73.  
  74.     local outfit = getPlayerStorageValue(cid, 99283)
  75.         if outfit >= 1 then
  76.             local newOutfit = getCreatureOutfit(cid)
  77.             newOutfit.lookType = outfit
  78.             doCreatureSetOutfit(cid, newOutfit, -1)
  79. doRemoveCreature(cid)
  80.  
  81.         else
  82.             doCreatureRemoveCondition(cid, CONDITION_OUTFIT)
  83. doRemoveCreature(cid)
  84.         end
  85.  
  86. end
  87.  
  88.  
  89. function getWatchingPlayersFromPos(cid, pos)
  90.     local ret = {}
  91.  
  92.     local cp = {}
  93.     cp.x = pos.x
  94.     cp.y = pos.y
  95.     cp.z = pos.z
  96.  
  97.     for a = 0, 255 do
  98.         cp.stackpos = a
  99.         local b = getTileThingByPos(cp).uid
  100.         if isCreature(b) and getCreatureOutfit(b).lookType == 814 and getPlayerStorageValue(b, 99285) == cid then
  101.             table.insert(ret, b)
  102.         end
  103.     end
  104. return ret
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement