Existance of gadget that makes temporary units

Existance of gadget that makes temporary units

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
SanadaUjiosan
Conflict Terra Developer
Posts: 907
Joined: 21 Jan 2010, 06:21

Existance of gadget that makes temporary units

Post by SanadaUjiosan »

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.
User avatar
MidKnight
Posts: 2652
Joined: 10 Sep 2008, 03:11

Re: Existance of gadget that makes temporary units

Post by MidKnight »

What if I make it really easy for you? :P

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. :(
User avatar
SanadaUjiosan
Conflict Terra Developer
Posts: 907
Joined: 21 Jan 2010, 06:21

Re: Existance of gadget that makes temporary units

Post by SanadaUjiosan »

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.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Existance of gadget that makes temporary units

Post by KDR_11k »

Also in the unit script you can just add sleep 30000; get KILL_UNIT();.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Existance of gadget that makes temporary units

Post by Google_Frog »

It is a really easy gadget but since you said you do not want to do any programming at all...

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
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.
User avatar
SanadaUjiosan
Conflict Terra Developer
Posts: 907
Joined: 21 Jan 2010, 06:21

Re: Existance of gadget that makes temporary units

Post by SanadaUjiosan »

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:

Code: Select all

	function script.Create()
		Sleep(300)
		get KILL_UNIT()
	end
Very dumb, but it's all I could think of at the moment. (the sleep is low for testing reasons)
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Existance of gadget that makes temporary units

Post by FLOZi »

You are mixing COB and LUS.

Code: Select all

Spring.UnitScript.GetUnitValue(COB.KILL_UNIT)
But if you are using LUS you should just use the standard API anyway:

Code: Select all

Spring.DestroyUnit(unitID, selfD, reclaimed)
As explained by MidKnight.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Existance of gadget that makes temporary units

Post by CarRepairer »

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:

Code: Select all

	function script.Create()
		Sleep(300)
		get KILL_UNIT()
	end
Very dumb, but it's all I could think of at the moment. (the sleep is low for testing reasons)
KDR is an old dinosaur who uses extinct languages like BOS/COB.

Code: Select all

function script.Create()
  Sleep(30000)
  Spring.DestroyUnit(unitID)
end
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Existance of gadget that makes temporary units

Post by FLOZi »

Why the change in Sleep? Both bos/cob and lus use milliseconds.
User avatar
SanadaUjiosan
Conflict Terra Developer
Posts: 907
Joined: 21 Jan 2010, 06:21

Re: Existance of gadget that makes temporary units

Post by SanadaUjiosan »

Success!

I happily thank you guys. Lines in the credits.txt to CT for everyone!
Post Reply

Return to “Game Development”