- Joined
- Dec 31, 2007
- Messages
- 780
Hello guys, I've been a GUI coder since 2008 and i decided to learn JASS vJASS and Zinc altogether. So here i made a spell in Zinc and i would like if you could give me some tips to make mi code better and more understandable to normal human eyes.
What does the spell do?
Well, what it does is simple. It consists of an item that upgrades itself by the units you kill. If you kill 3 units it changes to first upgrade, if you kill 6 then it changes to second upgrade and finally if you kill 9 units, it will change to the last upgrade which is an item that has an special ability (which does something and then returns everything to 0, the counter and the item)
Here is the code
What does the spell do?
Well, what it does is simple. It consists of an item that upgrades itself by the units you kill. If you kill 3 units it changes to first upgrade, if you kill 6 then it changes to second upgrade and finally if you kill 9 units, it will change to the last upgrade which is an item that has an special ability (which does something and then returns everything to 0, the counter and the item)
Here is the code
JASS:
//! zinc
library LifeBottleKillsUnit{
integer x[];
integer y[9];
integer maxItems;
integer charges[];
function conditions() -> boolean{
unit u = GetKillingUnit();
return ((IsUnitType(u, UNIT_TYPE_HERO) == true ) && (IsUnitType(GetDyingUnit(), UNIT_TYPE_STRUCTURE) == false) && ((GetInventoryIndexOfItemTypeBJ(u, x[0]) > 0) || (GetInventoryIndexOfItemTypeBJ(u, x[1]) > 0) || (GetInventoryIndexOfItemTypeBJ(u, x[2]) > 0)));
}
function changeItem(unit u, integer playerId){
integer i;
for(0 <= i <= maxItems-2){
if (GetInventoryIndexOfItemTypeBJ(u, x[i]) > 0){
RemoveItem( UnitItemInSlot(u, x[i]));
UnitAddItemById( u, x[i+1]);
break;
}
}
if(i==maxItems-2){y[playerId] = 0;}
}
function addChargesToItem(){
unit u = GetKillingUnit();
integer i = GetPlayerId(GetOwningPlayer(u));
y[i] = y[i]+1;
if(( y[i] == charges[1]) || (y[i] == charges[2]) || (y[i] == charges[3])){
changeItem(u, i);
}
}
function conditionT2() -> boolean{
return (GetItemTypeId(GetManipulatedItem()) == x[maxItems-1]);
}
function resetValues(){
RemoveItem(GetManipulatedItem());
UnitAddItemById( GetTriggerUnit(), x[0]);
}
function onInit()
{
//Unit dies add charge trigger
trigger t = CreateTrigger();
//Unit casts fully-upgraded item's ability trigger
trigger t2 = CreateTrigger();
TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH );
TriggerAddCondition(t, Condition(function conditions));
TriggerAddAction(t, function addChargesToItem);
//Hero uses item, reset everything
TriggerRegisterAnyUnitEventBJ(t2, EVENT_PLAYER_UNIT_USE_ITEM );
TriggerAddCondition(t2, Condition(function conditionT2));
TriggerAddAction(t2, function resetValues);
t = null;
t2 = null;
//initialization
x[0] = 'afac';
x[1] = 'spsh';
x[2] = 'bgst';
x[3] = 'ajen';
charges[1] = 3;
charges[2] = 6;
charges[3] = 9;
maxItems = 4;
//end initialization
}
}
//! endzinc
Last edited: