Re: Journeywar
Posted: 04 Apr 2012, 12:45
Code: Select all
function CaveInLoop()
while(true) do
Spring.Echo("Terraformloop Active")
while elementsInTable ~= 0 do
Spring.Echo("table not empty")
--get the randomized CaveInPoint
x=math.random(1,elementsInTable)
Spring.Echo(elementsInTable)
if terraFormTable[x][1]~= nil then
xCaveIn=terraFormTable[x][1]
Spring.Echo(xCaveIn)
zCaveIn=(terraFormTable[x][2])
Spring.Echo(zCaveIn)
Spring.Echo(yCaveIn)
yCaveIn=(terraFormTable[x][3])-math.random(0,4)
--get Spring to set the Terrain on CaveIn
Spring.Echo(yCaveIn)
Spring.SetHeightMapFunc(function(x,z,y)
Spring.SetHeightMap(x,z,y,1)
end,
xCaveIn,
zCaveIn,
yCaveIn
)
table.remove(terraFormTable,x)
elementsInTable=elementsInTable-1
end
end
sleep=math.random(400,1200)
Sleep(sleep)
end
end
dont understand what you mean..you want to create crater in shapes other than the circular holes spring does?basically a loop which gets in a table precalculated points of the last railgun shot and then carves those into the landscape.
Code: Select all
originaly = Spring.GetGroundOrigHeight (x,z)
Spring.SetHeightMapFunc (Spring.SetHeightMap, x,z, height+originaly)
It works now.. but i screwed it up mathwise.knorke wrote:I found this old pastebin from a unitscript:
http://pastebin.com/B87GBpup
it makes the terrain under a units footprint form a wall inside the unit (so you other units can stand on top or w/e)
Anyway, to change the terrain at (x,z) by height it does:not sure if could be simpler.Code: Select all
originaly = Spring.GetGroundOrigHeight (x,z) Spring.SetHeightMapFunc (Spring.SetHeightMap, x,z, height+originaly)
Code: Select all
x,z,zOfOld=0
for i=15,range,1 do
--calc point
x=i+unitPosX
z=(slope*x)+unitPosZ
--modulu -if != yOfOld
if zOfOld ~= (z-(z%1))then
--getHeight add set point if height > unitPosX
y=Spring.GetGroundHeight(x,z)
if y > unitPosY then
tempTable={}
--add unitPosition
tempTable[1]=x
tempTable[2]=z
tempTable[3]=y
table.insert(terraFormTable,elementsInTable+1,tempTable)
elementsInTable=elementsInTable+1
--yOfOld =y
end
zOfOld=z
end
end
Code: Select all
local ZOMBO = "anything at all"
--config for killer,victim,zombie relation
local zomba = {
--when a scorpion kill a dude, the dude dies so hard he turns into a helicopter and converts to your team:
[UnitDefNames["tpscorpion"].id] = {[UnitDefNames["tpdude"].id] = {unit=UnitDefNames["tphubschrauber"].id, killerTeam=true,}, } ,
--when a tank is destroyed (no matter by what) a dude escapes from it, like the technicans in C&C:
[ZOMBO] = {[UnitDefNames["tptank"].id] = {unit=UnitDefNames["tpdude"].id, killerTeam=false,}, } ,
--jeep turns everything it kills into a new jeep (for its team)
[UnitDefNames["tpjeep"].id] = {unit=UnitDefNames["tpjeep"].id, killerTeam=true,} ,
--headcrab creates new headcrab when killing a dude:
-- [UnitDefNames["headcrab"].id] = {[UnitDefNames["dude"].id] = {unit=UnitDefNames["headcrab"].id, killerTeam=true,}, } ,
}
function gadget:UnitDestroyed(unitID, unitDefID, teamID, attackerID, attackerDefID, attackerTeamID)
local result = nil
if (zomba[attackerDefID]) then
if zomba[attackerDefID][unitDefID] then
result = zomba[attackerDefID][unitDefID]
else
result = zomba[attackerDefID]
end
end
if (result==nil and zomba[ZOMBO]) then
result = zomba[ZOMBO][unitDefID]
end
if (result) then
local x,y,z = Spring.GetUnitPosition (unitID)
if (result.killerTeam) then
teamID = attackerTeamID
end
Spring.CreateUnit (result.unit, x,y,z, 0, teamID)
end
end
Code: Select all
--when this kills something, creates this:
-- v v
--zomba[attacker] = result
--also possible:
--when this kills this creates this
-- v v v
--zomba [attacker][victim] = result
--when something should turn into a new thing, no matter what killed it:
-- anything kills this creates this
-- v v v
--zomba[ZOMBO][victim] = result
killerTeam = true / false
new unit is on killer's team or original team
Code: Select all
function gadget:GetInfo()
return {
name = "OverHeadCrab",
desc = "",
author = "jK - always jk is there anyhting lua, that he didnt do long before you, making you look like a idiot in his fathers shoes. :(.
Haha, this time its mainly copied from knorke : )",
date = "Sep. 2008",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true,
}
end
if (gadgetHandler:IsSyncedCode()) then
gaiaTeamID=Spring.GetGaiaTeamID()
local ZOMBO = "anything at all"
//This part sends them too hell
--config for killer,victim,zombie relation
local zomba = {
--when a scorpion kill a dude, the dude dies so hard he turns into a helicopter and converts to your team:
[UnitDefNames["headcrab"].id] = {[UnitDefNames["bg"].id] = {unit=UnitDefNames["zombie"].id, killerTeam=true,}, } ,
[UnitDefNames["headcrab"].id] = {[UnitDefNames["tiglil"].id] = {unit=UnitDefNames["zombie"].id, killerTeam=true,}, } ,
[UnitDefNames["headcrab"].id] = {[UnitDefNames["css"].id] = {unit=UnitDefNames["zombie"].id, killerTeam=true,}, } ,
[UnitDefNames["headcrab"].id] = {[UnitDefNames["skinfantry"].id] = {unit=UnitDefNames["zombie"].id, killerTeam=true,}, } ,
--when a tank is destroyed (no matter by what) a dude escapes from it, like the technicans in C&C:
[ZOMBO] = {[UnitDefNames["restrictor"].id] = {unit=UnitDefNames["bg"].id, killerTeam=false,}, } ,
[ZOMBO] = {[UnitDefNames["mtw"].id] = {unit=UnitDefNames["bg"].id, killerTeam=false,}, } ,
[ZOMBO] = {[UnitDefNames["ampro"].id] = {unit=UnitDefNames["bg"].id, killerTeam=false,}, } ,
--jeep turns everything it kills into a new jeep (for its team)
--[UnitDefNames["tpjeep"].id] = {unit=UnitDefNames["tpjeep"].id, killerTeam=true,} ,
--headcrab creates new headcrab when killing a dude:
-- [UnitDefNames["headcrab"].id] = {[UnitDefNames["dude"].id] = {unit=UnitDefNames["headcrab"].id, killerTeam=true,}, } ,
}
function gadget:UnitDestroyed(unitID, unitDefID, teamID, attackerID, attackerDefID, attackerTeamID)
local result = nil
if (zomba[attackerDefID]) then
if zomba[attackerDefID][unitDefID] then
result = zomba[attackerDefID][unitDefID]
else
result = zomba[attackerDefID]
end
end
if (result==nil and zomba[ZOMBO]) then
result = zomba[ZOMBO][unitDefID]
end
if (result) then
local x,y,z = Spring.GetUnitPosition (unitID)
if (result.killerTeam) then
teamID = gaiaTeamID
end
Spring.CreateUnit (result.unit, x,y,z, 0, teamID)
end
end
//THis part watches for shell
local headCrabWeapon = {}
for i=1,#WeaponDefs do
local wd = WeaponDefs[i]
if (wd.description:find("HeadCrab-Shell")) then
Script.SetWatchWeapon(wd.id,true)
headCrabWeapon[wd.id] = true
end
end
function gadget:Explosion(weaponID, px, py, pz)
if (headCrabWeapon[weaponID]) then
Spring.CreateUnit("hc",px,py,pz, 0, gaiaTeamID)
end
return false
end
end
can directly get the weapondefID like this:for i=1,#WeaponDefs do
local wd = WeaponDefs
if (wd.description:find("HeadCrab-Shell")) then
Code: Select all
weapondefID = WeaponDefNames["HeadCrab-Shell"].id
Script.SetWatchWeapon(weapondefID , true)
Code: Select all
function gadget:UnitDestroyed(unitID, unitDefID, teamID, attackerID, attackerDefID, attackerTeamID)
if (not finishedUnits[unitID]) then return end
...
finishedUnits[unitID] = nil
end
--checking buildprogess==1 in UnitDestroyed does not work
local finishedUnits = {}
function gadget:UnitFinished(unitID, unitDefID, teamID)
finishedUnits[unitID] = true
end
? So, if a unit would be chanceled, a little guy would leave--> infinite infantry? but why does buildprogress not work- the unit still exists when this is called.knorke wrote:forgott that when when canceling unit contruction in a factory it calls UnitDestroyed. So add something like:Code: Select all
function gadget:UnitDestroyed(unitID, unitDefID, teamID, attackerID, attackerDefID, attackerTeamID) if (not finishedUnits[unitID]) then return end ... finishedUnits[unitID] = nil end --checking buildprogess==1 in UnitDestroyed does not work local finishedUnits = {} function gadget:UnitFinished(unitID, unitDefID, teamID) finishedUnits[unitID] = true end