Flying mount system TFS 1.2

Mkalo

ボーカロイド
Joined
Jun 1, 2011
Messages
1,120
Reaction score
888
Location
Japan
Demo:

You can see the source changes here: https://gist.github.com/Mkalo/32f7b36931f4992fa131252b51fbbeb9

Install this lib in your server: http://pastebin.com/3p1DU2Qa
(All the config is in the lib)

Now to events and shit: (The tags are commented inside the code.)
Creaturescript:
Code:
--     <event type="move" name="FlyEvent" script="flyevent.lua" />
function onMove(player, fromPosition, toPosition)
    if PvpRestrictions:lower() == "high" and player:isPzLocked() then
        return true
    end

    if player:isFlying() then
        local fromTile = Tile(fromPosition)
        local fromItem = fromTile:getItemById(460)
        if fromItem then
            fromItem:remove()
        end
        toPosition:createFlyFloor()
    end
    return true
end
Talkaction:
Code:
--    <talkaction words="!down" script="fly.lua" />
--    <talkaction words="!up" script="fly.lua" />

local exhauststorage = 16500
function onSay(player, words)
    if not player:isFlying() then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not flying.")
        return false
    end

    if player:isPzLocked() and PvpRestrictions:lower() == "high" then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You cannot use this command in fight.")
        return false
    end

    local last = player:getStorageValue(exhauststorage)
    local interval = ChangeFloorInterval
    if PvpRestrictions:lower() == "medium" and player:isPzLocked() then
        interval = ChangeFloorIntervalPZ
    end

    if last+interval > os.time() then
        player:sendCancelMessage(RETURNVALUE_YOUAREEXHAUSTED)
        return false
    end

    if words == "!up" then
        local ret = player:flyUp()
        if ret == false then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You cannot fly up.")
        else
            player:setStorageValue(exhauststorage, os.time())
        end
    elseif words == "!down" then
        local ret = player:flyDown()
        if ret == false then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You cannot fly down.")
        else
            player:setStorageValue(exhauststorage, os.time())
        end
    end
    return false
end
Now to the event changes (data/events):
Change events.xml where:
Code:
    <event class="Creature" method="onTargetCombat" enabled="0" />
To enabled="1"
And add this:
Code:
    <event class="Player" method="onToggleMount" enabled="1" />
Edit events/scripts/creature.lua replacing the onTargetCombat function to this:
Code:
function Creature:onTargetCombat(target)
    if self and target then
        if PvpRestrictions:lower() == "high" then
            if self:isPlayer() and self:isFlying() then
                local pos = self:getPosition()
                local tile = Tile(pos)
                if tile:getItemById(460) then
                    return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
                end
            end

            if target:isPlayer() and target:isFlying() then
                local pos = target:getPosition()
                local tile = Tile(pos)
                if tile:getItemById(460) then
                    return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
                end
            end
        end
    end
    return true
end
And add this function to events/scripts/player.lua:

Code:
function Player:onToggleMount(mountid, mount)
    if mount then
        if isInArray(FlyingMounts, mountid) then
            if isInArray({"high", "medium"}, PvpRestrictions:lower()) and self:isPzLocked() then
                self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You cannot start flying now.")
                return false
            end
            self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are now flying.")
            self:activateFly()
        end
    elseif self:isFlying() then
        local ret = self:deactivateFly()
        if ret then
            self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are no longer flying.")
        else
            self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You can't deactivate fly now.")
        end
        return ret
    end
    return true
end
Put this in your logout.lua under "function onLogout(player)":
Code:
    if player:isFlying() then
        player:sendCancelMessage("You cannot logout while flying.")
        return false
    end

Its done, it should be working. Requested in the topic:
Free Scripting. TFS [1.2]

Tomorrow I will add a video, but its pretty simple, certain mounts have the ability to fly (like in pokemon otservers and shit.). The pvp stuff may have bugs, please report if you spot any.
 
Last edited:

strutZ

Australian OT Member {AKA Beastn}
Joined
Nov 16, 2014
Messages
1,334
Reaction score
468
o.0 wtf? cant wait to see the video man!
 
OP
Mkalo

Mkalo

ボーカロイド
Joined
Jun 1, 2011
Messages
1,120
Reaction score
888
Location
Japan
o.0 wtf? cant wait to see the video man!
Done

-- Changed the code a bit fixing a bug in the targetcombat and added the logout part to prevent players from logging out while flying. (in case of crash they are going to be sent to the temple.)
 

Itutorial

Advanced OT User
Joined
Dec 23, 2014
Messages
1,418
Reaction score
310
I don't think he installed the source edit... or he has the wrong version of TFS
 
OP
Mkalo

Mkalo

ボーカロイド
Joined
Jun 1, 2011
Messages
1,120
Reaction score
888
Location
Japan
Updated the code, later I will update again to add some source changes to fix a bug (Players can change mount while mounted and it doesn't trigger togglemount.)
 
OP
Mkalo

Mkalo

ボーカロイド
Joined
Jun 1, 2011
Messages
1,120
Reaction score
888
Location
Japan
Temporary solution:
Code:
function Creature:onChangeOutfit(outfit)
    local current = self:getOutfit()
    if self:isPlayer() and self:isFlying() and current.lookMount ~= 0  and outfit.lookMount ~= 0 and current.lookMount ~= outfit.lookMount then
        return false
    end

    return true
end
It's kinda bad because the player actually changes the mount, it just doesn't register in his outfit.
 

zbizu

Veteran OT User
Joined
Nov 22, 2010
Messages
2,460
Reaction score
1,350
Location
Poland
Can't players fly on their own? It's a fictional world anyway and enabling that regardless of using a mount wouldn't change much (unless it's certain anime or concept-based or something).
Btw. You can use a loop which would check player's outfit every x seconds as a workaround (onThink or something).
 

William Sezo

Rookie but passionate
Joined
May 6, 2016
Messages
43
Reaction score
6
Location
Brazil
Woah! Never thought I would see that.
Can I simply install it in my TFS 1.2 or do I need to recompile the server?
 
OP
Mkalo

Mkalo

ボーカロイド
Joined
Jun 1, 2011
Messages
1,120
Reaction score
888
Location
Japan
Top