-
Notifications
You must be signed in to change notification settings - Fork 20
/
examples.lua
39 lines (36 loc) · 1.46 KB
/
examples.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
--[[
Some tips:
Make sure you add your units first somewhere in your code before adding any buildings, or else the units won't be checked for collision:
BuildingHelper:AddUnit(heroEntity)
Put BuildingHelper:BlockGridNavSquares(nMapLength) in your InitGameMode function.
]]
BUILD_TIME=1.0
function getBuildingPoint(keys)
local point = BuildingHelper:AddBuildingToGrid(keys.target_points[1], 2, keys.caster)
if point ~= -1 then
local farm = CreateUnitByName("npc_normal_farm", point, false, nil, nil, keys.caster:GetTeam())
BuildingHelper:AddBuilding(farm)
farm:UpdateHealth(BUILD_TIME,true,.85)
farm:SetHullRadius(64)
farm:SetControllableByPlayer( keys.caster:GetPlayerID(), true )
else
--Fire a game event here and use Actionscript to let the player know he can't place a building at this spot.
end
end
function getHardFarmPoint(keys)
local caster = keys.caster
local point = BuildingHelper:AddBuildingToGrid(keys.target_points[1], 4, caster)
if point == -1 then
-- Refund the cost.
caster:SetGold(caster:GetGold()+HARD_FARM_COST, false)
--Fire a game event here and use Actionscript to let the player know he can't place a building at this spot.
return
else
caster:SetGold(caster:GetGold()-5, false)
local farm = CreateUnitByName("npc_hard_farm", point, false, nil, nil, caster:GetTeam())
BuildingHelper:AddBuilding(farm)
farm:UpdateHealth(BUILD_TIME,true,.8)
farm:SetHullRadius(128)
farm:SetControllableByPlayer( caster:GetPlayerID(), true )
end
end