PDA

View Full Version : Small Sscanf issue .. +REPP for help


DonWade
29/12/2011, 08:19 PM
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;
}

DonWade
30/12/2011, 02:52 PM
Bump.. Anyone ?

HuSs3n
30/12/2011, 04:26 PM
if(sscanf(params, "u", ID)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /rape (Player Name/ID)");

[O.z]Caroline
30/12/2011, 06:29 PM
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;
}

Dark_Kostas
30/12/2011, 06:36 PM
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
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)
}

DonWade
30/12/2011, 08:44 PM
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]

DonWade
01/01/2012, 01:52 PM
Sorry for bumping again :S , but really need this working ...

Babul
01/01/2012, 02:19 PM
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;
}

DonWade
01/01/2012, 03:01 PM
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;
}

Dark_Kostas
01/01/2012, 03:32 PM
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.

DonWade
01/01/2012, 03:49 PM
sorry but ur code gives me few errors , and i tried it .

Dark_Kostas
01/01/2012, 03:51 PM
sorry but ur code gives me few errors , and i tried it .

It shouldnt give any errors as it's the same as the original one but with different "sscanf" line. So you probably did something wrong.