Drag Command help!
#1

Hey guys. I've been having trouble upgrading my drag command to actually stop dragging the player once you hit a key. In this one, I want it to use 'KEY_FIRE.' I'm not so sure how to do it, but when I tried using 'OnPlayerKeyPress' it wouldn't work. Read over these errors for me.

Код:
C:\Users\Randy\Desktop\Madson Roleplay (Official Server)\gamemodes\KG.pwn(70752) : error 017: undefined symbol "OnPlayerKeyPress"
C:\Users\Randy\Desktop\Madson Roleplay (Official Server)\gamemodes\KG.pwn(70753) : warning 202: number of arguments does not match definition
C:\Users\Randy\Desktop\Madson Roleplay (Official Server)\gamemodes\KG.pwn(70754) : warning 202: number of arguments does not match definition
C:\Users\Randy\Desktop\Madson Roleplay (Official Server)\gamemodes\KG.pwn(87222) : error 010: invalid function or declaration
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
Then, the code for /cuff itself.

pawn Код:
CMD:drag(playerid, params[])
{
    if(IsACop(playerid))
    {
        new string[128], giveplayerid;
        if(sscanf(params, "u", giveplayerid)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /drag [playerid]");

        if(IsPlayerConnected(giveplayerid))
        {
            if(GetPVarInt(giveplayerid, "PlayerCuffed") == 2)
            {
                if(IsPlayerInAnyVehicle(playerid)) return SendClientMessageEx(playerid, COLOR_WHITE, " You must be out of the vehicle to use this command.");
                if(GetPVarInt(giveplayerid, "BeingDragged") == 1)
                {
                    SendClientMessageEx(playerid, COLOR_WHITE, " That player is already being dragged. ");
                    return 1;
                }
                new Float:dX, Float:dY, Float:dZ;
                GetPlayerPos(giveplayerid, dX, dY, dZ);
                if(!IsPlayerInRangeOfPoint(playerid, 5.0, dX, dY, dZ))
                {
                    SendClientMessageEx(playerid, COLOR_GRAD2, " That suspect is not near you.");
                    return 1;
                }
                format(string, sizeof(string), "* %s has is now dragging you.", GetPlayerNameEx(playerid));
                SendClientMessageEx(giveplayerid, COLOR_WHITE, string);
                format(string, sizeof(string), "* You are now dragging %s, you may move them now.", GetPlayerNameEx(giveplayerid));
                SendClientMessageEx(playerid, COLOR_WHITE, string);
                format(string, sizeof(string), "* %s grabs ahold of %s and begins to move them.", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid));
                ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                SendClientMessageEx(playerid, COLOR_WHITE, "You are now dragging the suspect, press the '{AA3333}FIRE{FFFFFF}' button to stop.");
                SetPVarInt(giveplayerid, "BeingDragged", playerid);
                SetPVarInt(playerid, "DraggingPlayer", 1);
                OnPlayerKeyPress KEY_FIRE
                DeletePVar(giveplayerid, "BeingDragged", playerid);
                DeletePVar(playerid, "DraggingPlayer", 0);
            }
            else
            {
                SendClientMessageEx(playerid, COLOR_WHITE, " The specified player is not cuffed !");
            }
        }
    }
    else
    {
        SendClientMessageEx(playerid, COLOR_GREY, "   You are not a LEO ! ");
        return 1;
    }
    return 0;
}

Rep to anyone that can help.
Reply
#2

You did it wrong. You could do something like this...

Where you did:
SetPVarInt(giveplayerid, "BeingDragged", playerid);
SetPVarInt(playerid, "DraggingPlayer", 1);
OnPlayerKeyPress KEY_FIRE
DeletePVar(giveplayerid, "BeingDragged", playerid);
DeletePVar(playerid, "DraggingPlayer", 0);

Change it to:
SetPVarInt(giveplayerid, "BeingDragged", playerid);
SetPVarInt(playerid, "DraggingPlayer", giveplayerid);
As for the key-press:
Define,
// PRESSED(keys)
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
then...
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys))
{
if (PRESSED( KEY_FIRE ))
if(GetPVarInt(playerid, "DraggingPlayer" != INVALID_PLAYER_ID)
{
new giveplayerid = GetPVarInt(playerid, "DraggingPlayer");
DeletePVarInt(playerid, "DraggingPlayer" = 1)
DeletePVarIint(giveplayerid, "BeingDragged");
}
}
I also improved your code a little bit. You'd want to actually put the player's ID in "DraggingPlayer". This should work fine, if not just tell me.
Reply
#3

pawn compiler crashes.

pawn Код:
CMD:drag(playerid, params[])
{
    if(IsACop(playerid))
    {
        new string[128], giveplayerid;
        if(sscanf(params, "u", giveplayerid)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /drag [playerid]");

        if(IsPlayerConnected(giveplayerid))
        {
            if(GetPVarInt(giveplayerid, "PlayerCuffed") == 2)
            {
                if(IsPlayerInAnyVehicle(playerid)) return SendClientMessageEx(playerid, COLOR_WHITE, " You must be out of the vehicle to use this command.");
                if(GetPVarInt(giveplayerid, "BeingDragged") == 1)
                {
                    SendClientMessageEx(playerid, COLOR_WHITE, " That player is already being dragged. ");
                    return 1;
                }
                new Float:dX, Float:dY, Float:dZ;
                GetPlayerPos(giveplayerid, dX, dY, dZ);
                if(!IsPlayerInRangeOfPoint(playerid, 5.0, dX, dY, dZ))
                {
                    SendClientMessageEx(playerid, COLOR_GRAD2, " That suspect is not near you.");
                    return 1;
                }
                format(string, sizeof(string), "* %s has is now dragging you.", GetPlayerNameEx(playerid));
                SendClientMessageEx(giveplayerid, COLOR_WHITE, string);
                format(string, sizeof(string), "* You are now dragging %s, you may move them now.", GetPlayerNameEx(giveplayerid));
                SendClientMessageEx(playerid, COLOR_WHITE, string);
                format(string, sizeof(string), "* %s grabs ahold of %s and begins to move them.", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid));
                ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                SendClientMessageEx(playerid, COLOR_WHITE, "You are now dragging the suspect, press the '{AA3333}FIRE{FFFFFF}' button to stop.");
                SetPVarInt(giveplayerid, "BeingDragged", playerid);
                SetPVarInt(playerid, "DraggingPlayer", giveplayerid);
                public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)) {
                if (PRESSED( KEY_FIRE ))
                if(GetPVarInt(playerid, "DraggingPlayer" != INVALID_PLAYER_ID)
                new giveplayerid = GetPVarInt(playerid, "DraggingPlayer");
                DeletePVarInt(playerid, "DraggingPlayer" = 1)
                DeletePVarInt(giveplayerid, "BeingDragged");
            }
            else
            {
                SendClientMessageEx(playerid, COLOR_WHITE, " The specified player is not cuffed !");
            }
        }
    }
    else
    {
        SendClientMessageEx(playerid, COLOR_GREY, "   You are not a LEO ! ");
        return 1; }
    }
    return 0;
}
just requote the full command if you can.
Reply
#4

Try this, this is already tested too. So it should work for you. Good luck pal.

Код:
CMD:drag(playerid, params[])
{
	if(IsACop(playerid))
	{
		new string[128], giveplayerid;
		if(sscanf(params, "i", giveplayerid)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /drag [playerid]");

		if(IsPlayerConnected(giveplayerid))
		{
			if(IsPlayerInAnyVehicle(playerid)) return SendClientMessageEx(playerid, COLOR_WHITE, " You must be out of the vehicle to use this command.");
			if(GetPVarInt(giveplayerid, "BeingDragged") == 1)
			{
				SendClientMessageEx(playerid, COLOR_WHITE, " That player is already being dragged. ");
				return 1;
			}
			new Float:pX, Float:pY, Float:pZ;
			GetPlayerPos(giveplayerid, pX, pY, pZ);
			if(!IsPlayerInRangeOfPoint(playerid, 5.0, pX, pY, pZ))
			{
				SendClientMessageEx(playerid, COLOR_GRAD2, " That suspect is not near you.");
				return 1;
			}
			format(string, sizeof(string), "* %s is now dragging you.", GetPlayerNameEx(playerid));
			SendClientMessageEx(giveplayerid, COLOR_WHITE, string);
			format(string, sizeof(string), "* You are now dragging %s, you may move them now.", GetPlayerNameEx(giveplayerid));
			SendClientMessageEx(playerid, COLOR_WHITE, string);
			format(string, sizeof(string), "* %s grabs hold of %s and begins to move them.", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid));
			ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			SendClientMessageEx(playerid, COLOR_WHITE, "You are now dragging the suspect, press the '{AA3333}FIRE{FFFFFF}' button to move.");
			SetPVarInt(giveplayerid, "BeingDragged", 1);
			SetPVarInt(playerid, "DraggingPlayer", giveplayerid);
		}
	}
	else
	{
		SendClientMessageEx(playerid, COLOR_GREY, "   You are not a LEO ! ");
		return 1;
	}
	return 1;
}
Reply
#5

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys))
{
if (PRESSED( KEY_FIRE ))
{
				new string[128];
                if(GetPVarInt(playerid, "DraggingPlayer" != INVALID_PLAYER_ID)
                new giveplayerid = GetPVarInt(playerid, "DraggingPlayer");
                DeletePVarInt(playerid, "DraggingPlayer" = 1)
                DeletePVarInt(giveplayerid, "BeingDragged");
				new Float: x, Float: y, Float: z, vw, int;
				GetPlayerPos(playerid, x, y, z);
				GetPlayerVirtualWorld(playerid, vw);
				GetPlayerInterior(playerid, int);
				SetPlayerPos(giveplayerid, x, y, z);
				SetPlayerInterior(giveplayerid, vw);
				SetPlayerVirtualWorld(giveplayerid, int);
				format(string, sizeof(string), "You have stopped dragging %s.", GetPlayerNameEx(giveplayerid));
				SendClientMessageEx(playerid, COLOR_GRAD3, string);
	            format(string, sizeof(string), "* Officer %s has stopped dragging you.", GetPlayerNameEx(playerid));
                SendClientMessageEx(giveplayerid, COLOR_WHITE, string);
                format(string, sizeof(string), "* %s stops dragging %s - letting them free.", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid));
                ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);

}
}

CMD:drag(playerid, params[])
{
    if(IsACop(playerid))
    {
        new string[128], giveplayerid;
        if(sscanf(params, "u", giveplayerid)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /drag [playerid]");

        if(IsPlayerConnected(giveplayerid))
        {
            if(GetPVarInt(giveplayerid, "PlayerCuffed") == 2)
            {
                if(IsPlayerInAnyVehicle(playerid)) return SendClientMessageEx(playerid, COLOR_WHITE, " You must be out of the vehicle to use this command.");
                if(GetPVarInt(giveplayerid, "BeingDragged") == 1)
                {
                    SendClientMessageEx(playerid, COLOR_WHITE, " That player is already being dragged. ");
                    return 1;
                }
                new Float:dX, Float:dY, Float:dZ;
                GetPlayerPos(giveplayerid, dX, dY, dZ);
                if(!IsPlayerInRangeOfPoint(playerid, 5.0, dX, dY, dZ))
                {
                    SendClientMessageEx(playerid, COLOR_GRAD2, " That suspect is not near you.");
                    return 1;
                }
                format(string, sizeof(string), "* %s is now dragging you.", GetPlayerNameEx(playerid));
                SendClientMessageEx(giveplayerid, COLOR_WHITE, string);
                format(string, sizeof(string), "* You are now dragging %s, you may move them now.", GetPlayerNameEx(giveplayerid));
                SendClientMessageEx(playerid, COLOR_WHITE, string);
                format(string, sizeof(string), "* %s grabs ahold of %s and begins to move them.", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid));
                ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                SendClientMessageEx(playerid, COLOR_WHITE, "You are now dragging the suspect, press the '{AA3333}FIRE{FFFFFF}' button to stop.");
                SetPVarInt(giveplayerid, "BeingDragged", playerid);
                SetPVarInt(playerid, "DraggingPlayer", giveplayerid);
            }
            else
            {
                SendClientMessageEx(playerid, COLOR_WHITE, " The specified player is not cuffed !");
            }
        }
    }
    else
    {
        SendClientMessageEx(playerid, COLOR_GREY, "   You are not a LEO ! ");
        return 1; }
    }
    return 0;
}
@dano, that's not what he wants... He basically had that... Why don't you read for once? He wants to STOP DRAGGING WHEN THEY PRESS THE FIRE KEY!
Reply
#6

Thanks Abagail, but pawn library is still crashing on me! Can you just transfer the if you hit fire key to a command rather then pressing the fire key? (/sdrag)

+ Repped for the help you've given already! (:
Reply
#7

Sorry I taught he meant press the fire key to put them where he went. There was no need to rage.
Reply
#8

CMDdrag(playerid, params[])
{
if(!IsACop(playerid)) return SendClientMessageEx(playerid, -1, "Only cops can use this command.");
new string[128];
if(GetPVarInt(playerid, "DraggingPlayer" != INVALID_PLAYER_ID)
new giveplayerid = GetPVarInt(playerid, "DraggingPlayer");
DeletePVarInt(playerid, "DraggingPlayer" = 1)
DeletePVarInt(giveplayerid, "BeingDragged");
new Float: x, Float: y, Float: z, vw, int;
GetPlayerPos(playerid, x, y, z);
GetPlayerVirtualWorld(playerid, vw);
GetPlayerInterior(playerid, int);
SetPlayerPos(giveplayerid, x, y, z);
SetPlayerInterior(giveplayerid, vw);
SetPlayerVirtualWorld(giveplayerid, int);
format(string, sizeof(string), "You have stopped dragging %s.", GetPlayerNameEx(giveplayerid));
SendClientMessageEx(playerid, COLOR_GRAD3, string);
format(string, sizeof(string), "* Officer %s has stopped dragging you.", GetPlayerNameEx(playerid));
SendClientMessageEx(giveplayerid, COLOR_WHITE, string);
format(string, sizeof(string), "* %s stops dragging %s - letting them free.", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid));
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPL E,COLOR_PURPLE);
}

This should work. If pawno still crashes, let me know. Also to avoid any bugging I'd recommend making it so officers can only drag one person at a time. This could be done like so:

if(GetPVarInt(giveplayerid, "DraggingPlayer") != INVALID_PLAYER_ID)
{
SendClientMessageEx(playerid, COLOR_WHITE, " You can only drag one person at a time. ");
return 1;
}

Codes:
[/sdrag]
Код:
CMD:sdrag(playerid, params[])
{
if(!IsACop(playerid)) return SendClientMessageEx(playerid, -1, "Only cops can use this command.");
		new string[128];
                if(GetPVarInt(playerid, "DraggingPlayer" != INVALID_PLAYER_ID)
                new giveplayerid = GetPVarInt(playerid, "DraggingPlayer");
                DeletePVarInt(playerid, "DraggingPlayer" = 1)
                DeletePVarInt(giveplayerid, "BeingDragged");
				new Float: x, Float: y, Float: z, vw, int;
				GetPlayerPos(playerid, x, y, z);
				GetPlayerVirtualWorld(playerid, vw);
				GetPlayerInterior(playerid, int);
				SetPlayerPos(giveplayerid, x, y, z);
				SetPlayerInterior(giveplayerid, vw);
				SetPlayerVirtualWorld(giveplayerid, int);
				format(string, sizeof(string), "You have stopped dragging %s.", GetPlayerNameEx(giveplayerid));
				SendClientMessageEx(playerid, COLOR_GRAD3, string);
	            format(string, sizeof(string), "* Officer %s has stopped dragging you.", GetPlayerNameEx(playerid));
                SendClientMessageEx(giveplayerid, COLOR_WHITE, string);
                format(string, sizeof(string), "* %s stops dragging %s - letting them free.", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid));
                ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
}
Improved Drag command:
Код:
CMD:drag(playerid, params[])
{
    if(IsACop(playerid))
    {
        new string[128], giveplayerid;
        if(sscanf(params, "u", giveplayerid)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /drag [playerid]");

        if(IsPlayerConnected(giveplayerid))
        {
            if(GetPVarInt(giveplayerid, "PlayerCuffed") == 2)
            {
                if(IsPlayerInAnyVehicle(playerid)) return SendClientMessageEx(playerid, COLOR_WHITE, " You must be out of the vehicle to use this command.");
                if(GetPVarInt(giveplayerid, "BeingDragged") == 1)
                {
                    SendClientMessageEx(playerid, COLOR_WHITE, " That player is already being dragged. ");
                    return 1;
                }
                if(GetPVarInt(giveplayerid, "DraggingPlayer") == 1)
                {
                    SendClientMessageEx(playerid, COLOR_WHITE, " You can only drag one person at a time. Use [/sdrag] to stop dragging the other suspect.");
                    return 1;
                }
                new Float:dX, Float:dY, Float:dZ;
                GetPlayerPos(giveplayerid, dX, dY, dZ);
                if(!IsPlayerInRangeOfPoint(playerid, 5.0, dX, dY, dZ))
                {
                    SendClientMessageEx(playerid, COLOR_GRAD2, " That suspect is not near you.");
                    return 1;
                }
                format(string, sizeof(string), "* %s is now dragging you.", GetPlayerNameEx(playerid));
                SendClientMessageEx(giveplayerid, COLOR_WHITE, string);
                format(string, sizeof(string), "* You are now dragging %s, you may move them now.", GetPlayerNameEx(giveplayerid));
                SendClientMessageEx(playerid, COLOR_WHITE, string);
                format(string, sizeof(string), "* %s grabs ahold of %s and begins to move them.", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid));
                ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                SendClientMessageEx(playerid, COLOR_WHITE, "You are now dragging the suspect, press the '{AA3333}FIRE{FFFFFF}' button to stop.");
                SetPVarInt(giveplayerid, "BeingDragged", playerid);
                SetPVarInt(playerid, "DraggingPlayer", 1);
                OnPlayerKeyPress KEY_FIRE
                DeletePVar(giveplayerid, "BeingDragged", playerid);
                DeletePVar(playerid, "DraggingPlayer", 0);
            }
            else
            {
                SendClientMessageEx(playerid, COLOR_WHITE, " The specified player is not cuffed !");
            }
        }
    }
    else
    {
        SendClientMessageEx(playerid, COLOR_GREY, "   You are not a LEO ! ");
        return 1;
    }
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)