Skip to content

CNC Generals Zero hour Lua scripting examples

MetaIdea edited this page Jul 13, 2021 · 5 revisions

Loop through all available map objects and print their object types to the console:

for objectindex,object in globals() do if strfind(objectindex, "ObjID") then print(GetObjectName(object)) end end

Spawn a dozer at Player 1 start waypoint and print it's ObjectType and teleport it 10 feed up.

MyUnit = "test1" ExecuteAction("CREATE_NAMED_ON_TEAM_AT_WAYPOINT", MyUnit, "AmericaVehicleDozer", "teamplayer0", "Player_1_Start") print(GetObjectType(MyUnit)) x,y,z = ObjectGetPosition(object) ObjectSetPosition(object,x,y,z+10)

Spawn another extra supply depot next to each existing one on the map

local x,y,z local ObjectList = {} local ObjectType local DuplicateOffset = 85 for objectIndex,object in globals() do if strfind(objectIndex, "ObjID") then ObjectType = GetObjectType(object) if ObjectType == "SupplyDock" or ObjectType == "SupplyPile" or ObjectType == "SupplyWarehouse" then tinsert(ObjectList, {object,ObjectType}) end end end for i=1,getn(ObjectList),1 do x,y,z = ObjectGetPosition(ObjectList[i][1]) ExecuteAction("UNIT_SPAWN_NAMED_LOCATION_ORIENTATION", GetUnitName(), ObjectList[i][2], NeutralTeam, {x+DuplicateOffset,y+DuplicateOffset,GetGroundHeight(x+DuplicateOffset,y+DuplicateOffset)}, ObjectGetRotation(ObjectList[i][1])) end

Clone this wiki locally