Name | Type | is_array | initial_value |
AbilityCode | abilcode | No | |
UnitType | unitcode | No |
library SimError initializer init
//**************************************************************************************************
//*
//* SimError
//*
//* Mimic an interface error message
//* call SimError(ForPlayer, msg)
//* ForPlayer : The player to show the error
//* msg : The error
//*
//* To implement this function, copy this trigger and paste it in your map.
//* Unless of course you are actually reading the library from wc3c's scripts section, then just
//* paste the contents into some custom text trigger in your map.
//*
//**************************************************************************************************
//==================================================================================================
globals
private sound error
endglobals
//====================================================================================================
function SimError takes player ForPlayer, string msg returns nothing
set msg="\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00"+msg+"|r"
if (GetLocalPlayer() == ForPlayer) then
call ClearTextMessages()
call DisplayTimedTextToPlayer( ForPlayer, 0.52, 0.96, 2.00, msg )
call StartSound( error )
endif
endfunction
private function init takes nothing returns nothing
set error=CreateSoundFromLabel("InterfaceError",false,false,false,10,10)
//call StartSound( error ) //apparently the bug in which you play a sound for the first time
//and it doesn't work is not there anymore in patch 1.22
endfunction
endlibrary
library TinyBuildingsLimits initializer Init requires SimError
globals
private trigger constructionTrigger = CreateTrigger()
private hashtable h = InitHashtable()
endglobals
function AddTinyBuildingItem takes integer abilityId, integer buildingTypeId returns nothing
call SaveInteger(h, abilityId, 0, buildingTypeId)
endfunction
function CheckTinyBuildingForPlayer takes unit caster, integer unitTypeId returns boolean
local player owner = GetOwningPlayer(caster)
local integer max = GetPlayerTechMaxAllowed(owner, unitTypeId)
local integer count = 0
if (max >= 0) then
set bj_wantDestroyGroup = true
set count = CountLivingPlayerUnitsOfTypeId(unitTypeId, owner)
if (count >= max) then
call IssueImmediateOrder(caster, "stop")
call SimError(owner, "Reached limit of " + I2S(max) + " for building " + GetObjectName(unitTypeId))
set owner = null
return false
endif
endif
set owner = null
return true
endfunction
private function TriggerConditionConstruct takes nothing returns boolean
local integer buildingTypeId = LoadInteger(h, GetSpellAbilityId(), 0)
if (buildingTypeId != 0) then
call CheckTinyBuildingForPlayer(GetTriggerUnit(), buildingTypeId)
endif
return false
endfunction
private function Init takes nothing returns nothing
set constructionTrigger = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(constructionTrigger, EVENT_PLAYER_UNIT_SPELL_CHANNEL)
call TriggerAddCondition(constructionTrigger, Condition(function TriggerConditionConstruct))
endfunction
endlibrary
library Helpers requires TinyBuildingsLimits
function AddMapTinyBuildingItem takes nothing returns nothing
call AddTinyBuildingItem(udg_AbilityCode, udg_UnitType)
endfunction
endlibrary