[TFS 1.2] creature:sendSquare(color, sec[,canSee])

Discussion in 'Mods & Lua Functions' started by Static_, Aug 13, 2016.

  1. Static_

    Static_ Premium User Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,932
    Likes Received:
    1,233
    Best Answers:
    165
    Usage: creature:sendSquare(color, sec [,canSee])

    Example: creature:sendSquare(180, 5) -> Sends red colored square to creature for 5 seconds

    Note: canSee should be a table argument such as: {'Playername', 'Playername2'}

    Video

    lib/core/creature.lua
    Code (Text):
    1.  
    2. local function sendSquare(cid, color, sec, n, send)
    3.     local creature = Creature(cid)
    4.     if not creature then
    5.         return false
    6.     end
    7.     if n <= sec then
    8.         local pos = creature:getPosition()
    9.         local msg = NetworkMessage()
    10.         msg:addByte(0x93)
    11.         msg:addU32(cid)
    12.         msg:addByte(0x01)
    13.         msg:addByte(color)
    14.         for i = 1, #send do
    15.             if pos:getDistance(send[i]:getPosition()) <= 7 then
    16.                 msg:sendToPlayer(send[i])
    17.             end
    18.         end
    19.         addEvent(sendSquare, 1000, cid, color, sec, n + 1, send)
    20.     end
    21. end
    22.  
    23. function Creature:sendSquare(color, sec, canSee, n)
    24.     --// Creature:sendSquare(color, sec[, canSee])
    25.     local pos = self:getPosition()
    26.  
    27.     --// Create a send table if canSee is an argument (otherwise uses spectators)
    28.     local specs = Game.getSpectators(pos, false, true, 0, 8, 0, 6)
    29.     local send = {}
    30.     if canSee then
    31.         if type(canSee) == 'table' then
    32.             for i = 1, #specs do
    33.                 if isInArray(canSee, specs[i]:getName()) then
    34.                     send[#send+1] = specs[i]
    35.                 end
    36.             end
    37.         else
    38.             return print('Error [Creature:sendSquare] invalid argument type for canSee')
    39.         end
    40.     end
    41.     send = (next(send) and send) or specs
    42.     sendSquare(self:getId(), color, sec, (n and n+1) or 0, send)
    43.     return true
    44. end
    45.  
     
    Last edited: Dec 31, 2016
    zbizu and HeberPcL like this.
  2. Slavi Dodo

    Slavi Dodo #define SLAVI32 _WIN32

    Joined:
    Sep 9, 2015
    Messages:
    544
    Likes Received:
    216
    Best Answers:
    0
    1- You can use real send square function which is added on player.h
    2- And it should be Player.sendSquare since this function is not related to creature itself while it's son ( player )
    3- Tibia doesn't require the message to be sent only when creature(to be squared) is on screen or even being a known creature.

    Some information about squares
    The second byte ( length )
    • 0 means remove
    • 1 means flashing for a second
    • 2 means until another notification

    ----------------------------------------------
    Information is shared by development of Fortissimum, especially E-PvP system.
     
    Last edited: Aug 14, 2016
    HeberPcL likes this.
  3. Static_

    Static_ Premium User Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,932
    Likes Received:
    1,233
    Best Answers:
    165
    updated function

    forgot to address this but here i am 4 months later

    1. yes i know but too lazy to implement it in sources
    2. it is related to creature itself, this is for all creatures, not just player
    3. yes i know, but there is no point in sending it if no one will be seeing it.
     
  4. Dyabl0

    Dyabl0 Yes!

    Joined:
    Sep 22, 2009
    Messages:
    1,856
    Likes Received:
    254
    Best Answers:
    8
    Can be possible if player is red skull it gets red square automatically until it loses? However, great work.
     
  5. Static_

    Static_ Premium User Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,932
    Likes Received:
    1,233
    Best Answers:
    165
    Code (Text):
    1.  
    2. local skulls = {
    3.     SKULL_YELLOW = TEXTCOLOR_YELLOW,
    4.     SKULL_WHITE = TEXTCOLOR_WHITE,
    5.     SKULL_RED = TEXTCOLOR_RED,
    6.     SKULL_BLACK = TEXTCOLOR_BLACK,
    7.     SKULL_ORANGE = TEXTCOLOR_ORANGE
    8. }
    9.  
    10. local function sendSkullSquare(cid)
    11.     local player = Player(cid)
    12.     if not player then
    13.         return
    14.     end
    15.     local skullColor = skulls[player:getSkull()]
    16.     if skullColor then
    17.         player:sendSquare(skullColor, 1)
    18.         addEvent(sendSkullSquare, 1000, cid)
    19.     end
    20. end
    21.  
    22. function onLogin(player)
    23.     sendSkullSquare(player:getId())
    24.     return true
    25. end
     
    HeberPcL and primate like this.
  6. Dyabl0

    Dyabl0 Yes!

    Joined:
    Sep 22, 2009
    Messages:
    1,856
    Likes Received:
    254
    Best Answers:
    8
    Doesn't work for some reason, can you send me a private message so I can specify more?
     
    Last edited: Dec 19, 2016
  7. Static_

    Static_ Premium User Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,932
    Likes Received:
    1,233
    Best Answers:
    165
    updated, small bugfix (couldn't send networkmessage through addevent) + rewrote canSee a bit (less confusing)
     
  8. Forrest

    Forrest Banned User

    Joined:
    Dec 21, 2016
    Messages:
    58
    Likes Received:
    12
    Best Answers:
    0
    C++
    const.h
    Code (Text):
    1.  
    2. enum SquareColor_t : uint8_t {
    3.     SQ_COLOR_BLACK = 0,
    4.     SQ_COLOR_BLUE = 5,
    5.     SQ_COLOR_LIGHTGREEN = 30,
    6.     SQ_COLOR_LIGHTBLUE = 35,
    7.     SQ_COLOR_MAYABLUE = 95,
    8.     SQ_COLOR_DARKRED = 108,
    9.     SQ_COLOR_LIGHTGREY = 129,
    10.     SQ_COLOR_SKYBLUE = 143,
    11.     SQ_COLOR_PURPLE = 155,
    12.     SQ_COLOR_RED = 180,
    13.     SQ_COLOR_ORANGE = 198,
    14.     SQ_COLOR_YELLOW = 210,
    15.     SQ_COLOR_WHITE_EXP = 215,
    16.     SQ_COLOR_NONE = 255,
    17. };
    18.  
    luascript.cpp
    Code (Text):
    1.  
    2. registerEnum(SQ_COLOR_BLACK)
    3. registerEnum(SQ_COLOR_BLUE)
    4. registerEnum(SQ_COLOR_LIGHTGREEN)
    5. registerEnum(SQ_COLOR_LIGHTBLUE)
    6. registerEnum(SQ_COLOR_MAYABLUE)
    7. registerEnum(SQ_COLOR_DARKRED)
    8. registerEnum(SQ_COLOR_LIGHTGREY)
    9. registerEnum(SQ_COLOR_SKYBLUE)
    10. registerEnum(SQ_COLOR_PURPLE)
    11. registerEnum(SQ_COLOR_RED)
    12. registerEnum(SQ_COLOR_ORANGE)
    13. registerEnum(SQ_COLOR_YELLOW)
    14. registerEnum(SQ_COLOR_WHITE_EXP)
    15. registerEnum(SQ_COLOR_NONE)
    16.  
    globals.lua
    Code (Text):
    1.  
    2. squareColors = {
    3.     ['black'] = SQ_COLOR_BLACK,
    4.     ['blue'] = SQ_COLOR_BLUE,
    5.     ['light green'] = SQ_COLOR_LIGHTGREEN,
    6.     ['light blue'] = SQ_COLOR_LIGHTBLUE,
    7.     ['maya blue'] = SQ_COLOR_MAYABLUE,
    8.     ['dark red'] = SQ_COLOR_DARKRED,
    9.     ['light grey'] = SQ_COLOR_LIGHTGREY,
    10.     ['sky blue'] = SQ_COLOR_SKYBLUE,
    11.     ['purple'] = SQ_COLOR_PURPLE,
    12.     ['red'] = SQ_COLOR_RED,
    13.     ['orange'] = SQ_COLOR_ORANGE,
    14.     ['yellow'] = SQ_COLOR_YELLOW,
    15.     ['white'] = SQ_COLOR_WHITE_EXP,
    16.     ['none'] = SQ_COLOR_NONE
    17. }
    18.  
     
  9. Static_

    Static_ Premium User Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,932
    Likes Received:
    1,233
    Best Answers:
    165
    data\lib\core\constants.lua
    Code (Text):
    1.  
    2. TEXTCOLOR_BLACK = 0
    3. TEXTCOLOR_BLUE = 5
    4. TEXTCOLOR_GREEN = 18
    5. TEXTCOLOR_TEAL = 35
    6. TEXTCOLOR_LIGHTGREEN = 66
    7. TEXTCOLOR_DARKBROWN = 78
    8. TEXTCOLOR_LIGHTBLUE = 89
    9. TEXTCOLOR_DARKPURPLE = 112
    10. TEXTCOLOR_BROWN = 120
    11. TEXTCOLOR_GREY = 129
    12. TEXTCOLOR_DARKRED = 144
    13. TEXTCOLOR_DARKPINK = 152
    14. TEXTCOLOR_PURPLE = 154
    15. TEXTCOLOR_DARKORANGE = 156
    16. TEXTCOLOR_RED = 180
    17. TEXTCOLOR_PINK = 190
    18. TEXTCOLOR_ORANGE = 192
    19. TEXTCOLOR_DARKYELLOW = 205
    20. TEXTCOLOR_YELLOW = 210
    21. TEXTCOLOR_WHITE = 215
    22. TEXTCOLOR_NONE = 255
     
    Last edited: Dec 22, 2016
  10. Forrest

    Forrest Banned User

    Joined:
    Dec 21, 2016
    Messages:
    58
    Likes Received:
    12
    Best Answers:
    0
    Yes I am aware of that I just added that code for 1 of 2 reasons it shows how to add more values to an enum but it also shows how to registering them for use outside of the server.

    I did not update any of your code, but thought that this additional code was relevant to the body of the thread. Thank you for quoting my post and letting me know something which is pretty obvious since TEXTCOLOR_xx is where I obtained the values for the SQ_COLOR_xx enums.
     

Share This Page

Loading...