Creating a Method to make the character go up to Coord Mouse Course

Asked

Viewed 61 times

0

Good morning guys, I’m wanting to create a method to make the character walk up to the mouse coordinates, this method will be done on the server, so I made him receive the mouse coordinates, only now I have to make the server recognize the coordinates and move character to there.

Below is the process.

Client

if Mouse.trigger?(Mouse::Left)
    for i in 1..$game_temp.Player_HighIndex
        @cursor_sprite.visible = StructManager.Player(i)
        if @cursor_sprite.visible
            if StructManager.Player($game_system.MyIndex).X != (Mouse.x / 32).to_i || StructManager.Player($game_system.MyIndex).Y != (Mouse.y / 32).to_i
                @cursor_sprite.x = (Mouse.x + 16 / 32).to_i
                @cursor_sprite.y = (Mouse.y + 16 / 32).to_i
                Network.RequestCurso(i, @cursor_sprite.x, @cursor_sprite.y)
            end
        end
    end
end

Now I did so on the server, but it did not work.

    //*********************************************************************************************
    // ReceivedCurso / Revisto pela última vez em 01/08/2016, criado por LKS Florencio
    //*********************************************************************************************
    public static void ReceivedCurso(int index, string data)
    {
        //CÓDIGO
        if ((PStruct.tempplayer[index].InBank) || (PStruct.tempplayer[index].InCraft) || (PStruct.tempplayer[index].InTrade > 0) || (PStruct.tempplayer[index].InShop > 0) || (PStruct.tempplayer[index].Stunned) || (PStruct.tempplayer[index].Sleeping)) { return; }
        string[] splited = data.Replace("<99>", "").Split(';');

        if (splited.Length != 1) { return; }
        if (!IsNumeric(splited[0])) { return; }
        if ((Convert.ToInt32(splited[0]) > 10) || (Convert.ToInt32(splited[0]) < 0)) { return; }

        byte XDir = Convert.ToByte(splited[0]);
        byte YDir = Convert.ToByte(splited[1]);





        if ((PStruct.CanPlayerMove(index, XDir) == true) && (PStruct.tempplayer[index].MoveTimer < Loops.TickCount.ElapsedMilliseconds) || (PStruct.CanPlayerMove(index, YDir) == true) && (PStruct.tempplayer[index].MoveTimer < Loops.TickCount.ElapsedMilliseconds))
        {
            PStruct.PlayerCurso(index, XDir, YDir);
            PStruct.tempplayer[index].MoveTimer = Loops.TickCount.ElapsedMilliseconds + Convert.ToInt64((((8 + (4 - PStruct.tempplayer[index].movespeed) - PStruct.tempplayer[index].movespeed) * 64) - 25)); //25ms de tolerância
            WinsockAsync.Log(String.Format("Coord Selecionada"));
        }
        else
        {
        SendData.Send_PlayerXY(index);
        }



    }

Second step, as this system is to process keyboard arrow relative to the character move, does not fuse with mouse. (At least that’s what I believe is)

        //*********************************************************************************************
    // PlayerMove / Revisto pela última vez em 01/08/2016, criado por Allyson S. Bacon
    // Move determinado jogador para determinada posição
    //*********************************************************************************************
            public static void PlayerCurso(int index, byte XDir, byte YDir)
    {
        //EXTEND
        if (Extensions.ExtensionApp.ExtendMyApp
            (MethodBase.GetCurrentMethod().Name, index, XDir, YDir) != null)
        {
            return;
        }

        //CÓDIGO
        //if (PStruct.tempplayer[index].Warping) { return; }
        //Tentamos nos mover
        int x = Convert.ToInt32(PStruct.character[index, PStruct.player[index].SelectedChar].X), y = Convert.ToInt32(PStruct.character[index, PStruct.player[index].SelectedChar].Y);


        switch (YDir)
        {
            case 8:
                y -= YDir;
                PStruct.character[index, PStruct.player[index].SelectedChar].Dir = Globals.DirUp;
                break;
            case 2:
                y += YDir;
                PStruct.character[index, PStruct.player[index].SelectedChar].Dir = Globals.DirDown;
                break;
            default:
                WinsockAsync.Log(String.Format("Direção nula"));
                break;
        }
        switch (XDir)
        {
            case 4:
                x -= XDir;
                PStruct.character[index, PStruct.player[index].SelectedChar].Dir = Globals.DirLeft;
                break;
            case 6:
                x += XDir;
                PStruct.character[index, PStruct.player[index].SelectedChar].Dir = Globals.DirRight;
                break;
            default:
                WinsockAsync.Log(String.Format("Direção nula"));
                break;
        }


        int map = Convert.ToInt32(PStruct.character[index, PStruct.player[index].SelectedChar].Map);
        //int x = Convert.ToInt32(PStruct.character[index, PStruct.player[index].SelectedChar].X);
        //int y = Convert.ToInt32(PStruct.character[index, PStruct.player[index].SelectedChar].Y);
        //Verifica os tipos de tiles
        if (MStruct.tile[map, x, y].Data1 == "2")
        {
            PStruct.tempplayer[index].Warping = true;
            PlayerWarp(index, Convert.ToInt32(MStruct.tile[map, x, y].Data2), Convert.ToByte(MStruct.tile[map, x, y].Data3), Convert.ToByte(MStruct.tile[map, x, y].Data4));
            return;
        }

        //Se nenhum tile tem ação, enviar as novas coordenadas do jogador após o movimento 
        SendData.Send_PlayerXY(index);
        SendData.Send_PlayerDir(index, 1);
        //return new PlayerCurso(x, y);
    }

My doubt: How can I convert to receive mouse coordinates?

  • As the method waits for a direction and you have the coordinates, before you need to capture the current position and calculate the direction based on the coordinates received from the mouse.

  • In the RPGMX script you call the method Network.RequestCurso(i, @cursor_sprite.x, @cursor_sprite.y) passing three parameters.. on the server what should be your final target gets only 2 ReceivedCurso(int index, string data), include in your reply the RequestCurso().

  • Okay, I was really here thinking that I needed to send the player index, but I’m still on empty as the server will interpret the Coord to move the Character. I’ll add on top a new method I made for Playercurso.

  • @Leandroangelo Main, there’s a bug here that I can’t fix. in the game the character has an animation of the attacking sword, but when he passes through the portal that connects to another part of the map, an error occurs because the #i = index# of the character turns out to be #Nill

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.