teleport the player to the center of the screen

StrikerX

Member
Hi guys, I have one question: Is there any script we can use to teleport the player to the center of the screen?
 
I don't remember teleporting to different places, but I know how to center entities in the screen. Putting them in the center of the screen is easy, but what about around in the walkable area? Do you want it also to be at the center of a walkable space (between zmin and zmax) after teleporting? If so, that's possible. I think it's also centering its position around the Z limit.

C:
void basicCenterPosition(float fY)
{
// Created by maxman
// Date: Oct-07-2023
// Entity moves to the center of the screen while staying in the walkable area. 

    void actor = getlocalvar("self"); // Call the acting entity or an actor
    int Screen = openborvariant("hresolution"); // Call the screen resolution
    int XPos  = openborvariant("xpos"); // Call X position from level coordinates
    int YPos = openborvariant("ypos"); // Call Y position from level coordinates
    int ZMin = openborvariant("player_min_z"); // Call minimum Z from level
    int ZMax = openborvariant("player_max_z"); // Call maximum Z from level

    if(ZMin <= ZMax){ //Is Z minimum limit less than or equal to Z maximum limit for a walkable space?
        changeentityproperty(actor, "position", (Screen/2)+XPos, ((ZMin+ZMax)/2)+YPos, fY); //Does the entity move to the center of screen? Does the entity stay at a walkable space? Placing outside of ground is optional.
    }

}

I just tested it in 2D plane, and it works. I haven't tested with 2.5D/3D yet, but it could work similar to 2D.
Code:
anim freespecial12 #Yoga Teleport (forward)
    delay    9
    offset    338 291
    frame    data/chars/dhalsim/cvs2_dhalsim_223.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_474.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_475.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_476.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_477.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_478.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_479.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_480.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_481.png
    delay 15
    #frame data/chars/misc/empty.gif
    frame none
    delay 9
    @cmd basicCenterPosition 60
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_481.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_480.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_479.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_478.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_477.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_476.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_475.png
    frame data/CHARS/Dhalsim/CVS2_Dhalsim_474.png
    frame    data/chars/dhalsim/cvs2_dhalsim_223.png

levels.txt examples:
Code:
branch    Stage_Ken
z    227 227
file    data/levels/ken.txt # level 6

Code:
scene   data/scenes/target/tar1.txt
branch    Stage1
z    174 264
file    data/levels/miami1.txt
next
scene   data/scenes/target/tar2.txt
branch Stage2-1
z    160 265
file    data/levels/italy1.txt
branch Stage2-2
file    data/levels/italy2.txt

I don't know if it's your liking, though.
 
Amazing code, thank you very much :D


I removed Ypos from the Code and it worked better for me.

Code:
void basicCenterPosition()
{
// Created by maxman
// Date: Oct-07-2023
// Entity moves to the center of the screen while staying in the walkable area. USAGE: @cmd basicCenterPosition

    void actor = getlocalvar("self"); // Call the acting entity or an actor
    int Screen = openborvariant("hresolution"); // Call the screen resolution
    int XPos  = openborvariant("xpos"); // Call X position from level coordinates
    int YPos = openborvariant("ypos"); // Call Y position from level coordinates
    int ZMin = openborvariant("player_min_z"); // Call minimum Z from level
    int ZMax = openborvariant("player_max_z"); // Call maximum Z from level

    if(ZMin <= ZMax){ //Is Z minimum limit less than or equal to Z maximum limit for a walkable space?
       changeentityproperty(actor, "position", (Screen/2)+XPos, ((ZMin+ZMax)/2)); //Does the entity move to the center of screen? Does the entity stay at a walkable space? Placing outside of ground is optional.
    }

}
 
Last edited:
Back
Top Bottom