PDA

View Full Version : VectorResource management in Lua scripts?


_Kilburn
27 Aug 2006, 15:22
Hi, i'm almost sure that nobody will answer my question but... I'm trying to make some funny game modes by modifying stdvs.lua. And I made a simple function that spawns a crate at a random position:

function lib_QuickSpawnCrate(CrateContainerData)
SendMessage("GameLogic.ResetCrateParameters")
SetData("Crate.Type", CrateContainerData.Type)
SetData("Crate.Contents", CrateContainerData.Contents)
SetData("Crate.NumContents", CrateContainerData.NumContents)
SetData("Crate.Index", CrateContainerData.Index)
SetData("Crate.LifetimeSec", CrateContainerData.LifetimeSec)
SetData("Crate.GroundSnap", CrateContainerData.GroundSnap)
SetData("Crate.Parachute", CrateContainerData.Parachute)
SetData("Crate.Spawn", CrateContainerData.Spawn)
SetData("Crate.FallSpeed", CrateContainerData.FallSpeed)
SetData("Crate.Gravity", CrateContainerData.Gravity)
SetData("Crate.TeamDestructible", CrateContainerData.TeamDestructible)
SetData("Crate.TeamCollectable", CrateContainerData.TeamCollectable)
SetData("Crate.UXB", CrateContainerData.UXB)
SetData("Crate.Hitpoints", CrateContainerData.Hitpoints)
SetData("Crate.Pushable", CrateContainerData.Pushable)
SetData("Crate.RandomSpawnPos", CrateContainerData.RandomSpawnPos)
SetData("Crate.CanDropFromChute", CrateContainerData.CanDropFromChute)
SetData("Crate.WaitTillLanded", CrateContainerData.WaitTillLanded)
SetData("Crate.TrackCam", CrateContainerData.TrackCam)
SetData("Crate.Scale", CrateContainerData.Scale)
SetData("Crate.AddToWormInventory", CrateContainerData.AddToWormInventory)
SetData("Crate.CustomGraphic", CrateContainerData.CustomGraphic)
SendMessage("GameLogic.CreateCrate")
end

But how can I spawn a crate at a wanted position? I found a Crate.ExplicitSpawnPos property in Local.xml, but it is a VectorResource, so I can't modifiy it, neither with SetData, nor with EditContainer.
GetData("Crate.ExplicitSpawnPos") and QueryContainer("Crate.ExplicitSpawnPos") return nil. (nil is a Lua value which means NULL)
I dumped all variables with "for key,value in pairs(getfenv()) do ... end" and i don't see any function with "Vector" in its name. :(

And i would like the same thing for creating particle emitters, explosions and triggers.

If someone answers to my question, it would be extraordinary... :rolleyes:

_Kilburn
1 Sep 2006, 19:01
If someone answers to my question, it would be extraordinary... :rolleyes:

I was right... :p

Gerich
31 Mar 2009, 19:54
I hasn't found any way to write vectors, but I can put vector into array(table)

example for position of worm.Position

Пример:
local CurrentWorm = GetData("ActiveWormIndex")
if CurrentWorm ~= -1 then
local DataId = lib_GetWormContainerName(CurrentWorm)
local worm = QueryContainer(DataId)
SetData( "Text.TestComment", worm.Position) --replace worm.Position by any VectorResource
SubString( "Text.TestComment", "Text.TestComment" , "(" , "Vector = {" )
SubString( "Text.TestComment", "Text.TestComment" , ")" , "}" )
local TextTable = GetData("Text.TestComment")
assert(loadstring(TextTable))()

--Now Vector has fields x,y,z
SetData("Text.TestComment", "Position Y = "..Vector.y)
SetData("CommentaryPanel.Comment", "Text.TestComment")
SendMessage("CommentaryPanel.ScriptText")

end

vectors in Worms are simple strings, but you can't edit them =( there is no way to do it, except hacking game code)))

_Kilburn
1 Apr 2009, 08:29
Old post is old, but woah, never thought of using SubString and loadstring, genius idea you've got there. Thanks a lot. :p

Also, I only needed reading, writing wasn't really important, so it's perfect.