GlobalEvent [TFS 1.x] Capacity Affects Player Speed

Discussion in 'GlobalEvents, Spells & CreatureEvents' started by BboyChaos, Oct 17, 2016.

  1. BboyChaos

    BboyChaos New Member

    Joined:
    May 20, 2014
    Messages:
    10
    Likes Received:
    1
    Best Answers:
    0
    Code (Text):
    1. function onThink(interval, lastExecution, thinkInterval)
    2.   local players_online = Game.getPlayers()
    3.   for _, player_name in ipairs(players_online) do
    4.     local player = Player(player_name)
    5.     local player_max_capacity = player:getCapacity()
    6.     local player_free_capacity = player:getFreeCapacity()
    7.     local player_percentage_capacity_free = player_free_capacity / (player_max_capacity * 0.01)
    8.     local player_base_speed = player:getBaseSpeed()
    9.     local player_speed = player_percentage_capacity_free * (player_base_speed * 0.01)
    10.     if player_speed < 220 then player_speed = 220 end
    11.     doChangeSpeed(player:getName(), -player:getSpeed() + player_speed)
    12.   end
    13.   return true
    14. end
     
  2. Xeraphus

    Xeraphus Support Team Support Team Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,116
    Likes Received:
    793
    Best Answers:
    66
    Code (Text):
    1.  
    2. function onThink(interval, lastExecution, thinkInterval)
    3.   for _, player_name in ipairs(Game.getPlayers()) do
    4.     local player = Player(player_name)
    5.     local player_speed = player:getFreeCapacity() / (player:getCapacity() * 0.01) * (player:getBaseSpeed() * 0.01)
    6.     player:changeSpeed( -player:getSpeed() + (player_speed < 220) and 220 or player_speed)
    7.   end
    8.   return true
    9. end
    you don't need 10 locals to do the same thing as you could in a few lines
     
    silveralol and BboyChaos like this.
  3. calveron

    calveron Bravemansworld Premium User

    Joined:
    Feb 5, 2008
    Messages:
    163
    Likes Received:
    8
    Best Answers:
    0
    attempt to perform arithmetic on a boolean value
     
  4. Xeraphus

    Xeraphus Support Team Support Team Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,116
    Likes Received:
    793
    Best Answers:
    66
    new code, original code he made loops forever and keeps adding speed to the player forever
    Code (Text):
    1.  
    2. local p = {}
    3.  
    4. function onThink(interval, lastExecution, thinkInterval)
    5.   for _, name in ipairs(Game.getPlayers()) do
    6.     local player = Player(name)
    7.     local guid = player:getGuid()
    8.     local maxCap, freeCap = player:getCapacity(), player:getFreeCapacity()
    9.     if not p[guid] or p[guid] ~= freeCap then
    10.         local delta = freeCap / (maxCap * 0.01) * (player:getBaseSpeed() * 0.01)
    11.         player:changeSpeed(-player:getSpeed() + ((delta <= 220) and 220 or delta))
    12.         p[guid] = freeCap
    13.     end
    14.   end
    15.   return true
    16. end
    this sets the player's free cap to a table using their GUID, and only changes speed if they don't have an entry in the table or if their capacity has changed.
     
    HeberPcL likes this.
  5. calveron

    calveron Bravemansworld Premium User

    Joined:
    Feb 5, 2008
    Messages:
    163
    Likes Received:
    8
    Best Answers:
    0
    How do I add it? :=D
     
  6. Xeraphus

    Xeraphus Support Team Support Team Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,116
    Likes Received:
    793
    Best Answers:
    66
    the same way you added the other one
    wut
     
  7. calveron

    calveron Bravemansworld Premium User

    Joined:
    Feb 5, 2008
    Messages:
    163
    Likes Received:
    8
    Best Answers:
    0
    The script works partly, however, the speed wont go back when I remove something from my char, I loose speed when I take it back tho

    Seems to work when remove more than just the backpack o0
     
    Last edited by a moderator: Oct 19, 2016
  8. Xeraphus

    Xeraphus Support Team Support Team Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,116
    Likes Received:
    793
    Best Answers:
    66
    works fine for me
    the more free cap you have the faster you are
    the less you have the slower you are
    o.o
     
  9. Mariuskens

    Mariuskens Sword Art Online 2D-MMORPG

    Joined:
    Nov 21, 2008
    Messages:
    866
    Likes Received:
    80
    Best Answers:
    0
    But if you use utani hur your speed changed 1 second but return again to first stage.. who have solution for this┬┐?
     
  10. Xeraphus

    Xeraphus Support Team Support Team Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,116
    Likes Received:
    793
    Best Answers:
    66
    solution: dont use utani hur
     
    strutZ likes this.

Share This Page

Loading...