SA-MP Forums Archive
dcmd /wanted command. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: dcmd /wanted command. (/showthread.php?tid=142643)



dcmd /wanted command. - Naxix - 19.04.2010

Hey! I triedto make a /wanted cmd to show which player is wanted and how many stars they have.

If no one is wanted it return as it should, but if there is someone wanted it just say "Wanted Players:"
And dosen't tell who is wanted.

code:
Код:
dcmd_wanted(playerid,params[])
{
	#pragma unused params
	new pid,string[128],wantedcount = 0,name[MAX_PLAYER_NAME];
	
	for(new j=0;j<MAX_PLAYERS;j++)
	{
 	if(GetPlayerWantedLevel(j) >= 1) wantedcount ++;
 	
	if(wantedcount == 0) return SendClientMessage(playerid, COLOUR_GREY, "There are currently no wanted players.");

	else if(wantedcount >= 1) return SendClientMessage(playerid, COLOUR_BLUE, "Wanted players:");
	for(new i=0;i<MAX_PLAYERS;i++)
		{
		  if(IsPlayerConnected(i))
			{
				if(GetPlayerWantedLevel(i) >= 1)
				{
				  new stars = GetPlayerWantedLevel(pid);
					GetPlayerName(i,name,sizeof(name));
					format(string,sizeof(string),"%s have %i stars",name,stars);
					SendClientMessage(playerid,COLOUR_BLUE,string);
					return 1;
				}
			}
		}
	}
	return 1;
}
I hope someone is able to fix this

- Naxix


Re: dcmd /wanted command. - Babul - 19.04.2010

Код:
dcmd_wanted(playerid,params[])
{
	#pragma unused params
	new ArrayWantedPlayersID[MAX_PLAYERS];
	new pid,string[128],wantedcount,name[MAX_PLAYER_NAME];
	new MaxPlayers=GetMaxPlayers();
	for(new p=0;p<MaxPlayers;p++)
	{
	 	if(GetPlayerWantedLevel(p)>0)
		{
			ArrayWantedPlayersID[wantedcount]=p;
			wantedcount++;
		}
	}

	if(wantedcount==0)
	{
		return SendClientMessage(playerid, COLOUR_GREY, "There are currently no wanted players.");
	}

	//sorting
	new ArrayWantedPlayersIDSorted[MAX_PLAYERS];
	new count;
//	for(new level=6;level>1;level--)
	for(new level=1;level<6;level++)
	{
		for(new w=0;w<wantedcount;w++)
		{
			if(GetPVarInt(ArrayWantedPlayersID[w],"WantedLevel")==level)
			{
				ArrayWantedPlayersIDSorted[count]=ArrayWantedPlayersID[w];
				count++;
			}
		}
	}
	for(new w=0;w<wantedcount;w++)
	{
		ArrayWantedPlayersID[w]=ArrayWantedPlayersIDSorted[w];
	}

	new stars;
	SendClientMessage(playerid, COLOUR_BLUE, "Wanted players:");
	for(new i=0;i<wantedcount;i++)
	{
//		if(IsPlayerConnected(ArrayWantedPlayersID[i]))	//not needed
//		{
//			if(GetPlayerWantedLevel(ArrayWantedPlayersID[i])>0)	//already checked before
//			{
				stars=GetPlayerWantedLevel(ArrayWantedPlayersID[i]);
				GetPlayerName(ArrayWantedPlayersID[i],name,sizeof(name));
				format(string,sizeof(string),"%s have %i stars",name,stars);
				SendClientMessage(playerid,COLOUR_BLUE,string);
//			}
//		}
	}
	return 1;
}
tested and working, u want the list sorted? ^^


Re: dcmd /wanted command. - Naxix - 19.04.2010

I have this error:
Код:
error 017: undefined symbol "GetPVarInt"
Do i need to download PVars or something? I never used it before


Re: dcmd /wanted command. - aircombat - 19.04.2010

u need latest : a_samp


Re: dcmd /wanted command. - Naxix - 19.04.2010

a_c?


Re: dcmd /wanted command. - Torran - 19.04.2010

Download the SA:MP 0.3a R7 Server Package


Re: dcmd /wanted command. - Naxix - 19.04.2010

Quote:
Originally Posted by Joe Torran C
Download the SA:MP 0.3a R7 Server Package
I have R7 o.O


Re: dcmd /wanted command. - Babul - 20.04.2010

i forgot to modify if-statement line to work w/o using PVariables, fixed it now.
please replace the sorting part with the (workingone) provided here:
Код:
	//sorting
	new ArrayWantedPlayersIDSorted[MAX_PLAYERS];
	new count;
//	for(new level=6;level>1;level--)
	for(new level=1;level<6;level++)
	{
		for(new w=0;w<wantedcount;w++)
		{
			if(GetPlayerWantedLevel(ArrayWantedPlayersID[w])==level)
			{
				ArrayWantedPlayersIDSorted[count]=ArrayWantedPlayersID[w];
				count++;
			}
		}
	}
	for(new w=0;w<wantedcount;w++)
	{
		ArrayWantedPlayersID[w]=ArrayWantedPlayersIDSorted[w];
	}