Existance of gadget that makes temporary units
Moderator: Moderators
- SanadaUjiosan
- Conflict Terra Developer
- Posts: 907
- Joined: 21 Jan 2010, 06:21
Existance of gadget that makes temporary units
Quick question: Is there a gadget out there that will affect how long a unit exists in the game? What I'm wanting is something to make a specific unit (a camera-tower type thing) only last for a specific duration of time (let's say 30 seconds.)
So like a unit would be able to build this camera tower, and the camera tower would sit there, being all camera-y, but when it's 30 seconds was up, it'd detonate and go away.
I'm guessing this is an easy thing to pull off, but I'm wondering if anyone's written a gadget for it.
And no, I am not going to do it. I'm not a programmer. It is either going to have to already exist, or a non-existent nice person write it for me.
So like a unit would be able to build this camera tower, and the camera tower would sit there, being all camera-y, but when it's 30 seconds was up, it'd detonate and go away.
I'm guessing this is an easy thing to pull off, but I'm wondering if anyone's written a gadget for it.
And no, I am not going to do it. I'm not a programmer. It is either going to have to already exist, or a non-existent nice person write it for me.
Re: Existance of gadget that makes temporary units
What if I make it really easy for you?
UnitCreated()
Tells you when a unit is built. gives you:
"unitID, unitDefID, teamID, builderID"
Spring.GetGameFrame()
Will get you the number of sim frames since game start.
GameFrame()
Is called every time there is a new frame. Spring has a fixed rate of 30 sim frames per second (IIRC), so 30 seconds would be 900 frames.
Spring.DestroyUnit(UnitID, selfd, reclaimed)
Destroys the unit with the given UnitID.
selfd can be set to true or false. true makes it explode.
reclaimed can be set to true or false. true makes it just disappear off the face of the map.
I'd write the script for you, but it's 2 AM right now and everything's swirly. Sorry.

UnitCreated()
Tells you when a unit is built. gives you:
"unitID, unitDefID, teamID, builderID"
Spring.GetGameFrame()
Will get you the number of sim frames since game start.
GameFrame()
Is called every time there is a new frame. Spring has a fixed rate of 30 sim frames per second (IIRC), so 30 seconds would be 900 frames.
Spring.DestroyUnit(UnitID, selfd, reclaimed)
Destroys the unit with the given UnitID.
selfd can be set to true or false. true makes it explode.
reclaimed can be set to true or false. true makes it just disappear off the face of the map.
I'd write the script for you, but it's 2 AM right now and everything's swirly. Sorry.

- SanadaUjiosan
- Conflict Terra Developer
- Posts: 907
- Joined: 21 Jan 2010, 06:21
Re: Existance of gadget that makes temporary units
If you'd like to write it when it's not 2am, it would be greatly appreciated. Maybe this super simple script could help me start to even fathom how gadgets work. I do well with examples. It took me like a month or two of staring at a simple animation script to understand how a weapon fires.
Re: Existance of gadget that makes temporary units
Also in the unit script you can just add sleep 30000; get KILL_UNIT();.
-
- Moderator
- Posts: 2464
- Joined: 12 Oct 2007, 09:24
Re: Existance of gadget that makes temporary units
It is a really easy gadget but since you said you do not want to do any programming at all...
This is just typed from scratch in the last 5 minutes. As such I some arguments might be the wrong way around etc... Also there is a use of pairs that could be removed but it should be pretty inconsequential at the frequency and size of table it is used for.
So it depends on how much of a non-programmer you are. Can you slap a gadget:info on top and debug the occasional syntax error?
I like KDR_11K's idea too, it is worth looking into.
Code: Select all
local KILL_OFFSET = 900 -- 30 seconds
local cameraUDID = UnitDefNames["camera"].id
local killTable = {}
local killTableByUnitID = {}
function gadget:UnitCreated(unitID,udid)
if cameraUDID == udid then
local f = Spring.GetGameFrame() + KILL_OFFSET
killTable[f] = killTable[f] or {}
killTable[f][unitID] = true
killTableByUnitID[unitID] = f
end
end
function gadget:GameFrame(f)
if killTable[f] then
for unitID,_ in pairs(killTable[f]) do
if Spring.IsValidUnit(unitID) then
Spring.DestroyUnit(unitID, false, false)
end
killTableByUnitID[unitID] = nil
end
killTable[f] = nil
end
end
function gadget:UnitDestroyed(unitID)
if killTableByUnitID[unitID] then
killTable[killTableByUnitID[unitID]][unitID] = nil
killTableByUnitID[unitID] = nil
end
end
So it depends on how much of a non-programmer you are. Can you slap a gadget:info on top and debug the occasional syntax error?
I like KDR_11K's idea too, it is worth looking into.
- SanadaUjiosan
- Conflict Terra Developer
- Posts: 907
- Joined: 21 Jan 2010, 06:21
Re: Existance of gadget that makes temporary units
I like KDR's idea too, it seems simple and easy.
Could someone give me an example of what that little bit would look like in the script? I don't know what "get KILL_UNIT()" should look like.
This is what I tried:
Very dumb, but it's all I could think of at the moment. (the sleep is low for testing reasons)
Could someone give me an example of what that little bit would look like in the script? I don't know what "get KILL_UNIT()" should look like.
This is what I tried:
Code: Select all
function script.Create()
Sleep(300)
get KILL_UNIT()
end
Re: Existance of gadget that makes temporary units
You are mixing COB and LUS.
But if you are using LUS you should just use the standard API anyway:
As explained by MidKnight.
Code: Select all
Spring.UnitScript.GetUnitValue(COB.KILL_UNIT)
Code: Select all
Spring.DestroyUnit(unitID, selfD, reclaimed)
- CarRepairer
- Cursed Zero-K Developer
- Posts: 3359
- Joined: 07 Nov 2007, 21:48
Re: Existance of gadget that makes temporary units
KDR is an old dinosaur who uses extinct languages like BOS/COB.SanadaUjiosan wrote:I like KDR's idea too, it seems simple and easy.
Could someone give me an example of what that little bit would look like in the script? I don't know what "get KILL_UNIT()" should look like.
This is what I tried:
Very dumb, but it's all I could think of at the moment. (the sleep is low for testing reasons)Code: Select all
function script.Create() Sleep(300) get KILL_UNIT() end
Code: Select all
function script.Create()
Sleep(30000)
Spring.DestroyUnit(unitID)
end
Re: Existance of gadget that makes temporary units
Why the change in Sleep? Both bos/cob and lus use milliseconds.
- SanadaUjiosan
- Conflict Terra Developer
- Posts: 907
- Joined: 21 Jan 2010, 06:21
Re: Existance of gadget that makes temporary units
Success!
I happily thank you guys. Lines in the credits.txt to CT for everyone!
I happily thank you guys. Lines in the credits.txt to CT for everyone!