SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 18/03/2014, 01:16 PM   #1
AroseKhanNiazi
High-roller
 
AroseKhanNiazi's Avatar
 
Join Date: Jan 2014
Location: Pakistan
Posts: 1,373
Reputation: 78
Default Can't attack twice in row

How can i make something like if a player piss on the person once he can't piss on him twice in row even he can't rob him after piss but when he piss or rob someone else he can do it so can anyone give an example
AroseKhanNiazi is offline   Reply With Quote
Old 18/03/2014, 07:40 PM   #2
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,422
Reputation: 973
Default Re: Can't attack twice in row

Use a variable to store the ID of the player who they pissed on last. Check if they try to piss on them again. Remember to clear on disconnect.
MP2 is offline   Reply With Quote
Old 18/03/2014, 11:01 PM   #3
Lajko1
High-roller
 
Join Date: Oct 2008
Posts: 1,233
Reputation: 17
Default Re: Can't attack twice in row

/rob -> Robbed[giveplayerid] = 1;, JustRobbed[playerid] = 1; -> Then check if veriables are both = 1 that means it was robbed by you in other case you are able to rob that person.. add timer to reset the veriable for example 60000 = 1 min so after 1 min you will be able to rob him again, and clear veriables on Disconnect, I think it should work in this way ^^
Lajko1 is offline   Reply With Quote
Old 18/03/2014, 11:04 PM   #4
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,499
Reputation: 439
Default Re: Can't attack twice in row

Put this in your piss command:

PissedOn[playerid] = giveplayerid; // Change giveplayerid to the player being pissed on.

Then to check if they've been pissed on:

if(PissedOn[playerid] = giveplayerid) return SCM(playerid, -1, "You cannot piss on them again.");
or
if(PissedOn[playerid] = giveplayerid) return SCM(playerid, -1, "You cannot rob someone you've pissed on!");

And of-course put this at the top:

new PissedOn[MAX_PLAYERS] = INVALID_PLAYER_ID;
Abagail is offline   Reply With Quote
Old 19/03/2014, 11:49 AM   #5
AroseKhanNiazi
High-roller
 
AroseKhanNiazi's Avatar
 
Join Date: Jan 2014
Location: Pakistan
Posts: 1,373
Reputation: 78
Default Re: Can't attack twice in row

ok but i got bugs see my script
Code:
//-----Can't Attack twice in row--//
new Attacked[MAX_PLAYERS] = INVALID_PLAYER_ID;
this is on top after includes

Code:
   	CMD:rape(playerid)
{

    if(PlayerDuelWatching[playerid] == 1) return SCM(playerid,COLOR_RED," You can't use this command while watching duel /leavewatch");
    new nPlayer = GetClosestPlayer(playerid);
    if(pInfo[playerid][belt] == 1) return SCM(playerid,COLOR_RED,"You can't rape while wearing a belt");
    if(blockedrape == 1) return SCM(playerid, COLOR_RED, "/Rape is blocked by admin");
   	if(Attacked[playerid] == nPlayer) return SCM(playerid, -1, "You cannot attack the same player twice in row.");
	//if(RestrictCMD == 1) return  SendClientMessage(playerid, COLOR_RED, "You Cannot Use This Command reason:[DISABLED]");
	if(spawned[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "You Cannot Use This Command While Dead.");
	if(IsPlayerInAnyVehicle(playerid)) return  SendClientMessage(playerid,COLOR_RED,"You Cannot Use This Command While In A Vehicle.");
	if(spawned[nPlayer] == 0) return SendClientMessage(playerid, COLOR_RED, "You Cannot Rape A Dead Body.");
    //if(OnDuty[nPlayer] == 1) return SendClientMessage(playerid, COLOR_RED, "You cannot use this command on an admin on duty");
	//if(IsInChallenge[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "You cannot rape in a challenge. You can take drugs and use /ad.");
	if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,COLOR_RED,"Error: You cannot use this command in a vehicle.");
	if(spectate[nPlayer] == 1) return SendClientMessage(playerid, COLOR_RED, "Nobody close enough to rape.");
	//if(duel[nPlayer] == 1) return SendClientMessage(playerid, COLOR_RED, "you cannot rape in duel area");
	new Float:x, Float:y, Float:z;
	GetPlayerPos(playerid,x,y,z);
	if(rape[playerid] == 1) return SendClientMessage(playerid,COLOR_RED,"Error: Please wait before raping again.");

	if(IsPlayerInRangeOfPoint(nPlayer,6.0,x,y,z))
	{
        if(aduty[nPlayer] == 1) return SCM(playerid, COLOR_RED,"You can't use this command on onduty admin.");
        //if(pInfo[nPlayer][Adminlevel] > 1) return SendClientMessage(playerid, COLOR_RED, ""ERROR_MESSAGE"");
	    if(IsPlayerInAnyVehicle(nPlayer)) return SendClientMessage(playerid,COLOR_RED,"Error: The nearest player is in a vehicle.");
	    rape[playerid] =1;
	    RapeRecent1[playerid] = SetTimerEx("RapeRecent",10*1000,0,"i",playerid);
		if(pInfo[playerid][belt] == 0)
		{
	    switch(random(9))
	    {

	        case  1, 2, 3:
	        {
				GameTextForPlayer(playerid,"Raping Failed",4500,3);
				pInfo[nPlayer][belt] = 0;
				new string[128];
				format(string,sizeof(string),"%s Has attempted to rape you.",PlayerName(playerid));
				SendClientMessage(nPlayer,COLOR_RED,string);
				//SetPVarInt(playerid, "CanRape", 0);
				//RapeAgain[playerid] = SetTimerEx("ActivePlayerRape",40000,0,"i",playerid);
	        }
	        case 4, 5:
	        {
                if(pInfo[nPlayer][belt] == 1) SCM(playerid,COLOR_RED,"You Broke his belt");
                pInfo[nPlayer][belt] = 0;
                SCM(nPlayer,COLOR_RED,"Your Belt is Broken");
	            new string[128], str[128];
				new Float:myhealth, Float:he;
				GetPlayerHealth(nPlayer,myhealth);
				SetPlayerHealth(nPlayer,myhealth-float(random(40)));
				GetPlayerHealth(nPlayer, he);
				format(str, sizeof str, "%s has been raped to death by %s.", PlayerName(nPlayer), PlayerName(playerid));
				if(he <= 0.0) SendClientMessageToAll(COLOR_RED, str);
				new Float:x1, Float:y1, Float:z1;
				GetPlayerPos(nPlayer,x1,y1,z1);
				SetPlayerPos(nPlayer,x1,y1,z1+1);
			    format(string,sizeof(string),"%s Has raped you.",PlayerName(playerid));
				SendClientMessage(nPlayer,0x00FFFFC8,string);
				format(string,sizeof(string),"You have raped %s.",PlayerName(nPlayer));
				SendClientMessage(playerid,0x00FFFFC8,string);
				format(string,sizeof(string),"~w~Raped %s",PlayerName(nPlayer));
				GameTextForPlayer(playerid,string,5000,3);
				format(string,sizeof(string),"%s has raped you",PlayerName(playerid));
				GameTextForPlayer(nPlayer,string,5000,3);
				SetPlayerScore(playerid,GetPlayerScore(playerid)+1);
				Attacked[playerid] = nPlayer;
				//SetPVarInt(playerid, "CanRape", 0);
				///RapeAgain[playerid] = SetTimerEx("ActivePlayerRape",1000*40,0,"i",playerid);
	        }
	        case 6, 7:
	        {
	            if(pInfo[nPlayer][belt] == 1) SCM(playerid,COLOR_RED,"You Broke his belt");
	            pInfo[nPlayer][belt] = 0;
	            SCM(nPlayer,COLOR_RED,"Your Belt is Broken");
	            new string[128], str[128];
				new Float:myhealth, Float:he;
				GetPlayerHealth(nPlayer,myhealth);
				SetPlayerHealth(nPlayer,myhealth-float(random(30)));
				GetPlayerHealth(nPlayer, he);
				format(str, sizeof str, "%s has been raped to death by %s.", PlayerName(nPlayer), PlayerName(playerid));
				if(he <= 0.0) SendClientMessageToAll(COLOR_MAROON, str);
				new Float:x1, Float:y1, Float:z1;
				GetPlayerPos(nPlayer,x1,y1,z1);
				SetPlayerPos(nPlayer,x1,y1,z1+1);
			    format(string,sizeof(string),"%s has raped you.",PlayerName(playerid));
				SendClientMessage(nPlayer,0x00FFFFC8,string);
				format(string,sizeof(string),"You have raped %s.",PlayerName(nPlayer));
				SendClientMessage(playerid,0x00FFFFC8,string);
				format(string,sizeof(string),"~w~Raped %s",PlayerName(nPlayer));
				GameTextForPlayer(playerid,string,5000,3);
				format(string,sizeof(string),"%s has raped you",PlayerName(playerid));
				GameTextForPlayer(nPlayer,string,5000,3);
				SetPlayerScore(playerid,GetPlayerScore(playerid)+1);
				Attacked[playerid] = nPlayer;
				//SetPVarInt(playerid, "CanRape", 0);
				//RapeAgain[playerid] = SetTimerEx("ActivePlayerRape",1000*40,0,"i",playerid);
	        }
	        case 8, 9:
	        {
	            if(pInfo[nPlayer][belt] == 1) SCM(playerid,COLOR_RED,"You Broke his belt");
	            pInfo[nPlayer][belt] = 0;
	            SCM(nPlayer,COLOR_RED,"Your Belt is Broken");
	            new string[128], str[128];
				new Float:myhealth, Float:he;
				GetPlayerHealth(nPlayer,myhealth);
				SetPlayerHealth(nPlayer,myhealth-float(random(20)));
				GetPlayerHealth(nPlayer, he);
				format(str, sizeof str, "%s has been raped to death by %s.", PlayerName(nPlayer), PlayerName(playerid));
				if(he <= 0.0) SendClientMessageToAll(COLOR_MAROON, str);
				new Float:x1, Float:y1, Float:z1;
				GetPlayerPos(nPlayer,x1,y1,z1);
				SetPlayerPos(nPlayer,x1,y1,z1+1);
			    format(string,sizeof(string),"%s has raped you.",PlayerName(playerid));
				SendClientMessage(nPlayer,0x00FFFFC8,string);
				format(string,sizeof(string),"You have raped %s.",PlayerName(nPlayer));
				SendClientMessage(playerid,0x00FFFFC8,string);
				format(string,sizeof(string),"~w~Raped %s",PlayerName(nPlayer));
				GameTextForPlayer(playerid,string,5000,3);
				format(string,sizeof(string),"%s has raped you",PlayerName(playerid));
				GameTextForPlayer(nPlayer,string,5000,3);
				SetPlayerScore(playerid,GetPlayerScore(playerid)+1);
				Attacked[playerid] = nPlayer;
	        }
	    }
	}
		if(pInfo[playerid][belt] == 1)
	{
	switch(random(16))
 	{
	case  1, 2, 3:
	        {
				GameTextForPlayer(playerid,"Raping Failed But Broked His Belt",4500,3);
				pInfo[nPlayer][belt] = 0;
				new string[128];
				format(string,sizeof(string),"%s Has attempted to rape you.And Broked You Belt",PlayerName(playerid));
				SendClientMessage(nPlayer,COLOR_RED,string);
				//SetPVarInt(playerid, "CanRape", 0);
				//RapeAgain[playerid] = SetTimerEx("ActivePlayerRape",40000,0,"i",playerid);
	        }
	        case 4:
	        {
                if(pInfo[nPlayer][belt] == 1) SCM(playerid,COLOR_RED,"You Broke his belt");
                pInfo[nPlayer][belt] = 0;
                SCM(nPlayer,COLOR_RED,"Your Belt is Broken");
	            new string[128], str[128];
				new Float:myhealth, Float:he;
				GetPlayerHealth(nPlayer,myhealth);
				SetPlayerHealth(nPlayer,myhealth-float(random(40)));
				GetPlayerHealth(nPlayer, he);
				format(str, sizeof str, "%s has been raped to death by %s.", PlayerName(nPlayer), PlayerName(playerid));
				if(he <= 0.0) SendClientMessageToAll(COLOR_RED, str);
				new Float:x1, Float:y1, Float:z1;
				GetPlayerPos(nPlayer,x1,y1,z1);
				SetPlayerPos(nPlayer,x1,y1,z1+1);
			    format(string,sizeof(string),"%s Has raped you.",PlayerName(playerid));
				SendClientMessage(nPlayer,0x00FFFFC8,string);
				format(string,sizeof(string),"You have raped %s.",PlayerName(nPlayer));
				SendClientMessage(playerid,0x00FFFFC8,string);
				format(string,sizeof(string),"~w~Raped %s",PlayerName(nPlayer));
				GameTextForPlayer(playerid,string,5000,3);
				format(string,sizeof(string),"%s has raped you",PlayerName(playerid));
				GameTextForPlayer(nPlayer,string,5000,3);
				SetPlayerScore(playerid,GetPlayerScore(playerid)+1);
				Attacked[playerid] = nPlayer;
				//SetPVarInt(playerid, "CanRape", 0);
				///RapeAgain[playerid] = SetTimerEx("ActivePlayerRape",1000*40,0,"i",playerid);
	        }
	        case 6:
	        {
	            if(pInfo[nPlayer][belt] == 1) SCM(playerid,COLOR_RED,"You Broke his belt");
	            pInfo[nPlayer][belt] = 0;
	            SCM(nPlayer,COLOR_RED,"Your Belt is Broken");
	            new string[128], str[128];
				new Float:myhealth, Float:he;
				GetPlayerHealth(nPlayer,myhealth);
				SetPlayerHealth(nPlayer,myhealth-float(random(30)));
				GetPlayerHealth(nPlayer, he);
				format(str, sizeof str, "%s has been raped to death by %s.", PlayerName(nPlayer), PlayerName(playerid));
				if(he <= 0.0) SendClientMessageToAll(COLOR_MAROON, str);
				new Float:x1, Float:y1, Float:z1;
				GetPlayerPos(nPlayer,x1,y1,z1);
				SetPlayerPos(nPlayer,x1,y1,z1+1);
			    format(string,sizeof(string),"%s has raped you.",PlayerName(playerid));
				SendClientMessage(nPlayer,0x00FFFFC8,string);
				format(string,sizeof(string),"You have raped %s.",PlayerName(nPlayer));
				SendClientMessage(playerid,0x00FFFFC8,string);
				format(string,sizeof(string),"~w~Raped %s",PlayerName(nPlayer));
				GameTextForPlayer(playerid,string,5000,3);
				format(string,sizeof(string),"%s has raped you",PlayerName(playerid));
				GameTextForPlayer(nPlayer,string,5000,3);
				SetPlayerScore(playerid,GetPlayerScore(playerid)+1);
				Attacked[playerid] = nPlayer;
				//SetPVarInt(playerid, "CanRape", 0);
				//RapeAgain[playerid] = SetTimerEx("ActivePlayerRape",1000*40,0,"i",playerid);
	        }
	        case 8:
	        {
	            if(pInfo[nPlayer][belt] == 1) SCM(playerid,COLOR_RED,"You Broke his belt");
	            pInfo[nPlayer][belt] = 0;
	            SCM(nPlayer,COLOR_RED,"Your Belt is Broken");
	            new string[128], str[128];
				new Float:myhealth, Float:he;
				GetPlayerHealth(nPlayer,myhealth);
				SetPlayerHealth(nPlayer,myhealth-float(random(20)));
				GetPlayerHealth(nPlayer, he);
				format(str, sizeof str, "%s has been raped to death by %s.", PlayerName(nPlayer), PlayerName(playerid));
				if(he <= 0.0) SendClientMessageToAll(COLOR_MAROON, str);
				new Float:x1, Float:y1, Float:z1;
				GetPlayerPos(nPlayer,x1,y1,z1);
				SetPlayerPos(nPlayer,x1,y1,z1+1);
			    format(string,sizeof(string),"%s has raped you.",PlayerName(playerid));
				SendClientMessage(nPlayer,0x00FFFFC8,string);
				format(string,sizeof(string),"You have raped %s.",PlayerName(nPlayer));
				SendClientMessage(playerid,0x00FFFFC8,string);
				format(string,sizeof(string),"~w~Raped %s",PlayerName(nPlayer));
				GameTextForPlayer(playerid,string,5000,3);
				format(string,sizeof(string),"%s has raped you",PlayerName(playerid));
				GameTextForPlayer(nPlayer,string,5000,3);
				SetPlayerScore(playerid,GetPlayerScore(playerid)+1);
				Attacked[playerid] = nPlayer;
			}
			case 10,11,12,13,14,15,5,7,9:
   			{
				return SCM(playerid,COLOR_RED,"You can't rape him he is Wearing Belt");
			}
		}
	}
	}
	else
	{
	    SendClientMessage(playerid,COLOR_RED,"Nobody close enough to rape.");
	}
	return 1;
}
This is whole cmd
Code:
if(Attacked[playerid] == nPlayer) return SCM(playerid, -1, "You cannot attack the same player twice in row.");
this i added in the cmd
Code:
Attacked[playerid] = nPlayer;
when you rape the player

now the problem is it will work first time until we pass to rape him but after that we can't rape any player it says
Code:
You cannot attack the same player twice in row.
AroseKhanNiazi is offline   Reply With Quote
Old 20/03/2014, 03:54 PM   #6
AroseKhanNiazi
High-roller
 
AroseKhanNiazi's Avatar
 
Join Date: Jan 2014
Location: Pakistan
Posts: 1,373
Reputation: 78
Default Re: Can't attack twice in row

Help please
AroseKhanNiazi is offline   Reply With Quote
Old 20/03/2014, 03:58 PM   #7
Macronix
Huge Clucker
 
Macronix's Avatar
 
Join Date: Jul 2010
Location: Germany
Posts: 432
Reputation: 73
Default AW: Can't attack twice in row

Show me your function GetClosestPlayer
Macronix is offline   Reply With Quote
Old 20/03/2014, 04:49 PM   #8
AroseKhanNiazi
High-roller
 
AroseKhanNiazi's Avatar
 
Join Date: Jan 2014
Location: Pakistan
Posts: 1,373
Reputation: 78
Default Re: Can't attack twice in row

Code:
stock GetClosestPlayer(playerid)
{
	new Float:cdist, targetid = -1;
	for (new i = 0; i < MAX_PLAYERS; i++)
	{
		if (IsPlayerConnected(i) && GetPlayerState(i) != PLAYER_STATE_SPECTATING && playerid != i && (targetid < 0 || cdist > GetDistanceBetweenPlayers(playerid, i)))
		{
	  		targetid = i;
	  		cdist = GetDistanceBetweenPlayers(playerid, i);
		}
	}
	return targetid;
}
AroseKhanNiazi is offline   Reply With Quote
Old 20/03/2014, 06:43 PM   #9
Macronix
Huge Clucker
 
Macronix's Avatar
 
Join Date: Jul 2010
Location: Germany
Posts: 432
Reputation: 73
Default AW: Can't attack twice in row

Mmh.. you could check with printf's the ID of targetid, nPlayer and your variable to debug it
Macronix is offline   Reply With Quote
Old 21/03/2014, 08:12 AM   #10
AroseKhanNiazi
High-roller
 
AroseKhanNiazi's Avatar
 
Join Date: Jan 2014
Location: Pakistan
Posts: 1,373
Reputation: 78
Default Re: Can't attack twice in row

i didn't get an example will work
AroseKhanNiazi is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Attack or what? Arjanz Server Support 9 16/03/2014 03:04 AM
gta.exe Attack Ahriman Scripting Help 5 11/08/2013 05:41 PM
Bot Attack. TomTroX Bug Reports 53 26/02/2012 08:25 AM
NPC attack bug Amine_Mejrhirrou Help Archive 8 08/12/2010 07:05 PM
Bot attack [KaE]Cartman Server Support 3 18/08/2009 03:10 PM


All times are GMT. The time now is 06:58 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.