Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --#lib init#
- Fly = {}
- flystorage = 123456
- function Fly:new(cid)
- local bool = getPlayerStorageValue(cid, flystorage)
- if(bool == -1)then bool = false end
- return setmetatable({cid = cid, active = bool}, {__index = self})
- end
- function Fly:isFlying()
- return self.active
- end
- function Fly:activeFly()
- self.active = true
- setPlayerStorageValue(cid, flystorage, true)
- end
- function Fly:flyUp()
- if(isCreature(self.cid))then
- local newpos = getThingPos(self.cid)
- newpos.z = newpos.z + 1
- if not(getTileInfo(newpos))then
- doCreateItem(101,1, newpos)
- end
- doTeleportThing(self.cid, newpos)
- else
- self.active = false
- end
- end
- function Fly:flyDown()
- if(isCreature(self.cid))then
- local newpos = getThingPos(self.cid)
- newpos.z = newpos.z - 1
- if not(getTileInfo(newpos))then
- doCreateItem(101,1, newpos)
- end
- doTeleportThing(self.cid, newpos)
- else
- self.active = false
- end
- end
- function Fly:deactiveFly()
- self.active = false
- setPlayerStorageValue(cid, flystorage, false)
- end
- -- #endlib#
- -- #creature init#
- function onDirection(cid, old, current)
- local fly = Fly:new(cid)
- local posold = getPositionByDirection(getThingPos(cid), old, 1)
- local itemold = getTileItemById(posold, 101)
- if(itemold)then
- doRemoveItem(itemold, 1)
- end
- if(fly:isFlying())then
- doCreateItem(101, 1, getPositionByDirection(getThingPos(cid), current, 1))
- end
- return true
- end
- function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
- local itemold = getTileItemById(lastPosition, 101)
- if(itemold)then
- doRemoveItem(itemold, 1)
- end
- if(fly:isFlying())then
- doCreateItem(101, 1, getCreatureLookPosition(cid))
- end
- return true
- end
- -- #end creature
- -- #talk example
- function onSay(cid, words, param, channel)
- local fly = Fly:new(cid)
- if(param == "ativar")then
- fly:activeFly()
- elseif(param == "desativa")then
- fly:deactiveFly()
- elseif(param == "desce")then
- fly:flyDown()
- elseif(param == "sobe")then
- fly:flyUp()
- else
- doPlayerSendCancel(cid, "Invalid parameteres")
- end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement