script dont work

script dont work

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

Moderator: Moderators

Post Reply
User avatar
jpcordovae
Posts: 28
Joined: 30 Apr 2009, 21:11

script dont work

Post by jpcordovae »

I take a script (unit_nuke_antinuke_mark.lua) and add markers for nuke and antinuke units, but I cant find the script ni Zero-K widget list.

I save the file in directory (windows 7 btw):
C:\Users\Juan Pablo\Documents\My Games\Spring\LuaUI\Widgets
As I understand, Zero-K should take the lua script and show it in the list by himself, right ?

May be a mistake in the code can be the reason why the widget can't be loaded in widget list ?

the script is this one:

Code: Select all

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--  file:    unit_nuke_antinuke_mark.lua
--  brief:   adds a mark to each nuke and antinuke units, taken from gui_mobile_anti_marker.lua from Dave Rodgers
--  author:  Juan Pablo Cordova E.
--
--  Copyright (C) 2011.
--  Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function widget:GetInfo()
  return {
    name      = "Nuke Antinuke Marker",
    desc      = "Automatically adds a mark to each enemy nuke and antinuke units",
    author    = "MelKor",
    date      = "Feb 24, 2011",
    license   = "GNU GPL, v2 or later",
    layer     = 0,
    enabled   = false  --  loaded by default?
  }
end

--------------------------------------------------------------------------------

local marked = {}

--------------------------------------------------------------------------------

local spGetMyPlayerID	= Spring.GetMyPlayerID
local spGetPlayerInfo	= Spring.GetPlayerInfo
local spGetMyAllyTeamID	= Spring.GetMyAllyTeamID
local spGetUnitDefID	= Spring.GetUnitDefID
local spGetUnitPosition = Spring.GetUnitPosition
local spGetUnitVelocity = Spring.GetUnitVelocity
local spMarkerAddPoint	= Spring.MarkerAddPoint

----------------------------------------------------------------

function widget:Initialize() 
	widget:Update()
end

function widget:Update()

	local _, _, spec = spGetPlayerInfo(spGetMyPlayerID())

	if (spec == true) then
		spEcho("<NukeAntinukeMarker> Spectator mode. Widget removed.")
		-- widgetHandler:RemoveWidget()
		return false
	end
end

----------------------------------------------------------------

function widget:UnitEnteredLos(uID, allyTeam)

	if (marked[uID]) then return end

	if (allyTeam == spGetMyAllyTeamID()) then return end
	
	local uDefID = spGetUnitDefID(uID)

	-- if (uDefID == nil) then return end -- Shouldn't need as we have LOS
	
	if ((UnitDefs[uDefID].name == 'armscab') or (UnitDefs[uDefID].name == 'cormabm')) then
		local vx, vy, vz = spGetUnitVelocity(uID)
		local x, y, z = spGetUnitPosition(uID)
		if ((vx ~= 0) or (vy ~= 0) or (vz ~= 0)) then
			spMarkerAddPoint(x, y, z, "Mobile Anti (Moving)")
		else
			spMarkerAddPoint(x, y, z, "Mobile Anti (Stationary)")
		end
		marked[uID] = true
	end
	
	if( (UnitDefs[uDefID].name) == 'armamd')
		local x,y,z = spGetUnitPosition(uID)
		spMarkerAddPoint(x, y, z, "armamd")
		marked[uID] = true
	end
	
	if( (UnitDefs[uDefID].name) == 'corfmd')
		local x,y,z = spGetUnitPosition(uID)
		spMarkerAddPoint(x, y, z, "corfmd")
		marked[uID] = true
	end
	
	if( (UnitDefs[uDefID].name) == 'cornukesub')
		local x,y,z = spGetUnitPosition(uID)
		spMarkerAddPoint(x, y, z, "cornukesub")
		marked[uID] = true
	end
	
	if( (UnitDefs[uDefID].name) == 'armcarry')
		local x,y,z = spGetUnitPosition(uID)
		spMarkerAddPoint(x, y, z, "armcarry")
		marked[uID] = true
	end
	
	if( (UnitDefs[uDefID].name) == 'armsilo')
		local x,y,z = spGetUnitPosition(uID)
		spMarkerAddPoint(x, y, z, "armsilo")
		marked[uID] = true
	end
	
	if( (UnitDefs[uDefID].name) == 'corsilo')
		local x,y,z = spGetUnitPosition(uID)
		spMarkerAddPoint(x, y, z, "corsilo")
		marked[uID] = true
	end
	
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: script dont work

Post by knorke »

zero k blocks user widgets by default to avoid conflicts. you need to turn that on again: http://springrts.com/phpbb/viewtopic.php?f=42&t=21922

That widget might now work as good in zero k, it was probally made for xta or ba: The hardcoded names of the nuke launchers, antis etc might be different in zerok ("corsilo" etc)
User avatar
jpcordovae
Posts: 28
Joined: 30 Apr 2009, 21:11

Re: script dont work

Post by jpcordovae »

Thanks you for the post, help me a lot, but I can't find the hardcoded names, I search in spring files, but no results.

MK
User avatar
jpcordovae
Posts: 28
Joined: 30 Apr 2009, 21:11

Re: script dont work

Post by jpcordovae »

I found hardcoded names in few scripts, you can check at http://code.google.com/p/zero-k/source/ ... n957&r=957

Anyway, I cant load any new widget.

Code: Select all

--MARKER LIST ------------------------------------ NEED TO UPDATE CA1F TO ZK WHEN MOD UPDATES.
unitList["BA"] = {} --initialize table
unitList["BA"]["armamd"] = { markerText = "Anti Nuke" }
unitList["BA"]["corfmd"] = { markerText = "Anti Nuke" }
unitList["BA"]["armsilo"] = { markerText = "Nuke" }
unitList["BA"]["corsilo"] = { markerText = "Nuke" }

unitList["CA"] = {} --initialize table
unitList["CA"]["armamd"] =              { markerText = "Anti Nuke" }
unitList["CA"]["corfmd"] =              { markerText = "Anti Nuke" }
unitList["CA"]["armsilo"] =             { markerText = "Nuke" }
unitList["CA"]["corsilo"] =             { markerText = "Nuke" }
unitList["CA"]["nest"] =                { markerText = "Nest" }
unitList["CA"]["thicket"] =             { markerText = "Thicket" }
unitList["CA"]["corint"] =              { markerText = "Intimidator" }
unitList["CA"]["corbhmth"] =    { markerText = "Behemoth" }
unitList["CA"]["armbrtha"] =    { markerText = "Big Bertha" }
unitList["CA"]["kettle"] =              { markerText = "Kettle" }
unitList["CA"]["starlight"] =   { markerText = "Starlight" }
unitList["CA"]["corebeac"] =    { markerText = "Zenith" }
unitList["CA"]["corfus"] =              { markerText = "Graviton Power Gen" }
unitList["CA"]["cafus"] =               { markerText = "Singularity Reactor" }
unitList["CA"]["armfus"] =              { markerText = "Fusion Reactor" }
unitList["CA"]["aafus"] =               { markerText = "Tachyon Collider" }
unitList["CA"]["cmgeo"] =               { markerText = "MOHO GEO" }
unitList["CA"]["amgeo"] =               { markerText = "MOHO GEO" }
unitList["CA"]["armgmm"] =              { markerText = "Prude" }
unitList["CA"]["armgeo"] =              { markerText = "Geo" }
unitList["CA"]["corgeo"] =              { markerText = "Geo" }

unitList["CA1F"] = {} --initialize table, should contain ZK buildings currently used.
unitList["CA1F"]["armamd"] =            { markerText = "Anti Nuke" }
unitList["CA1F"]["corsilo"] =           { markerText = "Nuke" }
unitList["CA1F"]["missilesilo"] =       { markerText = "Missle Silo" }
unitList["CA1F"]["armbrtha"] =          { markerText = "Big Bertha" }
unitList["CA1F"]["corbhmth"] =          { markerText = "Behemoth" }
unitList["CA1F"]["armanni"] =           { markerText = "Annihilator" }
unitList["CA1F"]["cordoom"] =           { markerText = "Doomsday" }
unitList["CA1F"]["starlight"] =         { markerText = "Starlight" }
unitList["CA1F"]["cafus"] =                     { markerText = "Singularity Reactor" }
unitList["CA1F"]["armfus"] =            { markerText = "Fusion Reactor" }
unitList["CA1F"]["amgeo"] =                     { markerText = "Moho Geo" }
--unitList["CA1F"]["geo"] =                     { markerText = "Geo" }
unitList["CA1F"]["roost"] =                             { markerText = "Roost" }
unitList["CA1F"]["chickenspire"] =              { markerText = "Spire" }
unitList["CA1F"]["chicken_dragon"] =    { markerText = "White Dragon" }
unitList["CA1F"]["chickenflyerqueen"] = { markerText = "Chicken Queen" }

--END OF MARKER LIST---------------------------------------
MK
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: script dont work

Post by knorke »

Anyway, I cant load any new widget.
Are you sure the new widget works?
Should try it in ie BA to be sure.
Keep asking in #zk until someone tells how to enable user widgets.
luckywaldo7
Posts: 1398
Joined: 17 Sep 2008, 04:36

Re: script dont work

Post by luckywaldo7 »

That widget you linked to does exactly what you are trying to do, so your effort is quite redundant :S.

It is already enabled by default so there should be no work required.
User avatar
jpcordovae
Posts: 28
Joined: 30 Apr 2009, 21:11

Re: script dont work

Post by jpcordovae »

luckywaldo7 wrote:That widget you linked to does exactly what you are trying to do, so your effort is quite redundant :S.

It is already enabled by default so there should be no work required.
The script I show it's mine, the original is a bit shorter, but make almost the same., I think is the best way to learn, take another and add stuffs.

I Already make it work, I use another 'template' script :D, that script just don't work, I don't know why.

MK
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7031
Joined: 16 Nov 2004, 13:08

Re: script dont work

Post by zwzsg »

Read infolog.txt, hopefully there'll be an error message.
User avatar
jpcordovae
Posts: 28
Joined: 30 Apr 2009, 21:11

Re: script dont work

Post by jpcordovae »

I make it works, the problem was between kb and screen: me, like almost the time, if you see in posted code, I never put the word then after the if. Anyway, spring don't say anything about error or something like that.

I've disassembled the mod and I find all I need to make any script. It isn't clear for newb's that the mods make all the definitions of units throw .fbi files... and inside that mods you can find all you need to make any script. Probably this will help to somebody like me.

Thanks to all who help me.

MK
Post Reply

Return to “Lua Scripts”