Small Sscanf issue .. +REPP for help
#1

i have problem , heres command for rape , and its working , but i want to make that u can rape closest player to you , without entering id and it works fine when i put new ID = GetClosestPlayerToPlayer(playerid); instead new ID; but then i cant rape player using /rape id

Anyone have solution for this ??


Giving +repp for help




Код:
dcmd_rape(playerid,params[])
{
	new string[128];
 	new ID;
	new Float:phealth;
	GetPlayerHealth(ID,phealth);
	if(sscanf(params, "u", ID))
	{
	    SendClientMessage(playerid,COLOR_RED,"USAGE: /rape (Player Name/ID)");
	    return 1;
	}
    if(IsSpawned[playerid] != 1)
	{
	    SendClientMessage(playerid,COLOR_RED,"You must be alive and spawned in order to be able to use this command.");
	    return 1;
	}
	if(!IsPlayerConnected(ID))
	{
	    format(string,sizeof(string),"The player ID (%d) is not connected to the server. You cannot rape them",ID);
	    SendClientMessage(playerid,COLOR_RED,string);
	    return 1;
	}
	if(gTeam[playerid] != CIVILIAN)
	{
	    SendClientMessage(playerid,COLOR_RED,"Only Civilians can rape other players.");
	    return 1;
	}
	if(GetDistanceBetweenPlayers(playerid,ID) > 4)
	{
	    SendClientMessage(playerid,COLOR_RED,"Player is not in range.");
	    return 1;
	}
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
	{
	    SendClientMessage(playerid,COLOR_RED,"You cannot rape someone while in a vehicle. Exit the vehicle first.");
	    return 1;
	}
	if(GetPlayerState(ID) == PLAYER_STATE_DRIVER || GetPlayerState(ID) == PLAYER_STATE_PASSENGER)
	{
	    SendClientMessage(playerid,COLOR_RED,"You cannot rape someone while they are in a vehicle. Get them to exit the vehicle first.");
	    return 1;
	}
	if(IsSpawned[ID] != 1)
	{
	    format(string,sizeof(string),"%s(%d) is not spawned. You cannot rape dead people.",PlayerName(ID),ID);
	    SendClientMessage(playerid,COLOR_RED,string);
	    return 1;
	}
	if(HasRapedRecently[playerid] > 1)
	{
	    SendClientMessage(playerid,COLOR_RED,"Please wait before raping someone again.");
	    return 1;
	}
	HasRapedRecently[playerid] =15;
	SetPlayerScore(playerid, GetPlayerScore(playerid)+1);
	SetPlayerHealth(ID, phealth-5);
	format(string,sizeof(string),"%s (%d) has raped %s (%d).",PlayerName(playerid),playerid,PlayerName(ID),ID);
	SendClientMessageToAll(COLOR_ORANGE,string);
	return 1;
}
Reply
#2

Bump.. Anyone ?
Reply
#3

Код:
	if(sscanf(params, "u", ID))  return SendClientMessage(playerid,COLOR_RED,"USAGE: /rape (Player Name/ID)");
Reply
#4

pawn Код:
dcmd_rape(playerid,params[])
{

    new ID;
    if(sscanf(params, "u", ID)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /rape (Player Name/ID)");
    if(IsSpawned[playerid] != 1) return SendClientMessage(playerid,COLOR_RED,"You must be alive and spawned in order to be able to use this command.");
    if(!IsPlayerConnected(ID))
    {
        format(string,sizeof(string),"The player ID (%d) is not connected to the server. You cannot rape them",ID);
        SendClientMessage(playerid,COLOR_RED,string);
        return 1;
    }
   
    if(gTeam[playerid] != CIVILIAN)
        return SendClientMessage(playerid,COLOR_RED,"Only Civilians can rape other players.");
       
    if(GetDistanceBetweenPlayers(playerid,ID) > 4)
        return SendClientMessage(playerid,COLOR_RED,"Player is not in range.");
       
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
        return SendClientMessage(playerid,COLOR_RED,"You cannot rape someone while in a vehicle. Exit the vehicle first.");
       
    if(GetPlayerState(ID) == PLAYER_STATE_DRIVER || GetPlayerState(ID) == PLAYER_STATE_PASSENGER)
        return SendClientMessage(playerid,COLOR_RED,"You cannot rape someone while they are in a vehicle. Get them to exit the vehicle first.");

    if(HasRapedRecently[playerid] > 1)
        return SendClientMessage(playerid,COLOR_RED,"Please wait before raping someone again.");
       
    if(IsSpawned[ID] != 1)
    {
        format(string,sizeof(string),"%s(%d) is not spawned. You cannot rape dead people.",PlayerName(ID),ID);
        SendClientMessage(playerid,COLOR_RED,string);
        return 1;
    }
       
    new string[128];
    new Float:phealth;
    GetPlayerHealth(ID,phealth);
    HasRapedRecently[playerid] =15;
    SetPlayerScore(playerid, GetPlayerScore(playerid)+1);
    SetPlayerHealth(ID, phealth-5);
    format(string,sizeof(string),"%s (%d) has raped %s (%d).",PlayerName(playerid),playerid,PlayerName(ID),ID);
    SendClientMessageToAll(COLOR_ORANGE,string);
    return 1;
}
Reply
#5

So do you want if you type only "/rape" it will rape the closest but if you type "/rape ID" it will rape that person? Then this should work
pawn Код:
dcmd_rape(playerid,params[])
{
    new string[128];
    new ID;
    new Float:phealth;
    GetPlayerHealth(ID,phealth);
    if(sscanf(params, "u", ID)) ID = GetClosestPlayerToPlayer(playerid);
    //Rest code ... if(IsSpawned[playerid] != 1)
}
Reply
#6

Nah , tested alll your ideas , it still return me /rape [ID] , but when i change new ID; with new ID=GetClosestPlayerToPlayer(playerid) , then i can rape closest player but no effect with /rape [ID]
Reply
#7

Sorry for bumping again :S , but really need this working ...
Reply
#8

only the first part changed, hope it works:
Код:
dcmd_rape(playerid,params[])
{
	new string[128];
 	new ID;
	new Float:phealth;
	GetPlayerHealth(ID,phealth);
	if(sscanf(params, "u", ID))
	{
	    SendClientMessage(playerid,COLOR_RED,"USAGE: /rape (Player Name/ID)");
//	    return 1;
		ID=GetClosestPlayerToPlayer(playerid);
		if(ID!=INVALID_PLAYER_ID)
		{
			new IDName[MAX_PLAYER_NAME];
			GetPlayerName(НD,IDName,sizeof(IDName));
			format(string,sizeof(string),"Closest Player:(%d)%s",ID,IDName);
			SendClientMessage(playerid,COLOR_GREEN,string);
//			return 1;
		}
		else
		{
	    	SendClientMessage(playerid,COLOR_RED,"No Player close.");
			return 1;
		}
	}
    if(IsSpawned[playerid] != 1)
	{
	    SendClientMessage(playerid,COLOR_RED,"You must be alive and spawned in order to be able to use this command.");
	    return 1;
	}
	if(!IsPlayerConnected(ID))
	{
	    format(string,sizeof(string),"The player ID (%d) is not connected to the server. You cannot rape them",ID);
	    SendClientMessage(playerid,COLOR_RED,string);
	    return 1;
	}
	if(gTeam[playerid] != CIVILIAN)
	{
	    SendClientMessage(playerid,COLOR_RED,"Only Civilians can rape other players.");
	    return 1;
	}
	if(GetDistanceBetweenPlayers(playerid,ID) > 4)
	{
	    SendClientMessage(playerid,COLOR_RED,"Player is not in range.");
	    return 1;
	}
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
	{
	    SendClientMessage(playerid,COLOR_RED,"You cannot rape someone while in a vehicle. Exit the vehicle first.");
	    return 1;
	}
	if(GetPlayerState(ID) == PLAYER_STATE_DRIVER || GetPlayerState(ID) == PLAYER_STATE_PASSENGER)
	{
	    SendClientMessage(playerid,COLOR_RED,"You cannot rape someone while they are in a vehicle. Get them to exit the vehicle first.");
	    return 1;
	}
	if(IsSpawned[ID] != 1)
	{
	    format(string,sizeof(string),"%s(%d) is not spawned. You cannot rape dead people.",PlayerName(ID),ID);
	    SendClientMessage(playerid,COLOR_RED,string);
	    return 1;
	}
	if(HasRapedRecently[playerid] > 1)
	{
	    SendClientMessage(playerid,COLOR_RED,"Please wait before raping someone again.");
	    return 1;
	}
	HasRapedRecently[playerid] =15;
	SetPlayerScore(playerid, GetPlayerScore(playerid)+1);
	SetPlayerHealth(ID, phealth-5);
	format(string,sizeof(string),"%s (%d) has raped %s (%d).",PlayerName(playerid),playerid,PlayerName(ID),ID);
	SendClientMessageToAll(COLOR_ORANGE,string);
	return 1;
}
Reply
#9

Thats not working too , but u gave me idea (+rep) , finally i got this working..

Btw , if someone else is searching for this heres code


Код:
dcmd_rape(playerid,params[])
{
  	new ID = GetClosestPlayerToPlayer(playerid);
 	new string[128];
 	if(gTeam[playerid] != CIVILIAN)
	{
	    SendClientMessage(playerid,COLOR_RED,"Only Civilians can rape other players.");
	    return 1;
	}
 	if(sscanf(params, "u", ID))
	{
		ID=GetClosestPlayerToPlayer(playerid);
		if(GetDistanceBetweenPlayers(playerid,ID) > 8)
		{
		    SendClientMessage(playerid,COLOR_RED,"No players around.");
		    return 1;
		}
		if(HasRapedRecently[playerid] > 1)
		{
		    SendClientMessage(playerid,COLOR_RED,"Please wait before raping someone again.");
		    return 1;
		}
	}
	if(!IsPlayerConnected(ID))
	{
	    format(string,sizeof(string),"The player ID (%d) is not connected to the server.",ID);
	    SendClientMessage(playerid,COLOR_RED,string);
	    return 1;
	}
	if(GetDistanceBetweenPlayers(playerid,ID) > 4)
	{
	    SendClientMessage(playerid,COLOR_RED,"That Player Is Not Close Enough");
	    return 1;
	}
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
	{
	    SendClientMessage(playerid,COLOR_RED,"You cannot rape someone while in a vehicle. Exit the vehicle first.");
	    return 1;
	}
	if(GetPlayerState(ID) == PLAYER_STATE_DRIVER || GetPlayerState(ID) == PLAYER_STATE_PASSENGER)
	{
	    SendClientMessage(playerid,COLOR_RED,"You cannot rape someone while they are in a vehicle. Get them to exit the vehicle first.");
	    return 1;
	}
	if(IsSpawned[ID] != 1)
	{
	    format(string,sizeof(string),"%s(%d) is not spawned. You cannot rape dead people.",PlayerName(ID),ID);
	    SendClientMessage(playerid,COLOR_RED,string);
	    return 1;
	}
	if(HasRapedRecently[playerid] > 1)
	{
	    SendClientMessage(playerid,COLOR_RED,"Please wait before raping someone again.");
	    return 1;
	}
 	new Float:phealth;
	GetPlayerHealth(ID,phealth);
	HasRapedRecently[playerid] =15;
	SetPlayerScore(playerid, GetPlayerScore(playerid)+1);
	SetPlayerHealth(ID, phealth-5);
	format(string,sizeof(string),"%s (%d) has raped %s (%d).",PlayerName(playerid),playerid,PlayerName(ID),ID);
	SendClientMessageToAll(COLOR_ORANGE,string);
	return 1;
}
Reply
#10

If you take a look at my code its exactly the same as your last version, anyway... make sure you try the codes before you just "claim" you tried them.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)