Name | Type | is_array | initial_value |
//TESH.scrollpos=0
//TESH.alwaysfold=0
/**************************************************************
*
* RegisterPlayerUnitEvent
* v4.2.0.0
* By Magtheridon96
*
* I would like to give a special thanks to Bribe, azlier
* and BBQ for improving this library. For modularity, it only
* supports player unit events.
*
* Functions passed to RegisterPlayerUnitEvent must
* return false. They can return nothing as well.
*
* Disclaimer:
* -----------
*
* - Don't use TriggerSleepAction inside registered code.
*
* API:
* ----
*
* function RegisterPlayerUnitEvent
* takes
* playerunitevent whichEvent : The event you would like to register
* code whichFunction : The code you would like to register
* returns
* nothing
*
* - Registers code that will execute when an event fires.
*
**************************************************************/
library RegisterPlayerUnitEvent // Special Thanks to Bribe and azlier
globals
private trigger array t
endglobals
function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
local integer i = GetHandleId(p)
local integer k = 15
if t[i] == null then
set t[i] = CreateTrigger()
loop
call TriggerRegisterPlayerUnitEvent(t[i], Player(k), p, null)
exitwhen k == 0
set k = k - 1
endloop
endif
call TriggerAddCondition(t[i], Filter(c))
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library SimError initializer init
//**************************************************************************************************
//*
//* SimError by Vexorian
//*
//* 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
//TESH.scrollpos=97
//TESH.alwaysfold=0
/*
=====Transformations v1.2
=====Created by Mckill2009
HOW TO INSTALL:
- Make a new trigger and convert to custom text via EDIT >>> CONVERT CUSTOM TEXT
- Copy ALL that is written here (overwrite the existing texts in the trigger)
- Copy all the required lilbraries to your map
HOW TO USE:
- Normal and Alternate Units must have the custom Bear Ability (see object editor for sample)
- Normal and Alternate Units must have an inventory or a hero
- You must register the units and items and first before using (see below)
- If you dont follow these HOW TO USE, it wont work
WARNING:
- It is strongly recommended that the number of items being registered EQUALS to the level of the ability
- It means, if the ability is only level 5, the items for a particular hero should be 5 pcs as well
API:
static method RegisterUnit takes unit hero, integer abilityid returns nothing
- Registers the unit, unregistered unit cannot take the item that is registered
- Saving the bear ability of the hero
- Removes the saved bear ability but will be added again when hero acquires a registered specified item for him
- This is the FIRST thing you will call
static method RegisterItem takes unit hero, integer itemid returns nothing
- Registers the item that a particular hero is using
- Sets the AbilityLevel and the COUNTER for the items registered for a particular hero
- This is the SECOND thing you will call
CREDITS and REQUIREMENTS:
- RegisterPlayerUnitEvent by Magtheridon96
- SimError by Vexorian
*/
library Transformation uses SimError, RegisterPlayerUnitEvent
globals
//===NON-CONFIGURABLES:
private constant hashtable HT = InitHashtable()
private constant integer CHILD_UNIT_ID = 10000
private constant integer CHILD_ABIL_ITEM_ID = 20000
private integer AbilityLevel = 0 //Sets the level of ability per item acquired
//===============================================================
//=====CONFIGURABLES:
private constant string DOUBLED_ITEM = "you can't have 2 items of the same type!"
private constant string UNIT_NOT_REGISTERED = "this unit is not registered!"
endglobals
//! textmacro REG2 takes FUNC, B, C
private function Is$FUNC$ takes unit u, item itm returns boolean
local integer i = 0
local integer unitID = GetHandleId(u)
local integer itemcount = LoadInteger(HT, unitID, CHILD_ABIL_ITEM_ID)
loop
if GetItemTypeId(itm)==LoadInteger(HT, unitID, i) and $C$ then
$B$
return true
endif
set i = i + 1
exitwhen i > itemcount
endloop
return false
endfunction
//! endtextmacro
//! runtextmacro REG2("UnitRegistered","set AbilityLevel = i+1","not HaveSavedHandle(HT, unitID, CHILD_UNIT_ID+2)")
//! runtextmacro REG2("ItemDoubled","//","HaveSavedHandle(HT, unitID, CHILD_UNIT_ID+2)")
struct TR extends array
private static method getItem takes nothing returns nothing
local unit u = GetTriggerUnit()
local item itm = GetManipulatedItem()
local integer uID
local integer abilityID
local real x = GetUnitX(u)
local real y = GetUnitY(u)
if HaveSavedHandle(HT,GetHandleId(u),0x9876) then
if IsUnitRegistered(u, itm) then
set uID = GetHandleId(u)
set abilityID = LoadInteger(HT, uID, CHILD_UNIT_ID)
call UnitAddAbility(u, abilityID)
call SetUnitAbilityLevel(u, abilityID, AbilityLevel)
call SaveItemHandle(HT, uID, CHILD_UNIT_ID+2, itm)
elseif IsItemDoubled(u, itm) then
call UnitDropItemPoint(u, itm, x, y)
call SimError(GetTriggerPlayer(), DOUBLED_ITEM)
endif
elseif HaveSavedInteger(HT,GetItemTypeId(itm),0) then
call UnitDropItemPoint(u, itm, x, y)
call SimError(GetTriggerPlayer(), UNIT_NOT_REGISTERED)
endif
set itm = null
set u = null
endmethod
private static method dropItem takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer it
local integer uID
if GetManipulatedItem()==LoadItemHandle(HT, GetHandleId(u), CHILD_UNIT_ID+2) then
call RemoveSavedHandle(HT, GetHandleId(u), CHILD_UNIT_ID+2)
call UnitRemoveAbility(u, LoadInteger(HT, GetHandleId(u), CHILD_UNIT_ID))
endif
set u = null
endmethod
private static method unitDies takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer unitID
if IsUnitType(u, UNIT_TYPE_HERO) then
set unitID = GetHandleId(u)
if HaveSavedInteger(HT, unitID, CHILD_UNIT_ID) then //ability that is saved
call RemoveSavedInteger(HT, unitID, CHILD_UNIT_ID+3)
call SetItemDroppable(LoadItemHandle(HT, unitID, CHILD_UNIT_ID+2), true)
endif
endif
set u = null
endmethod
private static method castOk takes unit u returns nothing
local integer unitID = GetHandleId(u)
local item itm
if UnitHasItem(u, LoadItemHandle(HT, unitID, CHILD_UNIT_ID+2)) then
set itm = LoadItemHandle(HT, unitID, CHILD_UNIT_ID+2)
if HaveSavedInteger(HT, unitID, CHILD_UNIT_ID+3) then
call RemoveSavedInteger(HT, unitID, CHILD_UNIT_ID+3)
call SetItemDroppable(itm, true)
else
call SaveInteger(HT, unitID, CHILD_UNIT_ID+3, 0)
call SetItemDroppable(itm, false)
endif
endif
set itm = null
endmethod
private static method castAbility takes nothing returns nothing
if GetSpellAbilityId()==LoadInteger(HT, GetHandleId(GetTriggerUnit()), CHILD_UNIT_ID) then
call thistype.castOk(GetTriggerUnit())
endif
endmethod
private static method onInit takes nothing returns nothing
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_PICKUP_ITEM, function thistype.getItem)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DROP_ITEM, function thistype.dropItem)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_EFFECT, function thistype.castAbility)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function thistype.unitDies)
endmethod
//=====SYSTEM API: You must follow this step by step
//SECOND thing to do >>> call TR.RegisterItem(YOUR HERO, ITEM RAW CODE)
//This registers ALL items that are used in the map
static method RegisterItem takes unit hero, integer itemid returns nothing
local integer unitID = GetHandleId(hero)
//childID starts with 0
call SaveInteger(HT, unitID, LoadInteger(HT, unitID, CHILD_ABIL_ITEM_ID), itemid)
//level of the bear ability, childID starts 20000
call SaveInteger(HT, unitID, CHILD_ABIL_ITEM_ID, LoadInteger(HT, unitID, CHILD_ABIL_ITEM_ID)+1)
//saves all items
call SaveInteger(HT,itemid,0,0)
endmethod
//FIRST thing to do >>> call TR.RegisterUnit(YOUR HERO, ABILITY RAW CODE)
//This registers your hero and removes the Transformation(Bear Ability)
//You MUST call this only once
static method RegisterUnit takes unit hero, integer abilityid returns nothing
local integer unitID = GetHandleId(hero)
if not HaveSavedHandle(HT, unitID, 0x9876) then
//this is the checking if the hero is registered or not
call SaveUnitHandle(HT, unitID, 0x9876, hero)
//saving the ability, loading it when hero acquires a registered item
call SaveInteger(HT, unitID, CHILD_UNIT_ID, abilityid)
call UnitRemoveAbility(hero, abilityid)
else
debug call BJDebugMsg("ERROR: "+GetUnitName(hero)+" has been registered already!")
endif
endmethod
endstruct
endlibrary