Detain/Drag Command Help
#1

Hi, I'm a new scripter and I'm trying to create a detain command but I can't create it. So, I came here to take help from the professionals.

pawn Код:
if(strcmp(cmd, "/detain", true) == 0) {
    if(IsSpawned[playerid] == 0) {
    SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
    return 1;
    }
    if(gTeam[playerid] != TEAM_COP && gTeam[playerid] != TEAM_ARMY) {
    SendClientMessage(playerid,COLOR_ERROR,"You are not Law Enforcement");
    return 1;
    }
    if(Jailed[playerid] ==1) {
    SendClientMessage(playerid, COLOR_ERROR, "You cannot use this command in jail");
    return 1;
    }
    if(InDerby[playerid] == 1) {
    SendClientMessage(playerid,COLOR_ERROR,"You cannot use this command while you are in the stadium");
    return 1;
    }
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp)) {
    SendClientMessage(playerid, COLOR_ERROR, "USAGE: /detain (id)");
    return 1;
    }
    giveplayerid = strval(tmp);
    if(!IsPlayerConnected(giveplayerid)) {
    format(string, sizeof(string), "ID (%d) is not an active player", giveplayerid);
    SendClientMessage(playerid, COLOR_ERROR, string);
    return 1;
    }
    new oname[24];
    new pname[24];
    GetPlayerName(playerid,oname, 24);
    GetPlayerName(giveplayerid, pname, 24);

    if(!IsNumeric(tmp)) {
    SendClientMessage(playerid, COLOR_ERROR, "USAGE: /detain (id) ID Must be a number");
    return 1;
    }

    if(gTeam[giveplayerid] <= 2) {
    SendClientMessage(playerid, COLOR_ERROR, "You cannot drag a Law Enforcement agent");
    return 1;
    }
    if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 4) {
    format(string, sizeof(string), "%s(%d) Is not close enough you cannot drag that player",pname, giveplayerid);
    SendClientMessage(playerid, COLOR_ERROR, string);
    return 1;
    }

    if(InAdminMode[giveplayerid] == 1337) {
    format(string, sizeof(string), "%s(%d) Is a server Admin. He / She is in Admin Mode. You cannot use this command on this player at this time",pname, giveplayerid);
    SendClientMessage(playerid, COLOR_ERROR, string);
    format(string, sizeof(string), "(ADMIN MODE) %s(%d) Has attempted to drag you. You are in Admin mode. You cannot be dragged",oname,playerid);
    SendClientMessage(giveplayerid, 0xFF7F50AA, string);
    return 1;
    }
    if(Jailed[giveplayerid] == 1) {
    format(string, sizeof(string), "%s(%d) Is in jail. You cannot drag a prisoner",pname, giveplayerid);
    SendClientMessage(playerid, COLOR_ERROR, string);
    return 1;
    }
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
    SendClientMessage(playerid, COLOR_ERROR, "You cannot drag a player from inside a car");
    return 1;
    }
    if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) {
    SendClientMessage(playerid, COLOR_ERROR, "You cannot drag a player from inside a car");
    return 1;
    }
    if(GetPlayerState(giveplayerid) == PLAYER_STATE_PASSENGER) {
    format(string, sizeof(string), "%s(%d) Is in a vehicle. Ask the player to get out before trying to drag him", pname, giveplayerid);
    SendClientMessage(playerid, COLOR_ERROR, string);
    return 1;
    }
    if(GetPlayerState(giveplayerid) == PLAYER_STATE_DRIVER) {
    format(string, sizeof(string), "%s(%d) Is in a vehicle. Ask the player to get out before trying to drag him", pname, giveplayerid);
    SendClientMessage(playerid, COLOR_ERROR, string);
    return 1;
    }
    if(gTeam[playerid] == TEAM_CASSEC && GetPlayerWantedLevel(giveplayerid) <=3) {
    SendClientMessage(playerid, COLOR_ERROR, "Casino Security agents can only handcuff suspects.");
    return 1;
    }

    if(GetPlayerState(giveplayerid) == PLAYER_STATE_ONFOOT) {
    SendClientMessage(giveplayerid, 0xA9A9A9AA, "| Dragged |");
    format(string, sizeof(string), "%s(%d): Has dragged you into his car",oname, playerid);
    SendClientMessage(giveplayerid, COLOR_DODGERBLUE, string);
    PutPlayerInVehicle(giveplayerid, gLastCar[playerid], 0);
    SendClientMessage(playerid, 0xA9A9A9AA, "| Suspect Dragged |");
    format(string, sizeof(string), "You have dragged %s(%d) into your vehicle", pname, giveplayerid);
    SendClientMessage(playerid, COLOR_DODGERBLUE, string);
    }
    return 1;
    }
This is what I came up with so far.
As I said, I'm new and there will be many mistakes here, so please help me with creating a detain command.

EDIT: There are no errors in compiler but when I try the command it doesn't put him in the vehicle. Please tell me my mistake and what to put where to solve this.
Reply
#2

PHP код:
if(strcmp(cmd"/detain"true) == 0) {
    if(
IsSpawned[playerid] == 0) {
    return 
SendClientMessage(playeridCOLOR_ERROR"You are dead. You cannot use this command");
    }
    if(
gTeam[playerid] != TEAM_COP && gTeam[playerid] != TEAM_ARMY) {
    return 
SendClientMessage(playerid,COLOR_ERROR,"You are not Law Enforcement");
    }
    if(
Jailed[playerid] ==1) {
    return 
SendClientMessage(playeridCOLOR_ERROR"You cannot use this command in jail");
    }
    if(
InDerby[playerid] == 1) {
    return 
SendClientMessage(playerid,COLOR_ERROR,"You cannot use this command while you are in the stadium");
    }
    
tmp strtok(cmdtextidx);
    if(!
strlen(tmp)) {
    return 
SendClientMessage(playeridCOLOR_ERROR"USAGE: /detain (id)");
    }
    
giveplayerid strval(tmp);
    if(!
IsPlayerConnected(giveplayerid)) {
    
format(stringsizeof(string), "ID (%d) is not an active player"giveplayerid);
    return 
SendClientMessage(playeridCOLOR_ERRORstring);
    }
    new 
oname[24];
    new 
pname[24];
    
GetPlayerName(playerid,oname24);
    
GetPlayerName(giveplayeridpname24);
    if(!
IsNumeric(tmp)) {
    return 
SendClientMessage(playeridCOLOR_ERROR"USAGE: /detain (id) ID Must be a number");
    }
    if(
gTeam[giveplayerid] <= 2) {
    return 
SendClientMessage(playeridCOLOR_ERROR"You cannot drag a Law Enforcement agent");
    }
    if(
GetDistanceBetweenPlayers(playerid,giveplayerid) > 4) {
    
format(stringsizeof(string), "%s(%d) Is not close enough you cannot drag that player",pnamegiveplayerid);
    return 
SendClientMessage(playeridCOLOR_ERRORstring);
    }
    if(
InAdminMode[giveplayerid] == 1337) {
    
format(stringsizeof(string), "%s(%d) Is a server Admin. He / She is in Admin Mode. You cannot use this command on this player at this time",pnamegiveplayerid);
    
SendClientMessage(playeridCOLOR_ERRORstring);
    
format(stringsizeof(string), "(ADMIN MODE) %s(%d) Has attempted to drag you. You are in Admin mode. You cannot be dragged",oname,playerid);
    return 
SendClientMessage(giveplayerid0xFF7F50AAstring);
    }
    if(
Jailed[giveplayerid] == 1) {
    
format(stringsizeof(string), "%s(%d) Is in jail. You cannot drag a prisoner",pnamegiveplayerid);
    return 
SendClientMessage(playeridCOLOR_ERRORstring);
    }
    if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
    return 
SendClientMessage(playeridCOLOR_ERROR"You cannot drag a player from inside a car");
    }
    if(
GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) {
    return 
SendClientMessage(playeridCOLOR_ERROR"You cannot drag a player from inside a car");
    }
    if(
GetPlayerState(giveplayerid) == PLAYER_STATE_PASSENGER) {
    
format(stringsizeof(string), "%s(%d) Is in a vehicle. Ask the player to get out before trying to drag him"pnamegiveplayerid);
    return 
SendClientMessage(playeridCOLOR_ERRORstring);
    }
    if(
GetPlayerState(giveplayerid) == PLAYER_STATE_DRIVER) {
    
format(stringsizeof(string), "%s(%d) Is in a vehicle. Ask the player to get out before trying to drag him"pnamegiveplayerid);
    return 
SendClientMessage(playeridCOLOR_ERRORstring);
    }
    if(
gTeam[playerid] == TEAM_CASSEC && GetPlayerWantedLevel(giveplayerid) <=3) {
    return 
SendClientMessage(playeridCOLOR_ERROR"Casino Security agents can only handcuff suspects.");
    }
    if(
GetPlayerState(giveplayerid) == PLAYER_STATE_ONFOOT) {
    
SendClientMessage(giveplayerid0xA9A9A9AA"| Dragged |");
    
format(stringsizeof(string), "%s(%d): Has dragged you into his car",onameplayerid);
    
SendClientMessage(giveplayeridCOLOR_DODGERBLUEstring);
    
PutPlayerInVehicle(giveplayeridgLastCar[playerid], 0);
    
SendClientMessage(playerid0xA9A9A9AA"| Suspect Dragged |");
    
format(stringsizeof(string), "You have dragged %s(%d) into your vehicle"pnamegiveplayerid);
    
SendClientMessage(playeridCOLOR_DODGERBLUEstring);
    }
    return 
1;
    } 
Try this and tell me the result.
Or change the returns to "return 0;" and keep the last one "return 1;"
Reply
#3

Firstly, the way you create commands through strcmp is inefficient compared to some of the command processors found on the forum, I'd recommend using izcmd since it's what most scripters use. Also, using strlen to check if the command parameters are empty is inefficient, using sscanf is more simple.

As for the problem with the command, the 0 in your PutPlayerInVehicle function means it's trying to place the dragged id into the driver's seat, which is something I imagine you don't want.

Код:
0 - Driver
1 - Front passenger
2 - Back-left passenger
3 - Back-right passenger
4+ - Passenger seats (coach etc.)
That is a guide of what the seat ids are, but everything else seems to be in place.
Reply
#4

IT WORKS!!!! OMG THANK YOU BOTH OF YOU <3
Thanks mongi & DTV.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)