Lua script request.

Lua script request.

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Lua script request.

Post by smoth »

Could someone write a script that locks the camera in TA camera at a specific zoom and rotation. Also could the camera stay locked on a specific unit?

Thanks in advance.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Lua script request.

Post by aegis »

smoth wrote:could the camera stay locked on a specific unit?
doesn't one of the keyboard shortcuts do that? T?
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Lua script request.

Post by smoth »

it has a specific camera angle etc... not the one I wanted.
User avatar
Blue_Falcon
Posts: 155
Joined: 16 Oct 2008, 18:54

Re: Lua script request.

Post by Blue_Falcon »

You can change the angle using Ctrl+Mousewheel... Is that what you're after?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Lua script request.

Post by zwzsg »

Don't post such an answer, or Smoth will raeg about how useless it is to post requests here again.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Lua script request.

Post by smoth »

Blue_Falcon wrote:You can change the angle using Ctrl+Mousewheel... Is that what you're after?
does that lock the camera to taview? does it set distance/angle? Does it set the camera to follow a unit? No, that is just turning the ta camera.

I would not make this request if I didn't have a good reason.
User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Re: Lua script request.

Post by Tribulex »

smoth wrote:
Blue_Falcon wrote:You can change the angle using Ctrl+Mousewheel... Is that what you're after?
does that lock the camera to taview? does it set distance/angle? Does it set the camera to follow a unit? No, that is just turning the ta camera.

I would not make this request if I didn't have a good reason.
I think i know what this reason is.


I second this request, i want it too actually... you will received baked goods from both smoth AND me.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Lua script request.

Post by zwzsg »

What is the unit you need the follow? How does widget (or gadget?) is given its ID? Will that unit change? Is it for a game where each player only has one unit? What if that unit die? Lock on death place or allow free roaming? The angle and height, hard coded or parametrable? Which way are passed the parameters? I assume some elasticity between the camera and unit movement would be nicer than stuttering?

From having tinkered with xyz's "spectator mode" widget, I know all you need is to periodically issue the commands:

Spring.SetCameraState({name=ta, mode=1, px=UnitX, py=0, pz=UnitZ, flipped=-1, dy=-0.9, zscale=0.5, height=999, dx=0, dz=-0.45}, TRANSITION_DURATION)
Spring.SelectUnitArray({UnitID})
Spring.SendCommands("track") -- "trackoff" is the command to stop it
Spring.SelectUnitArray({})

Or maybe if you're less conscious just:
Spring.SetCameraTarget(UnitX, 0, UnitZ, TRANSITION_DURATION)

So 90% of the code would be interfacing. And only you know what kind of interfacing you want. Because only you know the purpose and environnment of that Lua script.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Lua script request.

Post by KDR_11k »

Should maybe mention that I already gave him one.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Lua script request.

Post by zwzsg »

No, it was him that should have mentionned.



Here's the one I'm using now:

Code: Select all

	function gadget:Update()
		local u=GetTheOne()
		if u then
			-- Focus on the unit
			Spring.SelectUnitArray({},false)
			local x,_,z=Spring.GetUnitPosition(u)
			local _,v,paused=Spring.GetGameSpeed()
			v = paused and 0 or v
			local vx,_,vz=Spring.GetUnitVelocity(u)
			local r=UnitDefs[Spring.GetUnitDefID(u)].maxWeaponRange
			Spring.SetCameraState({name=ta, mode=1, px=x+9*v*vx,py=0, pz=z+9*v*vz, flipped=-1, dy=-0.9, zscale=0.5, height=2*r, dx=0, dz=-0.45},1)
		else
			if not Spring.GetSpectatingState() then
				-- Focus on the start pos
				Spring.SelectUnitArray({},false)
				local x,y,z=Spring.GetTeamStartPosition(Spring.GetLocalTeamID())
				Spring.SetCameraState({name=ta, mode=1, px=x, py=0, pz=z, flipped=-1, dy=-0.9, zscale=0.5, height=1200, dx=0, dz=-0.45},5)
			end
		end
	end
Notice how it compensate the unit speed and scale to weapon range. This does well for the purpose I wrote it for. However:






Is there any way to lock a camera, in the sense of making it obey Spring.SetCameraState and Spring.SetCameraTarget strictly and ignore any user input related to camera?

Because I want to do ingame cinematic intro to my mod, and I don't want my script to have to fight back against mouse pointer idling in the corner or user clicking on minimap.
Post Reply

Return to “Lua Scripts”