SA-MP Forums Archive
Stupid /find problem - 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: Stupid /find problem (/showthread.php?tid=242086)



Stupid /find problem - bijoyekuza - 19.03.2011

hey guys i tried to make a /find command for cops ....
so it goes like this :
up at the gm
Код:
forward AllowFind(playerid);
the public

Код:
public AllowFind(playerid)
{
	canFind[playerid] = 0;
}
the command

Код:
    if(strcmp(cmdtext,"/find",true) == 0)
	{
		if(PlayerInfo[playerid][pCop] == 0)
		{
		    SendClientMessage(playerid,COLOR_RED,"You are not a cop!");//if the player isnt cop
		}
		if(PlayerInfo[playerid][pCop] > 1 && PlayerInfo[playerid][CopDuty] == 0 ) return SendClientMessage(playerid,COLOR_AFOR,"Ur not on cop duty!"); // if the player has the right rank of cop but he aint on duty
		if(PlayerInfo[playerid][pCop] == 1) return rank(playerid);// its a function that returns SendClientMessage(playerid,COLOR_RED,"Your rank doesnt allow you to use this tool!");
			if(PlayerInfo[playerid][pCop] > 1 && PlayerInfo[playerid][CopDuty] == 1)//if the player's cop rank is bigger then 1 + the player is on duty
			{
			new tmp[256];
			tmp = strtok(cmdtext, idx);
			new victim = strval(tmp);//the victim,the playerid
			if(!IsPlayerConnected(victim)) return notc(playerid);//if the players isnt connected it returns the function notc(playerid) - SendClientMessage(playerid,COLOR_RED,"That player is not connected!");
			if(strlen(tmp) == 0) return SendClientMessage(playerid,COLOR_RED,"Usage : /find [PLAYERID]");// if he doesnt writes the playerid
			switch(canFind[playerid])//the switch for variable canFind to this player
			{
				case 0://in case canFind for this player is 0,means he has not used this command yet.(for the 60 lats seconds) then it will find the player.
				{
				SetPlayerMarkerForPlayer(playerid,strval(tmp),COLOR_RED);//mark the victim as red
				SendClientMessage(playerid,COLOR_AFOR,"Hurry,the red marker will be gone in 60 seconds!");
				SetTimerEx("AllowFind", 60000, false, "i", playerid);//runs the timer AllowFind for this player
				}
				case 1:
				{//if the player's canFind variable is still 1 then it will do ....
				SendClientMessage(playerid,COLOR_AFOR,"You have to wait 60 seconds after usind this tool!");
				}
			}
			}
		
		return 1;
	}
when im not at duty.it says "ur not on duty" like it should
but when i am on duty and i am level 2 cop,i use /find and it returns me "usage : /find [playerid]"
and here is the big problem
when i do /find 0(my id) it returns me 0(SERVER:Unknow command.and doesnt do anything i put in the command



Re: Stupid /find problem - Klutty - 19.03.2011

And the problem is..?


Re: Stupid /find problem - bijoyekuza - 19.03.2011

when im not at duty.it says "ur not on duty" like it should
but when i am on duty and i am level 2 cop,i use /find and it returns me "usage : /find [playerid]"
and here is the big problem
when i do /find 0(my id) it returns me 0(SERVER:Unknow command.and doesnt do anything i put in the command


Re: Stupid /find problem - JaTochNietDan - 19.03.2011

Well you're checking if PlayerInfo[playerid][pCop] > 1, if I understand correctly, in your code, when they are cops, that value is set to 1, right? You're checking if it's over 1, so you need to change that check to either of the following:

pawn Код:
PlayerInfo[playerid][pCop] >= 1
PlayerInfo[playerid][pCop] > 0
Both will do the same thing, this is all assuming that the value of that variable is 1 when the person is a cop.


Re: Stupid /find problem - bijoyekuza - 19.03.2011

yea but it doesnt go like that ...

i mean
PlayerInfo[playerid][pCop] == 1 // cop lvl 1
PlayerInfo[playerid][pCop] == 2//cop lvl 2
it goes by levels
so
What I want to do is that only cops level 2+ can use this command


Re: Stupid /find problem - JaTochNietDan - 19.03.2011

Okay, the problem is with how you're using strtok, you need to use it before the command, so you get the original part of the command, the "/part" without any of the additional parameters, so for that you need to split the information and store it earlier on before the command.

For example:

pawn Код:
public OnPlayerCommandText(playerid, params[])
{
    new
        idx,
        cmd[128] = strtok(cmdtext, idx);
       
    if(strcmp(cmd,"/find",true) == 0)
    // your command
    return 0;
}
Then it should work properly when you type "/find 0", because think about what's happening now.

You type "/find", the if statement checks if cmdtext matches "/find", and it does. Then you type "/find 0", the cmdtext doesn't match "/find", because cmdtext is "/find 0". Now what we're doing is splitting up the information, so that only the first part of the command is compared.

Does this information help? It would be a lot easier if you used a command processor like DCMD, YCMD or ZCMD.


Re: Stupid /find problem - bijoyekuza - 19.03.2011

oh yea yea you right ... i used cmdtext instad of cmd
but now there is another problem(i think)...
amm ... I dont have anyone to test with him my server ... so I allways test the commands with myself
when i do /find 0(my id) the red marker just dosent show up.