Lua script to get the coordonate X,Y,Z in main campain

Hi,
I would like to know if it’s possible to get the coordinates number of any point in the main campaign and use it later with a script.
For now I can only use the coordinates of an object in the game (player, NPC,item…)

For example instead of using
SetCoords(coords) write SetCoords(X,Y,Z)
SetCoords(1265621,5146985,1) or SetCoords(0x1265621,0x5146985,0x1)
when I try to get the coordinate of point.
While “printing” (or using notifications) to find the coordinates of a players, I only have a value like 0x00251665 but I can not use it later with SetCoords().

Anyone know how the coordinates must be written in the function and if I need to use the editor or a script to get the values of the coordinates in the main campain ?

Thanks

I tried figuring this out some time ago and failed. Considering I started lua when I started DGA, Im still learning how exactly lua works + how Grim Dawn interacts with lua :slight_smile:

But since it was brought up again and I looked at the guide again, I may have an idea. Ill try a few things maybe I can get it done this time or maybe its not even possible and Im just wasting my time :smiley:

The setting of direct coordinates will give you a hard time.

However to find out the coordinates of a point, I’m using this:


local _player = Game.GetLocalPlayer()
local coords = _player:GetCoords()

print("---xAxis---")
print("x-Coord: %i", coords.xAxis.x)
print("y-Coord: %i", coords.xAxis.y)
print("z-Coord: %i", coords.xAxis.z)
print("---yAxis---")
print("x-Coord: %i", coords.yAxis.x)
print("y-Coord: %i", coords.yAxis.y)
print("z-Coord: %i", coords.yAxis.z)
print("---zAxis---")
print("x-Coord: %i", coords.zAxis.x)
print("y-Coord: %i", coords.zAxis.y)
print("z-Coord: %i", coords.zAxis.z)

The coordinates are 3 vectors that also describe the rotation of the player in the different axes.

Thank you Elfe,
So once I know the coordinates of a point for each axis (X,Y,Z -X,Y,Z - X,Y,Z) , can I use them with the function SetCoords() ?
What is the way to write it ?
For example
SetCoords (Xx,Yx,Zx,Xy,Yy,Zy,Xz,Yz,Zz) ?
Or
SetCoords :coords.xAxis.x(Xx)
SetCoords :coords.xAxis.y(Xy)

I did not find any examples
@WareBare I started lua with GrimDawn modding and I don’t know how to code so I have a long way to learn :wink: !

That’s a good question which I once asked a while ago and got no answer to.

In between I got some idea but I need to test that.

so yeah the guide says
coords:xAxis:x
since I now know properties use only ‘.’ I tried it with
coords.xAxis.x
and it worked (nothing new since Elfe posted it before :)), there is a Vector function, but nothing about WorldCoords and thats required for the SetCoords() method, I tried changing the values, but didnt work, like
coords.xAxis.x = 2
still uses the original coords, worth a try tho :smiley:

so I tried
worldCoords(origin,x,y,z)
Vector:worldCoords(origin,x,y,z)
and still nothing, Im running out of ideas :slight_smile:

I will try stuff when I have some free time (I am not home for now).
Let’s see what we know so far :

Entity
// instance methods
WorldCoords entity:GetCoords()
entity:SetCoords(WorldCoords coords)

WorldCoords
// properties
[ C ] Vec worldCoords: origin
[ C ] Vec worldCoords:xAxis
[ C ] Vec worldCoords:yAxis
[ C ] Vec worldCoords:zAxis
And from LuaDump

__cname: WorldCoords
__getters:
xAxis: function: 0x0da8a378
zAxis: function: 0x0da8a528
yAxis: function: 0x0da8a408
origin: function: 0x0da8a148
__type: -8
__setters:
xAxis: function: 0x0da8a3c0
zAxis: function: 0x0da8a570
yAxis: function: 0x0da8a498
origin: function: 0x0da8a2f8
Also when writing the coords do we need to try with a 0x added like the quests ?

// Note that quest and task ids should be prefaced with 0x to denote hex

Also Elfe, why don’t you use the origin coords to find the coords of a point in your script?
Like this :

print("—ORIGIN—")
print(“x-Coord: %i”, coords.origin.x)
print(“y-Coord: %i”, coords.origin.y)
print(“z-Coord: %i”, coords.origin.z)

the hex you are getting for the worldcoords or vectors are not the same as denoting a questId with 0x
infact the coord hex should be different everytime and that makes them useless for what we want to do :slight_smile:

Also the trainer made by immorrr can give us the coordinates values (in decimal format), save any number of locations and teleport the player to that place.So I believe it must be possible to achieve that with lua.

If the SetCoords(WorldCoords coords) requires hex numbers, we must find a way to convert the fixed known decimal coordinates to the valid hex coordinates in that specific game session ?

Let’s see we can :
1- Get the coordinates of multiple NPC (known fixed object location) in Devil crossing through LUA in hex numbers
2- Know these coordinate in Decimal number
3- So knowing the coordinates in Decimal and Hex format will it allow us to “build” a function to transform coordinates from Decimal to the specific hex format of that game session ?

Because these are always nil.

And the values are not hex. They’re 32 bit floats.

Hardly trying atm, making progress but nothing breaking yet.

take the following with a grain of salt, because I havnt touched C/C++/C# for 5 years :slight_smile:

forget about the hex stuff unless you are using something other than lets say
Game.GetlocalPlayer():GetCoords()
what you see is just the created variable/table/instance “id”, so its useless to us, what we have to figure out is how to create worldCoords, we can create vectors but Im starting to think there is nothing on the lua end to create worldCoord or even edit them. to make new vectors or to calculate a new location/vector with the ones we have, we can use the vector methods or create a new vector by using floats [Vector(float,float,float)]

so a new worldCoord could look like:
origin = Vector(nil,nil,nil)
xAxis = Vector(0.503942,0,0)
yAxis = Vector(0,1,0)
zAxis = Vector(0,0,-0.034)
problem is without something to create a new worldCoord instance I dont see this going anywhere :smiley:

and trainers usually manipalute the game memory, not what we are doing here :wink:

Same result here.

WorldCoords is a table, not a class which makes creating a new instance impossible.

We’re simply not supposed to be able to do that.

:frowning:

yeah I gave up, but at least I know how to get the coord floats now, no clue what I could use it for but a distance between me and an enemy is now possible to calculate :smiley: again no clue what I could do with that… yet.

Same.

What’s the purpose in being able to see coords but not use them?

We can swap positions between creatures / player but that’s pretty much it.

The only useful thing of this is that you can calculate a radius around your character and then spawn something or do some other lua functions.

Isn’t it possible to find a workaround by spawning an invisible creature then making move where we want (with the character:Move(WorldVec3 position) or the NPCwaypoint of the creature).Also I don’t know if giving him a teleport spell might help.
When the creature is at the desired location, replace it/destroy it and spawn the entity we want at this location ?

If you can create a new WorldVec3 type variable it could work but…holy crap that would be an immense script dependant action that would take way longer than what one might use this for.

Also you’d have to do a lot of calculating via scripts to calculate all the positions on your way just to make your character walk-teleport in a straight line.

Thank you Elfe that’s clearly out of my reach and motivation for such a function.Well we will have to wait for the expansion maybe there will be more lua functions that help do this.