Drag command
#1

So i can't drag in my server.
When i type drag it says that i am draging but actualy im not.

CMD
PHP код:
CMD:drag(playeridparams[])
{
    if(
IsACop(playerid))
    {
        new 
string[128], giveplayerid;
        if(
sscanf(params"u"giveplayerid)) return SendClientMessageEx(playeridCOLOR_GREY"USAGE: /drag [playerid]");
        if(
IsPlayerConnected(giveplayerid))
        {
            if(
GetPVarInt(giveplayerid"PlayerCuffed") == 2)
            {
                if(
IsPlayerInAnyVehicle(playerid)) return SendClientMessageEx(playeridCOLOR_WHITE" You must be out of the vehicle to use this command.");
                if(
GetPVarInt(giveplayerid"BeingDragged") == 1)
                {
                    
SendClientMessageEx(playeridCOLOR_WHITE" That player is already being dragged. ");
                    return 
1;
                }
                new 
Float:dXFloat:dYFloat:dZ;
                
GetPlayerPos(giveplayeriddXdYdZ);
                if(!
IsPlayerInRangeOfPoint(playerid5.0dXdYdZ))
                {
                    
SendClientMessageEx(playeridCOLOR_GRAD2" That suspect is not near you.");
                    return 
1;
                }
                
format(stringsizeof(string), "* %s has is now dragging you."GetPlayerNameEx(playerid));
                
SendClientMessageEx(giveplayeridCOLOR_WHITEstring);
                
format(stringsizeof(string), "* You are now dragging %s, you may move them now."GetPlayerNameEx(giveplayerid));
                
SendClientMessageEx(playeridCOLOR_WHITEstring);
                
format(stringsizeof(string), "* %s grabs ahold of %s and begins to move them."GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid));
                
ProxDetector(30.0playeridstringCOLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                
SendClientMessageEx(playeridCOLOR_WHITE"You are now dragging the suspect, press the '{AA3333}FIRE{FFFFFF}' button to stop.");
                
SetPVarInt(giveplayerid"BeingDragged"playerid);
                
SetPVarInt(playerid"DraggingPlayer"1);
            }
            else
            {
                
SendClientMessageEx(playeridCOLOR_WHITE" The specified player is not cuffed !");
            }
        }
    }
    else
    {
        
SendClientMessageEx(playeridCOLOR_GREY"   You are not a LEO ! ");
        return 
1;
    }
    return 
0;

Reply
#2

What you're doing there is merely setting the variables, where's the function that actually drags the players?
Reply
#3

Possibly i don't have that function
Reply
#4

Quote:
Originally Posted by FaZeRs
Посмотреть сообщение
Possibly i don't have that function
Then you must create it...
Give it a try and if you have any troubles ask them here;

Some tips:
- Use a timer, probably a 1s repeating timer is okay.
- Store the timer ID per player so you can kill it.
- Function must be declared as public so the timer can call it.
- Use functions such as GetXYInFrontOfPlayer to manage the position of the dragged player.
Reply
#5

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;

Reply
#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
#7

PHP код:
C:\Users\Euronics Latvija\Desktop\LCRP\gamemodes\nlrp.pwn(106718) : error 017undefined symbol "draggedtimer"
C:\Users\Euronics Latvija\Desktop\LCRP\gamemodes\nlrp.pwn(106718) : warning 215expression has no effect
C
:\Users\Euronics Latvija\Desktop\LCRP\gamemodes\nlrp.pwn(106718) : error 001expected token";"but found "]"
C:\Users\Euronics Latvija\Desktop\LCRP\gamemodes\nlrp.pwn(106718) : error 029invalid expressionassumed zero
C
:\Users\Euronics Latvija\Desktop\LCRP\gamemodes\nlrp.pwn(106718) : fatal error 107too many error messages on one line 
Reply
#8

Quote:
Originally Posted by FaZeRs
Посмотреть сообщение
PHP код:
C:\Users\Euronics Latvija\Desktop\LCRP\gamemodes\nlrp.pwn(106718) : error 017undefined symbol "draggedtimer"
C:\Users\Euronics Latvija\Desktop\LCRP\gamemodes\nlrp.pwn(106718) : warning 215expression has no effect
C
:\Users\Euronics Latvija\Desktop\LCRP\gamemodes\nlrp.pwn(106718) : error 001expected token";"but found "]"
C:\Users\Euronics Latvija\Desktop\LCRP\gamemodes\nlrp.pwn(106718) : error 029invalid expressionassumed zero
C
:\Users\Euronics Latvija\Desktop\LCRP\gamemodes\nlrp.pwn(106718) : fatal error 107too many error messages on one line 
You didn't make the command then, did you? draggedtimer[MAX_PLAYERS] must be defined somewhere in the script before it's use.
Reply
#9

Did it. But now i got

PHP код:
C:\Users\Euronics Latvija\Desktop\LCRP\gamemodes\nlrp.pwn(106736) : error 017undefined symbol "RemoveUnderScore"
C:\Users\Euronics Latvija\Desktop\LCRP\gamemodes\nlrp.pwn(106737) : error 017undefined symbol "RemoveUnderScore" 
Reply
#10

Quote:
Originally Posted by FaZeRs
Посмотреть сообщение
Did it. But now i got

PHP код:
C:\Users\Euronics Latvija\Desktop\LCRP\gamemodes\nlrp.pwn(106736) : error 017undefined symbol "RemoveUnderScore"
C:\Users\Euronics Latvija\Desktop\LCRP\gamemodes\nlrp.pwn(106737) : error 017undefined symbol "RemoveUnderScore" 
When you copy a script into your code you have to make sure that you have all the functions that are being used within that code. I can write a quick version of that function but in the future you will have to find them yourself.

The error "undefined symbol "(..)" " means that whatever it tells you is not in the script and is being called. You have to either add the missing function by yourself scripting it from zero or change it and adapt to your current script functions.

pawn Код:
stock RemoveUnderScore(playerid)
{
    new name[MAX_PLAYER_NAME],pos;
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);

    while(strfind(name,"_",true) != -1)
    {
        pos = strfind(name,"_",true);
        name[pos] = ' ';
    }

    return name;
}
Not tested, but compiles fine.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)