- Joined
- Jun 26, 2020
- Messages
- 1,928
I create this system to control almost everything about the bouties and can edit it with external triggers, and use it with another events more than when you kill a unit, is uncompleted and I wanna add more stuff.
And surpringsly it works because for some reason all actions of external triggers happens before this trigger runs the function "Bounty Text" if it had the event of unit death, but my problems are:
vJASS:
library BountyController initializer Init
globals
private hashtable Bounties=InitHashtable()
private unit Dead
private integer Id
private real PosX
private real PosY
private boolean array PlayerNotSee
private boolean Cleared=false
player LocalPlayer
private constant string DEF_COLOR="ffcc00"
private constant integer DEF_SIZE=10
private constant real DEF_LIFE_SPAN=3.50
private constant real DEF_SPEED=64
private constant real DEF_FADE_POINT=2.50
private constant string DEF_STATE="gold"
private constant real DEF_HEIGHT=0
private constant boolean DEF_SHOW=true
private constant boolean DEF_SHOW_NOTHING=false
private constant boolean DEF_ALLOW_FRIEND_FIRE=false
endglobals
function BOUNTY takes integer id, integer base, integer dice, integer side returns nothing
call SaveInteger(Bounties,0,id,base)
call SaveInteger(Bounties,1,id,dice)
call SaveInteger(Bounties,2,id,side)
endfunction
//Here is to determine the normal bounties
//you just have to add: BOUNTY("'ID of the unit'","Bounty: Base","Bounty: Number of dice","Bounty: Sides per dice")
//or you can do it outside the code when you consider it
//there is to write it /**/ BOUNTY("''","","","")
private function SetData takes nothing returns nothing
local integer i
/*Vigilante draeniano (Nivel 1)*/ call BOUNTY('n002',35,6,3)
/*Vigilante draeniano (Nivel 2)*/ call BOUNTY('n005',35,6,3)
/*Vigilante draeniano (Nivel 3)*/ call BOUNTY('n00Q',35,6,3)
/*Draenei Mage (Nivel 2)*/ call BOUNTY('n00B',35,6,3)
/*Draenei Mage (Nivel 3)*/ call BOUNTY('n003',35,6,3)
/*Defense Tower (Draenei)*/ call BOUNTY('o00H',100,5,5)
/*Grunt orco fel (Nivel 1)*/ call BOUNTY('n00D',35,6,3)
/*Grunt orco fel (Nivel 2)*/ call BOUNTY('n00F',35,6,3)
/*Grunt orco fel (Nivel 3)*/ call BOUNTY('n00S',35,6,3)
/*Brujo orco fel (Nivel 2)*/ call BOUNTY('n017',35,6,3)
/*Brujo orco fel (Nivel 3)*/ call BOUNTY('n00R',35,6,3)
/*Defense Tower (Demons)*/ call BOUNTY('o00I',100,5,5)
/*Defense Tower (Dummy)*/ call BOUNTY('u00K',100,5,5)
/*Renegade Draenei*/ call BOUNTY('ndrp',25,1,3)
/*Wild Dragon*/ call BOUNTY('n00O',25,1,3)
set i=0
loop
exitwhen i>PLAYER_NEUTRAL_AGGRESSIVE
call SetPlayerFlagBJ(PLAYER_STATE_GIVES_BOUNTY,false,Player(i))
set i=i+1
endloop
endfunction
private function Clear takes nothing returns nothing
if not Cleared then
set udg_BountyColor=DEF_COLOR
set udg_BountySize=DEF_SIZE
set udg_BountyLifeSpan=DEF_LIFE_SPAN
set udg_BountyFadePoint=DEF_FADE_POINT
set udg_BountySpeed=DEF_SPEED
set udg_BountyPlayerState=DEF_STATE
set udg_BountyHeight=DEF_HEIGHT
set udg_BountyShow=DEF_SHOW
set udg_BountyShowNothing=DEF_SHOW_NOTHING
set udg_BountyAllowFriendFire=DEF_ALLOW_FRIEND_FIRE
set udg_BountyPlayer=null
set udg_BountyUnitPos=null
set udg_BountyLocPos=null
set udg_Bounty=-1
set Dead=null
set Id=0
call ForceClear(udg_BountyWhoSee)
endif
endfunction
function BountyText takes nothing returns nothing
local texttag tt=null
local playerstate state=null
if udg_BountyPlayerState=="gold" then
set state=PLAYER_STATE_RESOURCE_GOLD
elseif udg_BountyPlayerState=="lumber" then
set state=PLAYER_STATE_RESOURCE_LUMBER
else
call Clear()
return //If the state is not valid, the process stop
endif
call AdjustPlayerStateSimpleBJ(udg_BountyPlayer,state,udg_Bounty)
set state=null
if udg_BountyLocPos!=null then
set PosX=GetLocationX(udg_BountyLocPos)
set PosY=GetLocationY(udg_BountyLocPos)
call RemoveLocation(udg_BountyLocPos)
elseif udg_BountyUnitPos!=null then
set PosX=GetUnitX(udg_BountyUnitPos)
set PosY=GetUnitY(udg_BountyUnitPos)
else
call Clear()
return //If there is no position to the text, the text won't show
endif
if udg_BountyShow then //If this is true, it will show the text
set tt=CreateTextTag()
call SetTextTagPermanent(tt,false)
call SetTextTagText(tt,"|cff"+udg_BountyColor+"+"+I2S(udg_Bounty)+"|r",TextTagSize2Height(udg_BountySize))
call SetTextTagVisibility(tt,IsPlayerInForce(LocalPlayer,udg_BountyWhoSee))
call SetTextTagPos(tt,PosX,PosY,udg_BountyHeight)
call SetTextTagFadepoint(tt,udg_BountyFadePoint)
call SetTextTagLifespan(tt,udg_BountyLifeSpan)
call SetTextTagVelocityBJ(tt,udg_BountySpeed,90)
set tt=null
endif
call Clear()
endfunction
private function UnitBounty takes nothing returns boolean
set Dead=GetDyingUnit()
set Id=GetUnitTypeId(Dead)
//Check if the value of bounty didn't get affected
if udg_Bounty==-1 then
set udg_Bounty=IMaxBJ(0,LoadInteger(Bounties,0,Id)+GetRandomInt(0,LoadInteger(Bounties,1,Id)*LoadInteger(Bounties,2,Id)))
elseif udg_Bounty<0 then
set udg_Bounty=IMaxBJ(0,LoadInteger(Bounties,0,Id)+GetRandomInt(0,LoadInteger(Bounties,1,Id)*LoadInteger(Bounties,2,Id)))*udg_Bounty*-1
endif
//Check if the player didn't get affected
if udg_BountyPlayer==null then
set udg_BountyPlayer=GetOwningPlayer(GetKillingUnit())
endif
//Check if the visibility of the owner of killing unit didn't get affected
if not PlayerNotSee[GetPlayerId(udg_BountyPlayer)] then
call ForceAddPlayer(udg_BountyWhoSee,udg_BountyPlayer)
else
set PlayerNotSee[GetPlayerId(udg_BountyPlayer)]=false
endif
//Check if the unit position of the text didn't get affected
if udg_BountyUnitPos==null then
set udg_BountyUnitPos=Dead
endif
if IsUnitEnemy(Dead,udg_BountyPlayer) or udg_BountyAllowFriendFire then //By default, there only can be bounty if the dying unit is enemy of the killing unit
if udg_Bounty!=0 or udg_BountyShowNothing then //By default, if the bounty is 0, so the process don't happen
set Cleared=true
call BountyText()
endif
endif
set Cleared=false
call Clear()
return false
endfunction
function CheckPlayer takes force f, player p returns nothing
if f==udg_BountyWhoSee then
set PlayerNotSee[GetPlayerId(p)]=true
endif
endfunction
function CheckPlayerBJ takes player p, force f returns nothing
call CheckPlayer(f,p)
endfunction
hook ForceRemovePlayer CheckPlayer
hook ForceRemovePlayerSimple CheckPlayerBJ
private function Init takes nothing returns nothing
//The trigger that runs when a unit dies
set udg_BountyDie=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(udg_BountyDie,EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(udg_BountyDie,Condition(function UnitBounty))
//The trigger that shows the text
set udg_BountyText=CreateTrigger()
call TriggerAddAction(udg_BountyText,function BountyText)
set LocalPlayer=GetLocalPlayer()
call SetData()
call Clear()
endfunction
endlibrary
- For some reason the clear function doesn't work fine, it always remains a previous edit in the next instance but in the next of that is cleared.
- Because of all actions of external triggers happens before this trigger runs the function "Bounty Text", the variables to the Bounty and the Player who receive it is not asigned yet, so it will have the default value, and because of that the unique edit the variable "Bounty" can be by multiplications and an especific value and not another that depends of the original Bounty.
- If I wanna allow negative bounties, what should be the default value of "Bounty"?
- If the solution is using custom events, can you teach me how to it works for I wanna do?
Last edited: