Jump to content

[PTP] Player To Player Teleport


Guest Rock

Recommended Posts

Salut.

Nu prea am ce face si m-am gandit sa fac un tutorial despre "Player To Player Teleport", mie imi place sa ii spun PTP.

Este foarte simplu si pentru cei care nu stiu la ce foloseste, e modul cel mai simplu de a te teleporta catre un alt player, apesti TAB, dai dublu click pe player-ul dorit si BINGO!

Prima data trebuie sa ai urmatoarele include-uri:

#include < rBits >

#include < zcmd  >

In caz ca nu le ai le gasesti aici.

Acum ca am avem include-urile vom pune urmatoarul cod la incepututul scriptului:

new Bit1: AllowTeleport < MAX_PLAYERS > // PTP[ Player To Player ]

Tocmai am definit o functie care vei vedea ca o vom folosii mai jos.

Acum ca am definit variabila vom cauta in gamemode/fs callback-ul urmator care va arata asa:

public OnPlayerClickPlayer( playerid, clickedplayerid, source )

{

return 1;

}

Vom definii in el variabila care stocheaza pozitia playerului selectat:

new Float: rPos[ 3 ];

Acum callback-ul nostru va arata asa:

public OnPlayerClickPlayer( playerid, clickedplayerid, source )

{

new Float: rPos[ 3 ];

return 1;

}

In continuare vom adaug functia urmatoare pentru a vedea daca player-ul selectat are activat PTP-ul si iti da voie sa te teleportezi la el.

if( Bit1_Get( AllowTeleport, clickedplayerid ) == 0 ) // 0 = activat

{

}

In interiorul acoladelor "{ }" vom adauga codul care va salva pozitia player-ului selectat in variabila creeata de noi. (rPos)

GetPlayerPos( clickedplayerid, rPos[ 0 ], rPos[ 1 ], rPos[ 2 ] ); // Aceasta functie va salva pozitia playerului

SetPlayerPos( playerid, rPos[ 0 ], rPos[ 1 ], rPos[ 2 ] ); // Aici setam pozitia ta langa celalalt player.

In momentul asta callback-ul nostru ar trebuii sa arate exact asa:

public OnPlayerClickPlayer( playerid, clickedplayerid, source )

{

new Float: rPos[ 3 ];

if( Bit1_Get( AllowTeleport, clickedplayerid ) == 0 )

{

GetPlayerPos( clickedplayerid, rPos[ 0 ], rPos[ 1 ], rPos[ 2 ] );

SetPlayerPos( playerid, rPos[ 0 ], rPos[ 1 ], rPos[ 2 ] );

}

return 1;

}

Acum vom verifica si daca acel player nu are activat PTP-ul in modul urmator:

else if( Bit1_Get( AllowTeleport, clickedplayerid ) == 1 ) // 1 = dezactivat

{

}

In interiorul acoladelor putem adauga un mesaj care te va anunta ca nu se poate efectua teleportarea.

In final callback-ul trebuie sa arate asa:

public OnPlayerClickPlayer( playerid, clickedplayerid, source )

{

new Float: rPos[ 3 ];

if( Bit1_Get( AllowTeleport, clickedplayerid ) == 0 )

{

GetPlayerPos( clickedplayerid, rPos[ 0 ], rPos[ 1 ], rPos[ 2 ] );

SetPlayerPos( playerid, rPos[ 0 ], rPos[ 1 ], rPos[ 2 ] );

}

else if( Bit1_Get( AllowTeleport, clickedplayerid ) == 1 )

{

    SendClientMessage( playerid, -1, "Acest player a dezactivat PTP[ Player To Player ] Teleport");

}

return 1;

}

Acum sa continuam cu comanda care va activa sau va dezactiva PTP-ul.

Comanda asta o punem oriunde in script dar NU sub un alt callback.

CMD:allowtele( playerid, params[ ] ) // Creem comanda /allowtele

{

if( Bit1_Get( AllowTeleport, playerid ) == 1 ) // Verificam daca PTP-ul este dezactivat

{

    Bit1_Set( AllowTeleport, playerid, 0 ); // Daca este dezactivat dam variabilei "AllowTeleport" valoarea 0, adica activat

    SendClientMessage( playerid, -1, "Player To Player Teleport Activated"); // Trimitem un mesaj player-ului ca sa activat

}

else // In caz ca nu era activat

{

    Bit1_Set( AllowTeleport, playerid, 1 ); // Daca era deja activat setam valoarea 1 variabilei "AllowTeleport" care inseamna oprit

    SendClientMessage( playerid, -1, "Player To Player Teleport Deactivated"); // Trimitem un mesaj player-ului ca PTP-ul este dezactivat

}

return 1;

}

Sper ca ati inteles si ca va este de folos.

Va multumesc ca ati citit.

Link to comment
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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.