Mod Question Repository... Questions come in, answers go out - Page 45

Mod Question Repository... Questions come in, answers go out

Resources to get you going on your new project, or to help you over some emergent problems during your development cycle.

Moderator: Moderators

Locked
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Mod Question Repository... Questions come in, answers go out

Post by CarRepairer »

wilbefast wrote:1. Unit can drive up vertical cliffs, no matter what MaxSlope is set to, even 0 (no movement defs have been done yet - could this be why?)
Yes
wilbefast wrote:2. Unit won't turn head in direction it's supposed to be firing
Do you have turret=true in your weapondef? Paste that here as well so we can see.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Mod Question Repository... Questions come in, answers go out

Post by FLOZi »

You can hit me up on the lobby (i'll be in #s44) or on MSN for help.

Sleep's are in milliseconds, as in bos/cob, not frames.
User avatar
wilbefast
Posts: 255
Joined: 14 Oct 2009, 18:04

Re: Mod Question Repository... Questions come in, answers go out

Post by wilbefast »

CarRepairer wrote:
wilbefast wrote:1. Unit can drive up vertical cliffs, no matter what MaxSlope is set to, even 0 (no movement defs have been done yet - could this be why?)
Yes
wilbefast wrote:2. Unit won't turn head in direction it's supposed to be firing
Do you have turret=true in your weapondef? Paste that here as well so we can see.
Sweet! The turret turns now, just won't fire all of a sudden :?

Here's the unit definition:

http://pastebin.com/m10557ead
FLOZi wrote:You can hit me up on the lobby (i'll be in #s44) or on MSN for help.

Sleep's are in milliseconds, as in bos/cob, not frames.
Cool, I'll head on over :-)

edit: I think I missed the boat as far as FLOZi is concerned :(
I've made a move definition - the tank now goes up and down ramps correctly :mrgreen:
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Mod Question Repository... Questions come in, answers go out

Post by FLOZi »

You caught me in the middle of Virgin1's daily Trek marathon :P

My MSN in on my profile if you use it.
User avatar
wilbefast
Posts: 255
Joined: 14 Oct 2009, 18:04

Re: Mod Question Repository... Questions come in, answers go out

Post by wilbefast »

Want to thank FLOZi for all the help :mrgreen:

I've got a whole bunch of things working, like building, repairing reclaiming, rotating turrets to fire and so on. The only things that remain a problem are:
- Nano spray comes from base of model despite NanoPiece being set to "flare" in the same way as the WeaponQuery.
- The StopBuilding() script seems to be being called every time anything is called (Stop, start, attack, etc) :shock: which is annoying because I can't reset the turret if I don't know when the building is finished...

Before I turn in, here's the pastebin script:

http://pastebin.com/m40f23596

And here's the mod files:

http://willhostforfood.com/?Action=down ... leid=93229

Again, thanks for all the help so far :-)


William
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Mod Question Repository... Questions come in, answers go out

Post by Pressure Line »

Code: Select all

function script.QueryNanopiece1 (heading, pitch) return flare end
should possibly read:

Code: Select all

function script.QueryNanopiece (heading, pitch) return flare end
as for the other problem... :/ i dunno
User avatar
wilbefast
Posts: 255
Joined: 14 Oct 2009, 18:04

Re: Mod Question Repository... Questions come in, answers go out

Post by wilbefast »

Pressure Line wrote:

Code: Select all

function script.QueryNanopiece1 (heading, pitch) return flare end
should possibly read:

Code: Select all

function script.QueryNanopiece (heading, pitch) return flare end
as for the other problem... :/ i dunno
I tried changing it - no difference though :cry:

And the StopBuilding script still seems to be being called every 2 seconds :S
Still - I'm moving on to the "actual" units: hopefully these bugs are just Spring objecting to how fugly that tank is...
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Mod Question Repository... Questions come in, answers go out

Post by CarRepairer »

wilbefast wrote:
Pressure Line wrote:

Code: Select all

function script.QueryNanopiece1 (heading, pitch) return flare end
should possibly read:

Code: Select all

function script.QueryNanopiece (heading, pitch) return flare end
as for the other problem... :/ i dunno
I tried changing it - no difference though :cry:

And the StopBuilding script still seems to be being called every 2 seconds :S
Still - I'm moving on to the "actual" units: hopefully these bugs are just Spring objecting to how fugly that tank is...
Wiki was incorrect until yesterday when I pointed it out to maackey. It's QueryNanoPiece (capital P).
User avatar
wilbefast
Posts: 255
Joined: 14 Oct 2009, 18:04

Re: Mod Question Repository... Questions come in, answers go out

Post by wilbefast »

CarRepairer wrote:Wiki was incorrect until yesterday when I pointed it out to maackey. It's QueryNanoPiece (capital P).
Awesome! It works :mrgreen: Thanks Car!

Now I just have to fix up the function script.StopBuilding() part... wonder if there's something that needs to be capitalised or un-capitalised...
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Mod Question Repository... Questions come in, answers go out

Post by CarRepairer »

wilbefast wrote:
CarRepairer wrote:Wiki was incorrect until yesterday when I pointed it out to maackey. It's QueryNanoPiece (capital P).
Awesome! It works :mrgreen: Thanks Car!

Now I just have to fix up the function script.StopBuilding() part... wonder if there's something that needs to be capitalised or un-capitalised...
Yes, the letter o, the second i (not the first i) but change to lowercase s, resulting in stOpBuildIng. Someone needs to fix the wiki :-)
User avatar
wilbefast
Posts: 255
Joined: 14 Oct 2009, 18:04

Re: Mod Question Repository... Questions come in, answers go out

Post by wilbefast »

CarRepairer wrote:the letter o, the second i (not the first i) but change to lowercase s, resulting in stOpBuildIng. Someone needs to fix the wiki :-)
:x
User avatar
PTSnoop
Posts: 97
Joined: 09 Sep 2009, 19:05

Re: Mod Question Repository... Questions come in, answers go out

Post by PTSnoop »

I have a unit with a turret=false weapon. The unit will fire if the target is directly in front, but won't turn to face anything; if told to attack something to its side, it'll just sit there. Is there some unit scripting thing to tell the unit to turn to face targets? (Lua animation examples preferred.)

At the moment, I've got the weapon set up with turret=true and the whole model rotating as a turret. But it needs a couple of kludgy hacks to make both cannons fire, and I'm pretty sure there'll be a better way of doing this...
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Mod Question Repository... Questions come in, answers go out

Post by FLOZi »

PTSnoop wrote:I have a unit with a turret=false weapon. The unit will fire if the target is directly in front, but won't turn to face anything; if told to attack something to its side, it'll just sit there. Is there some unit scripting thing to tell the unit to turn to face targets? (Lua animation examples preferred.)

At the moment, I've got the weapon set up with turret=true and the whole model rotating as a turret. But it needs a couple of kludgy hacks to make both cannons fire, and I'm pretty sure there'll be a better way of doing this...
Is the weapon the primary weapon?
Does it have onlytargetcategory or nochasecategory tags?
is the unit on hold position?

There are lots of things that can mess with that behaviour. (Which is much improved in the next proper engine release)
User avatar
PTSnoop
Posts: 97
Joined: 09 Sep 2009, 19:05

Re: Mod Question Repository... Questions come in, answers go out

Post by PTSnoop »

Yes, it's the primary weapon. There's no onlyTargetCategory; there is a noChaseCategory, but commenting it out doesn't solve the problem. And no, the unit isn't on Hold Position.

Here's the unit files, if they help.

Unitdefs:

Code: Select all

local unitName = "gcflycannon"
local unitDef = 
{
-- Internal settings
	BuildPic = "gcflycannon.bmp",
	Category = "GC UNIT NOTAIR ALL",
	Name = "GC Mosquito",
	ObjectName = "gcflycannon.s3o",
	Side = "GC",
	TEDClass = "TANK",
	UnitName = "gcflycannon",
	script = "gcflycannon.lua",
	
-- Unit limitations and properties
	ActivateWhenBuilt = 1,
	BuildTime = 2500,
	Description = "Medium Attack Unit",
	MaxDamage = 200,
	RadarDistance = 0,
	SightDistance = 300,
	SoundCategory = "GC_FLY",
	Upright = 1,
	
-- Energy and metal related
	BuildCostEnergy = 250,
	BuildCostMetal = 250,
	
-- Pathfinding and related
	Acceleration = 0.2,
	BrakeRate = 0.05,
	movementclass = "Hover2x2",
	canhover = 1,
	FootprintX = 2,
	FootprintZ = 2,
	MaxSlope = 50,
	MaxVelocity = 5.0,
	MaxWaterDepth = 12,
	TurnRate = 1000,
	turret = false,
	
-- Abilities
	Builder = 0,
	Reclaimable = 0,
	CanAttack = 1,
	CanGuard = 1,
	CanMove = 1,
	CanPatrol = 1,
	LeaveTracks = 0,
	
-- Abilities new to Spring
	
-- Weapons and related
	weapons = 
		{
				--"aim",
				"gcredpulse",
				"gcredpulse",
		},
	ExplodeAs = "GCFLYDEATH",
	SelfDestructAs = "GCFLYDEATH",
	SelfDestructCountdown = 5,
	NoChaseCategory = "VTOL",
	sfxtypes = 
	{
		explosiongenerators = 
		{
		      "custom:GCREDPULSE_FLARE",
		},
	},
}

unitDef.weaponDefs = weaponDefs

return lowerkeys({ [unitName] = unitDef })
Weapondef:

Code: Select all

local weaponDef = 
{
	gcredpulse = 
	{
      name                    = [[gcredpulse]],
      accuracy                = 10,
      alphaDecay              = 0.7,
      areaOfEffect            = 275,
      burnblow                = true,
      craterBoost             = 0,
      craterMult              = 0,
      cylindertargetting      = 0,
      edgeEffectiveness       = 0.4,
      explosionGenerator      = [[custom:GCREDPULSE_FX]],
      firestarter             = 70,
      impulseBoost            = 0,
      impulseFactor           = 0,
      intensity               = 0.7,
      interceptedByShieldType = 1,
      lineOfSight             = true,
      noSelfDamage            = true,
      range                   = 200,
      reloadtime              = 1,
      renderType              = 4,
      rgbColor                = [[1 0.4 0.4]],
      size		      = 3.5,
      separation              = 1.5,
      stages                  = 10,
      targetMoveError         = 0.001,
      texture1                = "fireball",
      turret                  = false,
      weaponType              = [[Cannon]],
      weaponVelocity          = 300,
		damage =
			{
			default = 175,
			SCOUTARMOUR = 5,
			VTOLARMOUR = 7,
			},
	}
}

return weaponDef
Unit animation, with kludgy turret=true hacks commented out:

Code: Select all

include "smokeunit.lua"

local body = piece "body"
local bodyfalse = piece "bodyfalse"
local rgun = piece "rgun"
local rflare = piece "rflare"
local lgun = piece "lgun"
local lflare = piece "lflare"

local smokePieces = { piece "body" }

local SIG_AIM1 = 1
local SIG_AIM2 = 2
local RESTORE_DELAY = Spring.UnitScript.GetLongestReloadTime(unitID) * 0.5

local function RestoreAfterDelay()
	Sleep(RESTORE_DELAY)
	Turn(body, y_axis, 0, math.rad(190))
end

local function RestoreAfterFalse()
	Sleep(RESTORE_DELAY)
	Turn(bodyfalse, y_axis, 0, math.rad(190))
end

function script.Create()
	StartThread(SmokeUnit, smokePieces)
end

function script.AimWeapon1(heading, pitch)
	Signal(SIG_AIM1)
	SetSignalMask(SIG_AIM1)
--	Turn(body, y_axis, heading, math.rad(90))
--	WaitForTurn(body, y_axis)
--	EmitSfx(1024, lflare)
--	StartThread(RestoreAfterDelay)
	return true
end

function script.AimWeapon2(heading, pitch)
	Signal(SIG_AIM2)
	SetSignalMask(SIG_AIM2)
--	Turn(bodyfalse, y_axis, heading, math.rad(90))
--	WaitForTurn(bodyfalse, y_axis)
--	EmitSfx(1024, rflare)
--	StartThread(RestoreAfterFalse)
	return true
end

function script.AimFromWeapon1() return lgun end
function script.AimFromWeapon2() return rgun end

function script.QueryWeapon1() return lflare end
function script.QueryWeapon2() return rflare end

function script.Killed(recentDamage, maxHealth)
	return 0
end
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Mod Question Repository... Questions come in, answers go out

Post by yuritch »

Try the same with turret=true and weaponmaindir + maxangledif set. Then it might start turning (I suspect the code that makes restricted-acr units turn to target expects a turreted weapon).
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Mod Question Repository... Questions come in, answers go out

Post by Pressure Line »

correct. turret=false weapons are for planes. iirc they pretty much do not work for anything else.
User avatar
wilbefast
Posts: 255
Joined: 14 Oct 2009, 18:04

Re: Mod Question Repository... Questions come in, answers go out

Post by wilbefast »

I fixed the "unit acting retarted instead of attacking" problem - one line of code:

Code: Select all

category = "land",
I'd assumed that I'd have to define what "land" was, but apparently it's defined by default. Indeed, it's define by default and obligatory for all unit which you want to behave sensibly. There also:

Code: Select all

corpse = "dead",
Not sure what either of these do to be honest (can anyone enlighten me?). As usual I figured this out by looking at maackey's code, or rather trying to get maackey's code to run in my mod. Or rather trying to get my units to run in maackey's mod. Or rather all of the above :wink:

I'm really pleased that it works now :mrgreen:
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Mod Question Repository... Questions come in, answers go out

Post by yuritch »

Code: Select all

corpse = "dead",
This defines what feature your unit turns into when it's killed (it also depends on corpsetype value from Killed() in script).

Units don't have to have this, they won't leave corpses then (like aircraft in most mods for ex.)
User avatar
wilbefast
Posts: 255
Joined: 14 Oct 2009, 18:04

Re: Mod Question Repository... Questions come in, answers go out

Post by wilbefast »

Ah, well in that case I want corpse = "dead"...

Hang on, so the variable "corpse" can be multiple different things aside from undefined and "dead"? What are they or where are such things defined? I'm assuming it's not just a corpse on/off switch because otherwise it'd be corpse = true and not corpse = "dead"...

What really confuses is this Build stance script being called ever 2 seconds for no apparent reason. More troubling is that Flozi has the same problem: I add an echo to his script and guess what? Yep, script.StopBuilding() is called whenever you issue ANY order to the unit. You don't notice of course because all it does in meridian is SetUnitValue(COB.INBUILDSTANCE, FALSE), but what about when you start trying to add a StartThread(RestoreAfterDelay)? Problems galore.

My solution is the following piece of code - it doesn't work unfortunately, and I'm not entirely sure why :|

Code: Select all

function script.StopBuilding()
	if (GetUnitValue(COB.INBUILDSTANCE)) then
		SetUnitValue(COB.INBUILDSTANCE, FALSE)
		Spring.Echo("function script.StopBuilding() was called")
		StartThread(RestoreAfterDelay)
	end
	
end
At least is that all syntactically correct? Still an amateur when it comes to lua...
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Mod Question Repository... Questions come in, answers go out

Post by CarRepairer »

I have unit A loaded on transport B that is firingplatform. I have unit C which can target unit A but not B. It seems that C will still go for A who is on the transport, but he can't reach it for various reasons such as weapon range. How to prevent C from going for A when A is loaded into B?
Locked

Return to “Game Development Tutorials & Resources”