Quick question regarding how this should work..
#1

Well, i'm trying to do this, and i'm not sure how I should go about doing it to prevent abuse, so.. Any ideas?

pawn Код:
COMMAND:offertp(playerid, params[]) {
    new
        string[128],
        Player;

    if(PVar[playerid][AuthLvl] > 0) {
        if(sscanf(params, "u", Player)) {
            UsageMessage(playerid, "OfferTP", "[Player ID]", "Offers a teleport to the specified user.");
            return 1;
        }
        format(string, sizeof(string), "You have offered a teleport to %s! They must now accept it using /AcceptTP.", GetTheirName(Player));
        SuccessMessage(playerid, string);
        format(string, sizeof(string), "{55FF00}[OFFER] {FFFFFF}Administrator %s has offered you a teleport. You can accept it by using /AcceptTP.", GetTheirName(playerid));
        SendClientMessage(Player, WHITE, string);
        Offer[Player][0] = playerid;
        Offer[playerid][0] = Player;
    }
    else return AuthError(playerid, 1);
    return 1;
}

COMMAND:accepttp(playerid, params[]) {
    new
        Float:AdminPosition[4];

    if(Offer[playerid][0] == -1)
        return ErrorMessage(playerid, "You do not have a teleportation request.");
       
    for(new i = 0; i < cfg_SERVER_MAXPLAYERS; i++) {
        if(Offer[playerid][0] == Offer[i][0]) {
       
            GetPlayerPos(i, AdminPosition[0], AdminPosition[1], AdminPosition[2]);
            SetPlayerPos(playerid, AdminPosition[0], AdminPosition[1], AdminPosition[2]);
            Offer[playerid][0] = -1;
            Offer[i][0] = -1;
        }
    }
    return 1;
}
/AcceptTP is where i'm having the logic-block, and need help on.

I don't have a tester to help me test things, so i'm wondering if the above code will work. It logically should, but that doesn't always mean it does.
Reply
#2

Lets stip that code to the important parts

pawn Код:
//offertp
Offer[Player][0] = playerid;
Offer[playerid][0] = Player;
//accepttp
for(new i = 0; i < cfg_SERVER_MAXPLAYERS; i++) {
    if(Offer[playerid][0] == Offer[i][0]) {
        GetPlayerPos(i, AdminPosition[0], AdminPosition[1], AdminPosition[2]);
        SetPlayerPos(playerid, AdminPosition[0], AdminPosition[1], AdminPosition[2]);
        Offer[playerid][0] = -1;
        Offer[i][0] = -1;
    }
}
So Offer[x] = y; and Offer[y] = x;
Alright now we loop through all players
And check if Offer[x] (which is y) is the same as Offer[i]
So this condition is only fulfilled if two players got an offer by y
And if its fulfilled than it teleports the command user to the other player who got an offer

pawn Код:
//offertp
Offer[Player][0] = playerid;
//accepttp
GetPlayerPos(Offer[playerid][0], AdminPosition[0], AdminPosition[1], AdminPosition[2]);
SetPlayerPos(playerid, AdminPosition[0], AdminPosition[1], AdminPosition[2]);
Offer[playerid][0] = -1;
Reply
#3

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Lets stip that code to the important parts

pawn Код:
//offertp
Offer[Player][0] = playerid;
Offer[playerid][0] = Player;
//accepttp
for(new i = 0; i < cfg_SERVER_MAXPLAYERS; i++) {
    if(Offer[playerid][0] == Offer[i][0]) {
        GetPlayerPos(i, AdminPosition[0], AdminPosition[1], AdminPosition[2]);
        SetPlayerPos(playerid, AdminPosition[0], AdminPosition[1], AdminPosition[2]);
        Offer[playerid][0] = -1;
        Offer[i][0] = -1;
    }
}
So Offer[x] = y; and Offer[y] = x;
Alright now we loop through all players
And check if Offer[x] (which is y) is the same as Offer[i]
So this condition is only fulfilled if two players got an offer by y
And if its fulfilled than it teleports the command user to the other player who got an offer

pawn Код:
//offertp
Offer[Player][0] = playerid;
//accepttp
GetPlayerPos(Offer[playerid][0], AdminPosition[0], AdminPosition[1], AdminPosition[2]);
SetPlayerPos(playerid, AdminPosition[0], AdminPosition[1], AdminPosition[2]);
Offer[playerid][0] = -1;
Thank you very much -- Shortened my command by quite a bit aswell.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)