tonihenkel

[Solved] Problem with Teleport at Spawn

Recommended Posts

Posted (edited)

Hi I'm a absolutly LUA Beginner an d I have a Problem with set  Teleport Point from a MySQL Table. After Disconnect, he saved the Position Data X, Y and Z in the MYSQL Database, this work!

 

Mysql:

PosX (Float 255) Default: 0

PosY (Float 255) Default: 0

PosZ (Float 255) Default: 0

After connect and login, he will read the Position information from the MySQL and set the player to her last position. It's the first connect (All Position Data == 0), he will spawn at airport.

 

Zitat

mp.events.add("sendDataToServer", (player, username, pass, state) => {

    
    gm.mysql.handle.query("SELECT * FROM Users WHERE `Username` = ?", [username, pass], function (err, res) {
    if (err){ err; }else{

    // Table Ergebnisse in Variablen legen


[...]
        if (res[0]["PosX"] == 0){ var table_x    = '-1044.849'; }else{ var table_x    = res[0]["PosX"]; }
        if (res[0]["PosY"] == 0){ var table_y    = '-2743.725'; }else{ var table_y    = res[0]["PosY"]; }
        if (res[0]["PosZ"] == 0){ var table_z    = '24.363';       }else{ var table_z    = res[0]["PosZ"]; }
[...]
      / / Spawn Flughafen
                    setTimeout(() => {
                    //player.position = new mp.Vector3(-1044.849, -2743.725, 24.363);
                    player.position = new mp.Vector3(table_x, table_y, table_z);                      
                    player.call('moveSkyCamera', [player, 'down'])
                    }, 100); // <-- in Millisekunden
                }

[...]
       

Zitat

 //player.position = new mp.Vector3(-1044.849, -2743.725, 24.363);  --> Is now a comment and was the old entry for alltimes spawn at airport - This works!

My Problem: The Player join not at airport when all position are 0, he spawn an another position (Anywhere in the City and under the earth). I check the varaiable with

console.log(table x + " " table_y + " " + table_z");

and the output was : -1044.849 -2743.725 24.363 

 

What is wrong ?

Edited by tonihenkel

Share this post


Link to post
Share on other sites
Posted (edited)
Zitat
You:
player.spawn(new mp.Vector3(parseFloat(res[0].PosX), parseFloat(res[0].PosY),parseFloat(res[0].PosZ))

Correct:
player.spawn(new mp.Vector3(parseFloat(res[0].PosX), parseFloat(res[0].PosY),parseFloat(res[0].PosZ))); 

 

You forget  ")" at end to close command ;)

 

When I login with  all Cordinate are Zero, its work and I spawm at airport. When I Change X, Y, Z, its not work(  Hanging in the Air Camera while spawn.is not correct: No error in console)

 

https://imgur.com/a/PcHQwX2

https://imgur.com/a/kUKnZkH

Edited by tonihenkel

Share this post


Link to post
Share on other sites
Posted (edited)
Zitat


                    
        
                        // Spawn Flughafen
                        setTimeout(() => {
                         if(parseFloat(res[0].PosX) != 0 && parseFloat(res[0].PosY) != 0){
                            console.log("1");
                            player.spawn(new mp.Vector3(parseFloat(res[0].PosX), parseFloat(res[0].PosY),parseFloat(res[0].PosZ)));   
                         }else{
                            console.log("2");
                            player.spawn(new mp.Vector3(-1044.849, -2743.725, 24.363));
                            player.call('moveSkyCamera', [player, 'down']);
                         }
                        }, 100); // <-- in Millisekunden

Console says 1 (For Testing), but he dont leave the sky camera (Error in player.spawn ?)

 

Its possible, the problem comes from mysql ?

Edited by tonihenkel

Share this post


Link to post
Share on other sites

Oh my god now its work! Ok, that was stupid :D I move the camera command and set PosZ +2 (No spawn under the earth)

 

Zitat


                    
                        // Spawn Flughafen
                        setTimeout(() => {
                         if(parseFloat(res[0].PosX) != 0 && parseFloat(res[0].PosY) != 0){
                            player.spawn(new mp.Vector3(parseFloat(res[0].PosX), parseFloat(res[0].PosY),parseFloat(res[0].PosZ)+2));   
                         }else{
                            player.spawn(new mp.Vector3(-1044.849, -2743.725, 24.363));
                         }
                         player.call('moveSkyCamera', [player, 'down']);
                        }, 100); // <-- in Millisekunden

                       

Thank you so much!

 

--CLOSE--

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.