Solved Vector3 - transform.position

Discussion in 'Rust Development' started by Taffy, Oct 18, 2014.

  1. I am soooo close to getting a basic tp home mod up but stuck on what I hope is the last hurdle.

    • I can retrieve the users co-ordinates
    • I can add values to datafile for users
    • I can pull values from datafile for users
    • fail when trying to put the co-ordinates back
    error
    [Oxide] 4:30 PM [Error] tphome: [string "tphome.lua"]:97: attempt to index field
    'transform' (a nil value)

    The line failing is;
    Code:
    ply.transform.position = target.transform.position
    the following script is retrieving the x,y,z and putting into a single variable (target)
    Code:
    x = tonumber(datatable.entries[steamID][tmplocation][1])
                y = tonumber(datatable.entries[steamID][tmplocation][2])
                z = tonumber(datatable.entries[steamID][tmplocation][3])
                target =  "(" .. x .. ", " .. y .. ", " .. z .. ")"
    The original value looks like this when captured;
    (-840.5, 10.2, 2012.2)

    the value I am pushing back looks like this;
    (-840.52667236328, 10.184094429016, 2012.1553955078)

    What a pain in the *&^%
     
    Last edited by a moderator: Oct 18, 2014
  2. Wulf

    Wulf Community Admin

  3. Your target is a string and not of the type Vector3. At this time you can't create your own Vector3 yet. You want to grab the player position first and then modify the x, y & z values. If it won't work just message me and I'll give you a hand or wait until I finish my update for my tp system since it actually holds code for sethome & tphome already.
     
  4. I didn't try but I think Vector3 look like this

    Vector3 = { x=0 ,y=0 ,z=0 }
     
  5. That would result in a table with the keys x, y and z. And not a Vector3 type.
     
  6. Try replacing
    Code:
    target =  "(" .. x .. ", " .. y .. ", " .. z .. ")"
    with
    Code:
    ply.transform.position.x = x
    ply.transform.position.y = y
    ply.transform.position.z = z
    and remove ply.transform.position = target.transform.position
     
  7. Yeah I'm sorry i've tryed it in a legacy plugin and it really dont work :(
     
  8. Worked a treat thanks chaps. Code in tp home plugin

    Thanks for the assistance :)

    Cheers
    Dave