Solved tfs skill after time 1.2

Discussion in 'Support' started by narkotyko, Dec 3, 2017.

Tags:
  1. narkotyko

    narkotyko New Member

    Joined:
    Jan 16, 2016
    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Hello i have question how can i do skill use after time. Example:
    Code (Text):
    1.  
    2. function test3(creature,variant)
    3.         testa:execute(creature, variant)
    4. end
    5.  
    6. function onCastSpell(creature, variant)
    7.     addEvent(test1, 10, creature:getId())
    8.     addEvent(test2, 5000, creature:getId())
    9.     addEvent(test3, 2000)
    10.  
    tes2 and test 3 is speak function and it work. how can do same with test3?
    nevermind i done this :
    Code (Text):
    1.  
    2.  
    3. function test3(variant)
    4.         local creature = Creature(cid)      
    5.         testo:execute(creature, variant)
    6. end
    7.  
    8. function onCastSpell(creature, variant)
    9.     addEvent(test3, 2000,variant)
     
  2. Best Answer:
    Post #2 by Linxsis, Dec 5, 2017
  3. Linxsis

    Linxsis Active Member

    Joined:
    Nov 18, 2017
    Messages:
    144
    Likes Received:
    39
    Best Answers:
    8
    Best Answer
    When writing a function its important to understand how parameters work. A parameter is a place holder telling you the programmer what type of information should be to passed to it.
    As an example let's create a function called Shapes and add to it over time to understand how a function works.
    Code (Lua):
    1. function Shapes()
    2. end
    Now that we have the basics of the function defined lets create a few parameters for it. In this example we'll use the parameters round & square.
    Code (Lua):
    1. function Shapes(round, square)
    2. end
    If we think beyond the scope of programming logic just for this example we can get a better idea of what is going on here. So lets do that now and think in general terms rather than logical. When we pass information to a function its called an argument, this argument must fit a function's parameter in the order that the parameters are defined.
    So if we call or invoke the Shape's function we would need to pass it 2 arguments, so lets do that now lets pass the argument's ball & box.
    Code (Lua):
    1. Shapes(ball, box)
    Normally a ball is round and a box is square, if we were to set the argument list as box, ball we will end up with an unwarranted outcome.

    So to look at your 1st issue you have
    Code (Lua):
    1. function test3(creature,variant)
    2.         testa:execute(creature, variant)
    3. end
    4. function onCastSpell(creature, variant)
    5.     addEvent(test1, 10, creature:getId())
    6.     addEvent(test2, 5000, creature:getId())
    7.     addEvent(test3, 2000)
    In the code above you have 3 addEvent's calling 3 different functions labeled test1, test2, test3 at different intervals. AddEvent's parameters are defined as this
    Code (Lua):
    1. addEvent(function name, time or interval, parameter list)
    In the 1st 2 addEvent call's you are sending the creature id to test1 & test2 however in test3 you aren't sending any information and according to the definition of test3 the function requires an argument of creature & variant . testa I won't even comment on since I don't know what the whole script looks like.

    In your 2nd example
    Code (Lua):
    1. function test3(variant)
    2.         local creature = Creature(cid)  
    3.         testo:execute(creature, variant)
    4. end
    5. function onCastSpell(creature, variant)
    6.     addEvent(test3, 2000,variant)
    There is just 1 addEvent and it is calling test3 at a time or interval of 2 seconds while you are passing variant to test3, test3 is calling Creature and asking for the cid which is not defined or has not been defined.
    So let's clean your code example's up and assuming that testa is a combat object we will include that in the new version of the script.
    Code (Lua):
    1.  
    2. -- test3 2 parameter's require a creature id (cid) and a variant (var)
    3. function test3(cid, var)
    4.     local creature = Creature(cid)
    5.     -- check if creature has been created
    6.     if creature then
    7.         -- if it has execute (assuming testa is a combat object)
    8.         testa:execute(creature, var)
    9.     end
    10. end
    11.  
    12. function onCastSpell(creature, variant)
    13.     -- invoke or call addEvent passing it test3 (function name), have it execute in 2 seconds (2000),
    14.     -- and pass test3 the arguments creature:getId() & variant
    15.     addEvent(test3, 2000, creature:getId(), variant)
    16.     return true
    17. end
     
    narkotyko likes this.
  4. narkotyko

    narkotyko New Member

    Joined:
    Jan 16, 2016
    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Very nice explain! Thank you :)
     

Share This Page

Loading...