Arrest command doesn't work
#1

PHP код:
command(arrestplayerid,params[])
{
    new 
string[128];
    new 
ID;
    new 
time;
    
    if (
sscanf(params"ud"IDtime))
    {
        if(
Factions[Player[playerid][Faction]][CommandTypes] == || Factions[Player[playerid][Faction]][CommandTypes] == 3)
        {
            
SendClientMessage(playeridCOLOR_GREY"SYNTAX: /arrest [playerid/name] [minutes]");
        }
        else
        {
            
RemoveTextMessage(playerid);
            
TextDrawShowForPlayer(playeridText:CantCommand);
            
SetTimerEx("RemoveTextMessage"3500false"d"playerid);
        }
    }
    if(
GetDistanceBetweenPlayers(playerid,ID) > 4)
    {
        
format(string,sizeof(string),"%s(%d) is too far away. You cannot reach him to arrest him.",RPName(ID),ID);
        
SendClientMessage(playerid,-1,string);
        return 
1;
    }
    if(
GetDistanceBetweenPlayers(playerid,ID) <= 4)
    {
        
ResetPlayerWeapons(ID);
        
Player[ID][Arrest] = 1;
        
Player[ID][PrisonTime] = time 60;
        
SetPlayerSpecialAction(IDSPECIAL_ACTION_NONE);
        
format(stringsizeof(string), "> You've arrested %s for %d days at San Andreas Prison."RPName(ID), time);
        
SendClientMessage(playeridSPECIALORANGEstring);
        
format(stringsizeof(string), "> %s has you arrested for %d days at San Andreas Prison."RPName(playerid), time);
        
SendClientMessage(IDSPECIALORANGEstring);
    }
    return 
1;

Helllo,

If you just put /arrest to check if it works, (Without ID and Time)
You will get

/arrest [id][time]
> You've arrested %s for %d days at San Andreas Prison.
> %s has you arrested for %d days at San Andreas Prison.
Reply
#2

C'mon man... What's it doing...

Don't just post up code expecting people to fix it for you by just looking at it. Tell us what is actually happening, and don't say "It doesn't work"...


It should at least be returning some output.
Reply
#3

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
C'mon man... What's it doing...

Don't just post up code expecting people to fix it for you by just looking at it. Tell us what is actually happening, and don't say "It doesn't work"...


It should at least be returning some output.
You need to read the post before posting this....
Reply
#4

Quote:
Originally Posted by lulo356
Посмотреть сообщение
You need to read the post before posting this....
I already have... Now explain what happens when you do /arrest before I shun you yet again...


I have no issue in not helping those who won't help themselves.


As I asked, What happens when you do /arrest...
Reply
#5

Quote:
Originally Posted by lulo356
Посмотреть сообщение
You need to read the post before posting this....
Okay, well I read your post and I still can't figure out how it doesn't work. No need to blame us because you can't explain something properly. In what way does it not work? The command still operates even if you leave out parameters? That's because you didn't return a value, like Sew_Sumi mentioned... but I guess you don't have the attention span to read his entire post.

pawn Код:
command(arrest, playerid,params[])
{
    new ID, time;
    if(sscanf(params, "ud", ID, time))
    {
        if(Factions[Player[playerid][Faction]][CommandTypes] == 1 || Factions[Player[playerid][Faction]][CommandTypes] == 3)
            SendClientMessage(playerid, COLOR_GREY, "SYNTAX: /arrest [playerid/name] [minutes]");
        else
        {
            RemoveTextMessage(playerid);
            TextDrawShowForPlayer(playerid, Text:CantCommand);
            SetTimerEx("RemoveTextMessage", 3500, false, "d", playerid);
        }
        return 1;
    }
    if(!IsPlayerConnected(ID) || ID == INVALID_PLAYER_ID)
        return SendClientMessage(playerid, -1, "That player does not exist."); // Change the message to your own preference. Do not continue without checking for a valid player ID.

    new string[90];
    if(GetDistanceBetweenPlayers(playerid, ID) > 4.0)
    {
        format(string, sizeof(string), "%s(%d) is too far away. You cannot reach him to arrest him.", RPName(ID), ID);
        SendClientMessage(playerid, -1, string);
    }
    else
    {
        ResetPlayerWeapons(ID);
        Player[ID][Arrest] = 1;
        Player[ID][PrisonTime] = time * 60;
        SetPlayerSpecialAction(ID, SPECIAL_ACTION_NONE);
        format(string, sizeof(string), "> You've arrested %s for %d days at San Andreas Prison.", RPName(ID), time);
        SendClientMessage(playerid, SPECIALORANGE, string);
        format(string, sizeof(string), "> %s has arrested you for %d days at San Andreas Prison.", RPName(playerid), time);
        SendClientMessage(ID, SPECIALORANGE, string);
    }
    return 1;
}
Let's hope that puts this dumb thread to rest.
Reply
#6

Instead of being asked "why does it not work" in a thread that clearly states you don't know why it does not work, I decided to restructure the command and explain each step(in the process) with comments so you can get your head around it.

Let me know if you have anymore issues. Here is the command:

pawn Код:
command(arrest, playerid,params[])
{
    new ID, time, string[90];
    if(sscanf(params, "ud", ID, time))//If the playerid did NOT enter the correct parameters..
    {
        //If the playerid did NOT enter the correct parameters..
        if(Factions[Player[playerid][Faction]][CommandTypes] == 1 || Factions[Player[playerid][Faction]][CommandTypes] == 3)//If player PASSES Faction check..
        {
            SendClientMessage(playerid, COLOR_GREY, "SYNTAX: /arrest [playerid/name] [minutes]");//Send the playerid a usage message, as they did NOT enter the correct parameters..
        }
        else//Else if the player FAILED Faction check..
        {
            //Do this..
            RemoveTextMessage(playerid);
            TextDrawShowForPlayer(playerid, Text:CantCommand);
            SetTimerEx("RemoveTextMessage", 3500, false, "d", playerid);
        }
        return 1;//This is CRITICAL. You need to tell the server to STOP here as the process is now done. Otherwise the server will just keep going(down the script)..
    }
    else//Else the playerid DID enter the correct parameters..
    {
        if(!IsPlayerConnected(ID) || ID == INVALID_PLAYER_ID)//If you have NPC's, I suggest you use !IsPlayerNPC(playerid) on this line..
        {
            return SendClientMessage(playerid, -1, "That player does not exist.");//Notify the playerid that the targetid does NOT exist..
        }
       
        if(GetDistanceBetweenPlayers(playerid, ID) > 4.0)//If the playerid EXISTS(online) and is MORE THAN 4 Metres away(or too far away)..
        {
            format(string, sizeof(string), "%s(%d) is too far away. You cannot reach him to arrest him.", RPName(ID), ID);//Notify the playerid..
            SendClientMessage(playerid, -1, string);
            return 1;//AGAIN this is CRITICAL(and was missing) as you need to tell the server when to STOP, otherwise it will CONTINUE(down the script)..
        }
        else//Else the playerid IS WITHIN or EQUAL TO 4 Metres from the targetid(ID)...
        {
            //Execute the arrest..
            ResetPlayerWeapons(ID);
            Player[ID][Arrest] = 1;
            Player[ID][PrisonTime] = time * 60;
            SetPlayerSpecialAction(ID, SPECIAL_ACTION_NONE);
            format(string, sizeof(string), "> You've arrested %s for %d days at San Andreas Prison.", RPName(ID), time);
            SendClientMessage(playerid, SPECIALORANGE, string);
            format(string, sizeof(string), "> %s has arrested you for %d days at San Andreas Prison.", RPName(playerid), time);
            SendClientMessage(ID, SPECIALORANGE, string);
            //I don't see a function that SENDS the player to Prison.. you may need to add this(unless Player[ID][Arrest] is checked somewhere else and THEN sends the targetid to Prison)
        }
    }
    return 1;
}
Reply
#7

Thank you all for your help!,

But i got the following issue now,.... The Arrest/prisontime will be not setted in the MYSQL after using this command can you maybe explain me why?
Reply
#8

Quote:
Originally Posted by lulo356
Посмотреть сообщение
The Arrest/prisontime will be not setted in the MYSQL after using this command can you maybe explain me why?
Because in this segment of code, nothing does anything with MySQL.

It should however be saving something, around the StatsSaving function usually.


Otherwise the code could go in this area

Код:
else
	{
		ResetPlayerWeapons(ID);
		Player[ID][Arrest] = 1;
		Player[ID][PrisonTime] = time * 60;
		SetPlayerSpecialAction(ID, SPECIAL_ACTION_NONE);
		format(string, sizeof(string), "> You've arrested %s for %d days at San Andreas Prison.", RPName(ID), time);
		SendClientMessage(playerid, SPECIALORANGE, string);
		format(string, sizeof(string), "> %s has arrested you for %d days at San Andreas Prison.", RPName(playerid), time);
		SendClientMessage(ID, SPECIALORANGE, string);
	}
It should have something around there, to send the info to the MySQL. Around the last 3 lines is the best, if you can't find a StatsSaving function.
Reply
#9

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Because in this segment of code, nothing does anything with MySQL.

It should however be saving something, around the StatsSaving function usually.


Otherwise the code could go in this area

Код:
else
	{
		ResetPlayerWeapons(ID);
		Player[ID][Arrest] = 1;
		Player[ID][PrisonTime] = time * 60;
		SetPlayerSpecialAction(ID, SPECIAL_ACTION_NONE);
		format(string, sizeof(string), "> You've arrested %s for %d days at San Andreas Prison.", RPName(ID), time);
		SendClientMessage(playerid, SPECIALORANGE, string);
		format(string, sizeof(string), "> %s has arrested you for %d days at San Andreas Prison.", RPName(playerid), time);
		SendClientMessage(ID, SPECIALORANGE, string);
	}
It should have something around there, to send the info to the MySQL. Around the last 3 lines is the best, if you can't find a StatsSaving function.
It's not setting the Arrest and Time now in the MYSQL, but if i look to the /aprison (Admin Jail) Everything works fine in that command, But its a kinda weird, because it should save but it doesn't do it...

Thank for your advise
Reply
#10

Post up your adminjail command. It'll simply be a case of finding where it sends it to the MySQL, and replicating that in the arrest command.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)