Hello I am coolcostupit and I am kinda new to beamngs api and modding abilities. I am still learning but I understand lua statements so all I need to know is how I can make a function in LuaGE where the current players vehicle gets teleported to given coords. This is what my function looks like right now: local function teleport(dest) local vehicle = v.data --obj:queueGameEngineLua("queueLuaCommand('vehicle = be:getObjectByID(be:getPlayerVehicleID(0))')") vehicle.position = dest print(vehicle.position) print(dest) end the lua file is located inside modfile/lua/vehicle/extensions/luafile.lua
I did teleportation in a different way in my mod, it teleports the player by offset values, maybe it will help Code: local function teleport(X,Y,Z) for cid, node in pairs (v.data.nodes) do local d = obj:getNodePosition(node.cid):toTable() d[1] = d[1] + X d[2] = d[2] + Y d[3] = d[3] + Z obj:setNodePosition(cid, vec3(d)) end end
Thank you , do you maybe know how to get the coordinates/Vector3 Position of the destination (if available) from the Navigation extensions from beamng so players will be teleported to the destination. By the way I love ur mods.
You can teleport the player vehicle in GELua rather easily like this: Code: local function teleport(x,y,z) vx = x or 0 -- x coordinate y = y or 0 -- y coordinate z = z or 0 -- z coordinate be:getPlayerVehicle(0):setPositionNoPhysicsReset(vec3(x,y,z)) end The navigation map follows world coordinates, so if you were to figure out the cursor coordinates relative to the ui map itself you'd have usable values already. However you'd still need to figure out a Z position, but a raycast like this does suffice: Code: Engine.castRay(vec3(x,y,99999), vec3(x,y,-99999), true, true) The full code would look like this: Code: local function teleport(x,y,z) x = x or 0 -- x coordinate y = y or 0 -- y coordinate -- cast ray if not z then local res = Engine.castRay(vec3(x,y,99999), vec3(x,y,-99999), true, true) if res and res.pt then z = res.pt.z end end z = z or 0 -- z coordinate be:getPlayerVehicle(0):setPositionNoPhysicsReset(vec3(x,y,z)) end
Thank you for your reply and help. Well now I got another problem (sorry I made a writing mistake), I am not sure but due to the lua location inside my mod file , beamng will not execute the code in LuaGe , I think its vehicleLua or something called like that. By that beamng gives me the variables: v --Vehicle User data obj --Vehicle API (beamng functions for the current player vehicle) There are probably alot of other variables but I am still new to beamngs api . Also I dont know java script very well, I tried making a $score.$on(navigationmapupdate) then it returns marker.data, I get some position but I dont know if this is the right position. I cant get on my computer right now but I can send you the rest code if you'd like to continue helping me at making this mod.
I have tried it out and it does work fine but : I am not sure if it is my mistake but the problem may be it adds the coordinates and not sets them Here is how I get the maps destination position: scope.$on('NavigationGroundMarkersUpdate', (event, data) => { scope.dest = data.markers; }); Here is the button function: scope.teleport = function () { console.log(scope.dest) bngApi.engineLua('ui_message("Teleporting to mission cords")') bngApi.activeObjectLua('extensions.beamTeleporter.teleport('+scope.dest+')'); };
Yeah I just copy+pasted it from my mod and there it works by adding the coordinates, setting would be more complex
Nope, I tried and it's too tricky, you would have to compare local and global position for each node accounting for vehicle rotation
obj:queueGameEngineLua("queueLuaCommand('be:getPlayerVehicle(0):setPositionNoPhysicsReset(vec3('"..x..,..y..,..z..'))'..) Now I am trying to do it using queueLuaCommand but I get a unfinished string error , this seems very complicated here lol
Your command wasn't quite correct, here's the correct one: obj:queueGameEngineLua("be:getPlayerVehicle(0):setPositionNoPhysicsReset(vec3("..x..","..y..","..z.."))") "queueLuaCommand()" is a function you can call via GELua on vehicle objects, to execute something in vehicle lua for that specific vehicle. You don't need it here.
I just made it, you can also use the code for your mod if you'd like to : obj:queueGameEngineLua("be:getPlayerVehicle(0):setPositionNoPhysicsReset(vec3("..X..","..Y..","..Z.."))") Now it doesnt add the position to the vehicles nodes, it sets them. But do you know how to get the destination position ? Because I am not getting the destination position I am getting the nearest node position for some reason. --- Post updated --- The fact just a seconds before you posted that I made the exact same code is crazy, programmer moment lol --- Post updated --- Just a short question: Do you maybe know how I get the position from the navigation destination? This is my current code: scope.$on('NavigationGroundMarkersUpdate', (event, data) => { scope.dest = data.markers; }); scope.dest gives me the nearest node (if I am right) but I want to get the position from the destination, do you maybe know how?
data.markers contains ALL markers the path is run through; it's an array. The data is stored as x1, y1, x2, y2, etc. So you have to grab the last two items to get x and y of the last marker. You can do that like this: let x = data.markers[data.markers.length - 2]; let y = data.markers[data.markers.length - 1];
Now as you said before beamng needs to raycast the z value , but since my code is not using luaGe I did it like that: obj:queueGameEngineLua("be:getPlayerVehicle(0):setPositionNoPhysicsReset(vec3("..x..","..y..",".."(Engine.castRay(vec3("..x..","..y..",99999), vec3("..x..","..y..",-99999), true, true))".."))") Now I get this error: --- Post updated --- I MADE IT OMG THANK YOU SO MUCH FOR THE HELP This is the current code I made and it works just as fine : obj:queueGameEngineLua("be:getPlayerVehicle(0):setPositionNoPhysicsReset(vec3("..x..","..y..",".."(Engine.castRay(vec3("..x..","..y..",99999), vec3("..x..","..y..",-99999), true, true)).pt.z".."))") Thank you for the help .
Engine.rayCast returns a table containing more information than the hit height, you have to be more specific: obj:queueGameEngineLua("be:getPlayerVehicle(0):setPositionNoPhysicsReset(vec3("..x..","..y..",".."(Engine.castRay(vec3("..x..","..y..",99999), vec3("..x..","..y..",-99999), true, true).pt.z)".."))") Edit: Welp, I was too late it seems