Drag command
#6

Quote:
Originally Posted by FaZeRs
Посмотреть сообщение
So can i do like this?

PHP код:
forward Draggingt(playeridID);
public 
Draggingt(playeridID)
{
        new 
Float:dXFloat:dYFloat:dZ;
        
GetPlayerPos(playeriddXdYdZ);
        
SetPlayerPos(IDdX+1dYdZ);
}
CMD:drag(playeridparams[])
{
        new 
IDstring[26+MAX_PLAYER_NAME], string2[20+MAX_PLAYER_NAME];
        if(
sscanf(params"u"ID)) return SendClientMessage(playeridGREY"CMD:/drag [playerid]");
        if(
pCuffed[ID] == 0) return SendClientMessage(playeridGREY"This player must first be cuffed");
        if(
Dragged[ID] == && Dragging[playerid] == 0)
        {
            
Dragged[ID] = 1;
            
Dragging[playerid] = 1;
            
format(stringsizeof(string), "You are being dragged by %s."RemoveUnderScore(playerid));
            
format(string2sizeof(string2), " You are dragging %s."RemoveUnderScore(ID));
            
SCM(playeridPURPLEstring2);
            
SCM(IDPURPLEstring);
        
draggedtimer[ID] = SetTimerEx("Draggingt"10001"dd"playerid,ID);
        }
        else
        {
            
Dragged[ID] = 0;
            
Dragging[playerid] = 0;
            
SCM(playeridPURPLE"You have stopped dragging your target.");
            
SCM(IDPURPLE"You aren't being dragged anymore.");
            
KillTimer(draggedtimer[ID]);
        }
        return 
1;

Yes that would work but x+1 would not always be the front of the player, it could be anywhere actually.

Use this function

pawn Код:
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    GetPlayerFacingAngle(playerid, a);
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}

forward Draggingt(playerid, ID);
public Draggingt(playerid, ID)
{
        if(Dragged[ID] != playerid)
             KillTimer(draggedtimer[ID]),
             return 1; //just in case.

        new Float:fX, Float:fY, Float:fZ;
        GetPlayerPos(playerid, fX,fY,fZ);
        GetXYInFrontOfPlayer(playerid, fX,fY,1.0);
        SetPlayerPos(ID, fX,fY,fZ);
        return 1;
}

//little improvement
CMD:drag(playerid, params[])
{
        new ID, string[26+MAX_PLAYER_NAME], string2[20+MAX_PLAYER_NAME];
        if(sscanf(params, "u", ID)) return SendClientMessage(playerid, GREY, "CMD:/drag [playerid]");
        if(pCuffed[ID] == 0) return SendClientMessage(playerid, GREY, "This player must first be cuffed");
        if(Dragged[ID] == INVALID_PLAYER_ID && Dragging[playerid] == INVALID_PLAYER_ID)
        {
            Dragged[ID] = playerid;
            Dragging[playerid] = ID;
            format(string, sizeof(string), "You are being dragged by %s.", RemoveUnderScore(playerid));
            format(string2, sizeof(string2), " You are dragging %s.", RemoveUnderScore(ID));
            SCM(playerid, PURPLE, string2);
            SCM(ID, PURPLE, string);
            draggedtimer[ID] = SetTimerEx("Draggingt", 1000, 1, "dd", playerid,ID);
        }
        else if(Dragged[ID] == playerid && Dragging[playerid] == ID)
        {
            Dragged[ID] = INVALID_PLAYER_ID;
            Dragging[playerid] = INVALID_PLAYER_ID;
            SCM(playerid, PURPLE, "You have stopped dragging your target.");
            SCM(ID, PURPLE, "You aren't being dragged anymore.");
            KillTimer(draggedtimer[ID]);
        }
        return 1;
}
At onplayerconnect to reset the variables

pawn Код:
Dragged[playerid] = INVALID_PLAYER_ID;
Dragging[playerid] = INVALID_PLAYER_ID;
At Onplayerdisconnect

pawn Код:
if(Dragging[playerid] != INVALID_PLAYER_ID)
{
    KillTimer(draggedtimer[Dragging[playerid]]);
    Dragged[Dragging[playerid]] = INVALID_PLAYER_ID;
    Dragging[playerid] = INVALID_PLAYER_ID;
}

if(Dragged[playerid] != INVALID_PLAYER_ID)
{
    Dragging[Dragged[playerid]] = INVALID_PLAYER_ID;
    Dragged[playerid] = INVALID_PLAYER_ID;
    KillTimer(draggedtimer[playerid]);
}
This will reset both the timer and the variables if the player is being dragged or is dragging anyone.
Reply


Messages In This Thread
Drag command - by FaZeRs - 02.02.2014, 00:21
Re: Drag command - by CuervO - 02.02.2014, 00:26
Re: Drag command - by FaZeRs - 02.02.2014, 00:28
Re: Drag command - by CuervO - 02.02.2014, 00:36
Re: Drag command - by FaZeRs - 02.02.2014, 01:26
Re: Drag command - by CuervO - 02.02.2014, 01:55
Re: Drag command - by FaZeRs - 02.02.2014, 02:08
Re: Drag command - by CuervO - 02.02.2014, 02:10
Re: Drag command - by FaZeRs - 02.02.2014, 02:14
Re: Drag command - by CuervO - 02.02.2014, 02:23

Forum Jump:


Users browsing this thread: 1 Guest(s)