/drag help me
#2

No but I can explain how it would work:

Код:
#define SCM SendClientMessage //Instead of writing "SendClientMessage" we write SCM
#define WHITE 0xFFFFFFFF //Instead of writing "0xFFFFFFFF" we write WHITE

new dragTimers[MAX_PLAYERS]; //to define how many dragTimers can be used at the same time

CMD:drag(playerid, params[])
{
	new dragID; //the id we will drag
	if(sscanf(params, "u", dragID)) return SCM(playerid, WHITE, "COMMAND: /drag [ID]"); //This is just a simple way how to use sscanf, tell me if you need more explaination here!
	
	if(isPlayerInPD(playerid)) //Here you check if the player is in police faction (you have to make it yourself!)
	{
		new Float:idX, Float:idY, Float:idZ; //declaring new float variables (float is like 5.0 or 3.14159265359 (pi lol))
		GetPlayerPos(dragID, idX, idY, idZ); //will set the player's, dragID's, coordinates into the variables: idX, idY and idZ
		
		if(IsPlayerInRangeOfPoint(playerid, 2.0, idX, idY, idZ)) //will check if PLAYERID (the dude typing /drag [id] is even close to the guy you want to drag. the 2.0 is a float standing for how far away you have to be. 2.0 is quite close but not too close in my opinion
		{
			TogglePlayerControllable(dragID, 0); //Will freeze the drag ID
			//Now here to make the player follow you there are multiple ways to do it. Timer or a bool variable are good choices in my opinion (not bool variable, it gets mixed up if more players at once use /drag ^^)
			dragTimers[playerid] = SetTimerEx("dragFunction", 2000, true, "ii", playerid, dragID); //first is the function, second is the interval 2000ms = 2 seconds, third is if you want it to repeat, "ii" stands for sending two intergers in this case playerid and dragID
			//dragTimers[playerid] means that it will set a "name" for the timer. In this case if the playerid is ID 5, the timer will be called "dragTimers[5]", stored in that one.
			return 1; //once at this point, command will not run anymore below
		}
		else
		{
			SCM(playerid, WHITE, "You're not near the player!"); //Explaining if the player is NOT near the 
			return 1; //cancels everything else below
		}
	}
	else
	{
		SCM(playerid, WHITE, "You're not in the PD!"); //Explaining that the player using /drag is not in PD
		return 1; //cancels everything else below
	}
}

forward dragFunction(playerid, dragID); //really can't explain this, it's just something you have to do in this mysterious scripting language
public dragFunction(playerid, dragID)
{
	new Float:x, Float:y, Float:z;
	GetPlayerPos(playerid, x, y, z); //Will set the position of playerid into x, y and z
	SetPlayerPos(dragID, x+3, y, z); //Will set the position of the id being dragged to exact same as playerid but +3 instead meaning they won't collide
	return 1; //functions must return a value
}

CMD:stopdrag(playerid, params[])
{
	//as playerid is passed into all commands, the name of the dragTimers timer would vary from player to player, meaning only the one doing /drag could do this command (HOPEFULLY!)
	KillTimer(dragTimers[playerid]); //this will kill the timer
	return 1;
}

//REMEMBER TO KILL THE TIMER ON ONPLAYERDISCONNECT AS WELLZ!
Newbie scripter so might not the best code and don't even know if it's working haha. If you copy then screw you, trying to sit and explain here wasting my time. Hope you LEARN this and won't only copy+paste because then I will not be solving those issues at least.
Reply


Messages In This Thread
/drag help me - by vn007322815 - 23.12.2013, 23:47
Re: /drag help me - by Hansrutger - 24.12.2013, 00:13

Forum Jump:


Users browsing this thread: 2 Guest(s)