- Joined
- Dec 2, 2016
- Messages
- 733
I've got 3 scripts in my game that all run when a unit is created for the first time in game. They cause a small lag spike in the game, any idea what causes this and how I can fix that? Here is the latest that I've made. I recall that I may need to use the Preload function? But if that's so, why do you need to preload a unit when a trigger like this runs?
// Zinc
// Zinc
JASS:
library dropOuts requires libMisc, libSetup, unitClassification, bloodTower {
public boolean unitHas_humanVault[12];
public unit slayer[12];
function OnTimye60() {
integer i;
timer t=GetExpiredTimer();
for (0 <= i < 13) {
if (unitHas_humanVault[i-1] == true) {
RemoveItem( GetItemOfTypeFromUnitBJ(slayer[GetConvertedPlayerId(Player(i))-1],'I011') );
}
}
}
function onStarty() {
timer t=CreateTimer();
TimerStart(t, 15, true, function OnTimye60);
//TimerStart(CreateTimer(), 15, true, function OnTimye60);
t=null;
}
function findSlayer() {
unit u = GetEnumUnit();
// Finding Slayer and Slayeress
if ( GetUnitTypeId(GetEnumUnit()) == 'HS00' || GetUnitTypeId(GetEnumUnit()) == 'HS01') {
CreateItemLoc( 'I011', GetUnitLoc(GetEnumUnit()) );
UnitAddItemSwapped( GetLastCreatedItem(), GetEnumUnit() );
slayer[GetConvertedPlayerId(GetOwningPlayer(u))-1] = GetEnumUnit();
}
}
function onCreation() {
unit u = GetTriggerUnit();
if (GetUnitTypeId(u) == 'h002') {
DisplayTextToForce(GetPlayersAll(), "Creation 1");
if (unitHas_humanVault[GetConvertedPlayerId(GetOwningPlayer(u))-1] == false ) {
unitHas_humanVault[GetConvertedPlayerId(GetOwningPlayer(u))-1] = true;
ForGroupBJ( GetUnitsInRectAll(GetEntireMapRect()), function findSlayer );
}
}
}
private function onInit() {
trigger trg = CreateTrigger();
trigger creation = CreateTrigger();
TriggerRegisterAnyUnitEventBJ( creation, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH );
TimerStart(CreateTimer(), 60, true, function OnTimye60);
TriggerAddAction(creation, function onCreation);
}
}