• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Lua] Texttag is not showed

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,853
I tried to make a Lua version of my system [Jass] Bounty Controller (GUI - Friendly) but for some reason the texttag is never showed and I don't know why, I checked the variables and they have the value that must have, so I don't know, can you tell me what is wrong?
Lua:
--[[
********************************************************************************************************
**************************************Bounty Controller by HerlySQR*************************************
********************************************************************************************************
 
      https://www.hiveworkshop.com/threads/jass-bounty-controller-gui-friendly.332114/
 
      This library was made to have almost every control of the bounties of the units
      Important is have deactivated the bounties (this system do that, but don't active them)
      and you have to set the values of the bounties manually.

      If you wanna set the default value of the bounty of the units you must use these functions:
          SetBountyBase("FourCC("ID of the unit")","Bounty: Base")
          SetBountyDice("FourCC("ID of the unit")","Bounty: Number of dice")
          SetBountySides("FourCC("ID of the unit")","Bounty: Sides per dice")
      or to do it all in once use this function:
          BOUNTY("FourCC("ID of the unit")","Bounty: Base","Bounty: Number of dice","Bounty: Sides per dice")
      to get a posible bounty from a unit use the function:
          GetBountyFromUnitType("FourCC("ID of the unit")")
      to get the individual values of the bounty use these functions:
          GetBountyBase("FourCC("ID of the unit")")
          GetBountyDice("FourCC("ID of the unit")")
          GetBountySides("FourCC("ID of the unit")")
      
      Is also posible do it in GUI, doing this steps
        SetBountyBase:
              Set BountyUnitID = "Unit-Type of you unit"
              Set BountyBase = "Bounty: Base"
              Trigger - Run BountySetBase (Ignoring conditions)
          SetBountyDice:
              Set BountyUnitID = "Unit-Type of you unit"
              Set BountyDice = "Bounty: Number of dice"
              Trigger - Run BountySetDice (Ignoring conditions)
          SetBountySides:
              Set BountyUnitID = "Unit-Type of you unit"
              Set BountySides = "Bounty: Sides per dice"
              Trigger - Run BountySetBase (Ignoring conditions)
          BOUNTY:
              Set BountyUnitID = "Unit-Type of you unit"
              Set BountyBase = "Bounty: Base"
              Set BountyDice = "Bounty: Number of dice"
              Set BountySides = "Bounty: Sides per dice"
              Trigger - Run BountySet (Ignoring conditions)
 
      The variables used are cleaned automatically, and to get the values do:
          GetBountyBase:
              Set BountyUnitID = "Unit-Type of you unit"
              Trigger - Run BountyGetBase (Ignoring conditions)
              The variable "BountyBase" has the value wanted.
          GetBountyDice:
              Set BountyUnitID = "Unit-Type of you unit"
              Trigger - Run BountyGetDice (Ignoring conditions)
              The variable "BountyDice" has the value wanted.
          GetBountySides:
              Set BountyUnitID = "Unit-Type of you unit"
              Trigger - Run BountyGetBase (Ignoring conditions)
              The variable "BountySides" has the value wanted.
          GetBountyFromUnitType:
              Set BountyUnitID = "Unit-Type of you unit"
              Trigger - Run BountyGet (Ignoring conditions)
              The variable "Bounty" has the value wanted.
 
      To edit the values of a bounty when a unit dies you must have
      a trigger with the event "BountyDeadEvent becomes Equal to 1.00", this event happens when
      a unit dies and the function "BountyText" will be called (That is called it doesn't mean the text will be displayed
      and the bounty will be given to the player, only those two will happen if all the rest of values are valid)
      the variables that you can edit are:
          "Bounty": The quantity of gold or lumber that you will receive (it can be negative).
          "BountyTextTag": The texttag that will be displayed.
          "BountyPermanent": This allows erase it (care, if this value is true and you don't use the texttag later it can be an object leak)
          "BountyColor": The color of the text (if is not set, the color of the text will have the default values depending of the state).
          "BountySize": The size of the text.
          "BountyLifeSpan": The lifetime of the text (if "BountyPermanent" is true this value is useless).
          "BountyFadePoint": How many seconds the text will fade after the lifespan.
          "BountySpeed": The speed of the text.
          "BountyDirection": The direction to the texttag will move.
          "BountyHeight": How many distance the text will be from the floor.
          "BountyShow": To show the text or not.
          "BountyShowNothing": If the Bounty is 0 by default the text is not showed, if you set this to true, the text will be showed even if the bounty is 0.
          "BountyAllowFriendFire": By default the bounty only will happen if the dying unit is enemy of the killing unit, if you set this to true, the bounty will happen even if they weren't enemies.
          "BountyEffect": The effect that will be displayed (In the same place of the text)
          "BountyShowEffect": The effect will be displayed if this value is true.
          "BountyPlayer": The player how will receive the bounty.
          "BountyPlayerState": What type of bounty the player will receive (only "gold" and "lumber" are valid).
          "BountyUnitPos": The position of the text and the effect (If is a unit)
          "BountyLocPos": The position of the text and the effect (If is a location, this have more priority than BountyUnitPos, and is removed with the clear function to prevent object leak, of course only if "BountyNotClear" is not true, and for this reason don't set it to a variable that you gonna use later)
          "BountyPosX", "BountyPosY", "BountyPosZ": The coords of the texttag when is displayed (they are only to read them, and only accesible with the event "BountyEvent becomes Equal to 1.00").
          "BountyWhoSee": The players who can see the text.
      To reffering the killing unit use the variable "BountyKillingUnit" and to the dying unit, "BountyDyingUnit"
      and when the bounty is given an (maybe) the text displayed you can use the event "BountyEvent becomes Equal to 1.00"
      You can't edit the text or the bounty because with this, because it happens after the process ends, but you can get the values
      (Note: If you wanna change the variable "BountyPlayer", to show him the text you have to (maybe) remove the previous player
      and add the new player to the player group "BountyWhoSee".)
 
      If you wanna have your own bounty with another event or function just set some of the variables previously seen
      there are neccesary values like "Bounty", "BountyPlayer", "BountyWhoSee" (You have to add manually the BountyPlayer in this case),
      "BountyUnitPos or BountyLocPos", because they not have default values different than nothing
      and then add in GUI "Trigger - Run BountyText (Ignoring conditions)" or in Lua BountyText()
      But in Lua you can use the function BountyCall(bounty,unitpos,bountyPlayer,addplayer,permanent).
 
      If you wanna have access to the texttag use the variable "BountyTextTag", but you have to know how, you can only do it with the event "BountyEvent"
      if you use this when you use manually the function BountyText better do Temp=BountyText() or Temp=BountyCall(<stuff>).
 
      And if you wanna keep the changes of the previous instance (included "BountyTextTag"), set the variable "BountyNotClear" to true, and you have to do it every instance
      you do if you wanna still saving the changes because this value is returned to false, but carefully, because the next instance can have
      unwanted changes.
 
      Additionally it has the variable LocalPlayer to not use GetLocalPlayer() everytime, if you don't like it,
      just uncoment the "local" before of it in the variables section.

      If you wanna deactive the system do "Trigger - Turn off Bounty_Controller"

  =====================================================================================================
]]


do
    local Bounties={}
    Bounties[0],Bounties[1],Bounties[2]={},{},{}
    --[[local]] LocalPlayer=nil
    --This "constants" can be edited (obviously only valid values)
    local DEF_COLOR_GOLD="ffcc00"
    local DEF_COLOR_LUMBER="32cd32"
    local DEF_SIZE=10
    local DEF_LIFE_SPAN=3.50
    local DEF_SPEED=64
    local DEF_DIRECTION=90
    local DEF_FADE_POINT=2.50
    local DEF_STATE="gold"
    local DEF_HEIGHT=0
    local DEF_SHOW=true
    local DEF_SHOW_NOTHING=false
    local DEF_ALLOW_FRIEND_FIRE=false
    local DEF_EFFECT="UI\\Feedback\\GoldCredit\\GoldCredit.mdl"
    local DEF_SHOW_EFFECT=true
    local DEF_PERMANENT=false
    
    --The functions to set the bounty stats
    
    function SetBountyBase(id,base) Bounties[0][id]=base end
    
    function SetBountyDice(id,dice) Bounties[1][id]=dice end
    
    function SetBountySides(id,sides) Bounties[2][id]=sides end
    
    function BOUNTY(id,base,dice,side)
        SetBountyBase(id,base)
        SetBountyDice(id,dice)
        SetBountySides(id,side)
    end
    
    --The functions to get the bounty stats (that you set before)
    
    function GetBountyBase(id)
        if Bounties[0][id] then
            return Bounties[0][id]
        end
        return 0
    end
    
    function GetBountyDice(id)
        if Bounties[1][id] then
            return Bounties[1][id]
        end
        return 0
    end
    
    function GetBountySides(id)
        if Bounties[2][id] then
            return Bounties[2][id]
        end
        return 0
    end
    
    function GetBountyFromUnitType(id)
        return GetBountyBase(id)+GetRandomInt(0,GetBountyDice(id)*GetBountySides(id))
    end
    
    --This function is runned at the map initialization, if you wanna use it to set your bounties, you can do it
    
    local function SetData()
        
        --[[Peasant]]   BOUNTY(FourCC("hpea"),35,6,3)
        
        for i=0,PLAYER_NEUTRAL_AGGRESSIVE do
            SetPlayerFlagBJ(PLAYER_STATE_GIVES_BOUNTY,false,Player(i))
        end
    end
    
    --To clear the data
    local function Clear()
        if not udg_BountyNotClear then
            udg_BountyTextTag=nil
            udg_BountyColor=nil
            udg_BountySize=DEF_SIZE
            udg_BountyLifeSpan=DEF_LIFE_SPAN
            udg_BountyFadePoint=DEF_FADE_POINT
            udg_BountySpeed=DEF_SPEED
            udg_BountyDirection=DEF_DIRECTION
            udg_BountyPlayerState=DEF_STATE
            udg_BountyHeight=DEF_HEIGHT
            udg_BountyShow=DEF_SHOW
            udg_BountyShowNothing=DEF_SHOW_NOTHING
            udg_BountyAllowFriendFire=DEF_ALLOW_FRIEND_FIRE
            udg_BountyEffect=DEF_EFFECT
            udg_BountyShowEffect=DEF_SHOW_EFFECT
            udg_BountyPermanent=DEF_PERMANENT
            udg_BountyPlayer=nil
            udg_BountyUnitPos=nil
            udg_BountyPosX=0.00
            udg_BountyPosY=0.00
            udg_Bounty=0
            ForceClear(udg_BountyWhoSee)
            if udg_BountyLocPos then
                RemoveLocation(udg_BountyLocPos)
                udg_BountyLocPos=nil
            end
        end
        udg_BountyKillingUnit=nil
        udg_BountyDyingUnit=nil
        udg_BountyNotClear=false
    end
    
    --This is to check the sign of the bounty
    local function Sign(i)
        if i<0 then
            return nil
        end
        return "+"
    end
    
    --The function that runs the bounty and the texttag
    function BountyText()
        local state,tt
        
        if udg_BountyPlayerState=="gold" then
            state=PLAYER_STATE_RESOURCE_GOLD
        elseif udg_BountyPlayerState=="lumber" then
            state=PLAYER_STATE_RESOURCE_LUMBER
        else
            Clear()
            return nil --If the state is not valid, the process stop
        end
        
        if udg_Bounty==0 and not udg_BountyShowNothing then
            udg_BountyShow=false
            udg_BountyShowEffect=false
        end
        
        AdjustPlayerStateSimpleBJ(udg_BountyPlayer,state,udg_Bounty)
        state=nil
        
        if not udg_BountyColor then
            if udg_BountyPlayerState=="gold" then
                udg_BountyColor=DEF_COLOR_GOLD
            elseif udg_BountyPlayerState=="lumber" then
                udg_BountyColor=DEF_COLOR_LUMBER
            end
        end
        
        if udg_BountyLocPos then
            udg_BountyPosX=GetLocationX(udg_BountyLocPos)
            udg_BountyPosY=GetLocationY(udg_BountyLocPos)
        elseif udg_BountyUnitPos then
            udg_BountyPosX=GetUnitX(udg_BountyUnitPos)
            udg_BountyPosY=GetUnitY(udg_BountyUnitPos)
        else
            udg_BountyShow=false
            udg_BountyShowEffect=false --If there is no position to the text, the text and the effect won't show
        end
        
        udg_BountyTextTag=CreateTextTag()
        SetTextTagPermanent(udg_BountyTextTag,udg_BountyPermanent)
        SetTextTagText(udg_BountyTextTag,"|cff"+udg_BountyColor+Sign(udg_Bounty)+I2S(udg_Bounty)+"|r",TextTagSize2Height(udg_BountySize))
        SetTextTagVisibility(udg_BountyTextTag,IsPlayerInForce(LocalPlayer,udg_BountyWhoSee) and udg_BountyShow)
        SetTextTagPos(udg_BountyTextTag,udg_BountyPosX,udg_BountyPosY,udg_BountyHeight)
        SetTextTagFadepoint(udg_BountyTextTag,udg_BountyFadePoint)
        SetTextTagLifespan(udg_BountyTextTag,udg_BountyLifeSpan)
        SetTextTagVelocityBJ(udg_BountyTextTag,udg_BountySpeed,udg_BountyDirection)
        
        if udg_BountyShowEffect then
            DestroyEffect(AddSpecialEffect(udg_BountyEffect,udg_BountyPosX,udg_BountyPosY))
        end
        
        udg_BountyEvent=0.00
        udg_BountyEvent=1.00
        udg_BountyEvent=0.00
        
        tt=udg_BountyTextTag
        
        Clear()
        
        return tt
    end
    
    --Function to short the Lua process
    function BountyCall(bounty,pos,myplayer,addplayer,permanent)
        udg_Bounty=bounty
        udg_BountyUnitPos=pos
        udg_BountyPlayer=myplayer
        if addplayer then ForceAddPlayer(udg_BountyWhoSee,udg_BountyPlayer) end
        udg_BountyPermanent=permanent
        return BountyText()
    end

    local oldInit = InitBlizzard
    function InitBlizzard()
        oldInit()
        
        --The trigger that runs when a unit dies
        udg_Bounty_Controller=CreateTrigger()
        TriggerRegisterAnyUnitEventBJ(udg_Bounty_Controller,EVENT_PLAYER_UNIT_DEATH)
        TriggerAddCondition(udg_Bounty_Controller,Condition(function()
            udg_BountyKillingUnit=GetKillingUnit()
            if not udg_BountyKillingUnit then --If there is not killing unit then the process stop
                return false
            end
            
            udg_BountyDyingUnit=GetDyingUnit()
            udg_Bounty=GetBountyFromUnitType(GetUnitTypeId(udg_BountyDyingUnit))
            if not udg_Bounty then udg_Bounty=0 end
            
            udg_BountyPlayer=GetOwningPlayer(udg_BountyKillingUnit)
            ForceAddPlayer(udg_BountyWhoSee,udg_BountyPlayer)
            udg_BountyUnitPos=udg_BountyDyingUnit
            
            udg_BountyDeadEvent=0.00
            udg_BountyDeadEvent=1.00
            udg_BountyDeadEvent=0.00
            
            if IsUnitEnemy(udg_BountyDyingUnit,udg_BountyPlayer) or udg_BountyAllowFriendFire then BountyText() end
            
            return false
        end))
        --(For GUI users) The trigger that shows the text
        udg_BountyText=CreateTrigger()
        TriggerAddAction(udg_BountyText,BountyText)
        --(For GUI users) The triggers that set the default bounty of a unit
        udg_BountySet=CreateTrigger()
        TriggerAddAction(udg_BountySet,function()
            BOUNTY(udg_BountyUnitID,udg_BountyBase,udg_BountyDice,udg_BountySides)
            udg_BountyUnitID,udg_BountyBase,udg_BountyDice,udg_BountySides=0,0,0,0
        end)
        udg_BountySetBase=CreateTrigger()
        TriggerAddAction(udg_BountySetBase,function()
            SetBountyBase(udg_BountyUnitID,udg_BountyBase)
            udg_BountyUnitID,udg_BountyBase=0,0
        end)
        udg_BountySetDice=CreateTrigger()
        TriggerAddAction(udg_BountySetDice,function()
            SetBountyDice(udg_BountyUnitID,udg_BountyDice)
            udg_BountyUnitID,udg_BountyDice=0,0
        end)
        udg_BountySetSides=CreateTrigger()
        TriggerAddAction(udg_BountySetSides,function()
            SetBountySides(udg_BountyUnitID,udg_BountySides)
            udg_BountyUnitID=0
            udg_BountySides=0
        end)
        --(For GUI users) The triggers that get the bounty values of a unit (that you set before)
        udg_BountyGet=CreateTrigger()
        TriggerAddAction(udg_BountyGet,function()
            udg_Bounty=GetBountyFromUnitType(udg_BountyUnitID)
            udg_BountyUnitID=0
        end)
        udg_BountyGetBase=CreateTrigger()
        TriggerAddAction(udg_BountyGetBase,function()
            udg_BountyBase=GetBountyBase(udg_BountyUnitID)
            udg_BountyUnitID=0
        end)
        udg_BountyGetDice=CreateTrigger()
        TriggerAddAction(udg_BountyGetDice,function()
            udg_BountyDice=GetBountyDice(udg_BountyUnitID)
            udg_BountyUnitID=0
        end)
        udg_BountyGetSides=CreateTrigger()
        TriggerAddAction(udg_BountyGetSides,function()
            udg_BountySides=GetBountySides(udg_BountyUnitID)
            udg_BountyUnitID=0
        end)
        --Last details
        TimerStart(CreateTimer(),0.00,false,function()
            LocalPlayer=GetLocalPlayer()
            SetData()
            udg_BountyEvent=0.00
            udg_BountyEvent=2.00
            udg_BountyEvent=0.00
        end)
    end
    
    local oldGlobals=InitGlobals
    function InitGlobals()
        oldGlobals()
        Clear()
    end
end
 
Level 24
Joined
Jun 26, 2020
Messages
1,853
I imagine it's another simple syntax mistake. Does this work?
Lua:
Bounties[0],Bounties[1],Bounties[2]={},{},{}
Never tried that before.
The texttags displays normally so I think yes, that is some of the first things I learned from lua, basically:
Lua:
var1,var2=a,b
--Is pratically equal to
var1=a
var2=b
--But if you do
x,y=3,x
--Is not equal to
x=3
y=x i.e y=3
--Because those not happen secuencially, I mean x is not set yet
Back to the first point, what do you mean with another syntax mistake?
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,641
Misspelled word, incorrect symbol (+ instead of ..), etc...

Oh and do you mean this doesn't work?
Lua:
udg_BountyEvent=0.00
udg_BountyEvent=2.00
udg_BountyEvent=0.00
I vaguely remember having issues with this in the past. Unfortunately, I don't remember if I managed to get it working or not.

I wonder if it's an issue with Lua.
 
Status
Not open for further replies.
Top