Need help with my command
#1

I have a /drag command that works pretty well ( i know it can be abused, because i havint added many things lol, i'm still on process of making it)

The problem is, How can I display something like "You need to have a car before you /drag a suspect" If a player has not previously entered a car?


pawn Код:
if(strcmp(cmd, "/drag", true) == 0)
    {
    if(IsSpawned[playerid] == 0) {
    SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
  return 1;
  }
    if(Jailed[playerid] ==1) {
  SendClientMessage(playerid, COLOR_ERROR, "You cannot use this command in jail");
  return 1;
  }
  if(gTeam[playerid] != TEAM_COP) {
  SendClientMessage(playerid,COLOR_ERROR,"You are not part of the SWAT team. Only SWAT can use this command");
  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: /drag (id)");
  return 1;
  }
  giveplayerid = strval(tmp);
  if(!IsPlayerConnected(giveplayerid)) {
  format(szstring, sizeof(szstring), "ID (%d) is not an active player", giveplayerid);
  SendClientMessage(playerid, COLOR_ERROR, szstring);
  return 1;
  }
  GetPlayerName(playerid,oname, 24);
    GetPlayerName(giveplayerid, pname, 24);

    if(!IsNumeric(tmp)) {
  SendClientMessage(playerid, COLOR_ERROR, "USAGE: /drag (id) ID Must be a number");
  return 1;
  }
    if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 4) {
    format(szstring, sizeof(szstring), "%s(%d) Is not close enough you cannot drag that player",pname, giveplayerid);
  SendClientMessage(playerid, COLOR_ERROR, szstring);
  return 1;
  }
  if(Jailed[giveplayerid] == 1) {
  format(szstring, sizeof(szstring), "%s(%d) Is in jail. You cannot drag a prisoner",pname, giveplayerid);
  SendClientMessage(playerid, COLOR_ERROR, szstring);
  return 1;
  }
  if(IsPlayerInAnyVehicle(playerid)) {
  SendClientMessage(playerid, COLOR_ERROR, "You are in a vehicle. You must be on foot to drag");
  return 1;
  }
  if(IsPlayerInAnyVehicle(giveplayerid)) {
  SendClientMessage(playerid, COLOR_ERROR, "That player is already in a vehicle");
  return 1;
  }
  SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_DRAGGED_|");
  format(szstring, sizeof(szstring), "%s(%d): has dragged you,use /breakcuffs to attempt an escape!",oname, playerid);
  SendClientMessage(giveplayerid, COLOR_DODGERBLUE, szstring);
  TogglePlayerControllable(giveplayerid, 0);
  isKidnapped[giveplayerid] =1;
  oscore = GetPlayerScore(playerid);
  SetPlayerScore(playerid, oscore +1);
  SendClientMessage(playerid, 0xA9A9A9AA, "|_Criminal Dragged|");
    format(szstring, sizeof(szstring), "You have grabbed %s(%d) and thrown him into your car!", pname, giveplayerid);
  SendClientMessage(playerid, COLOR_DODGERBLUE, szstring);
  format(szstring, sizeof(szstring), "%s(%d) has grabbed %s(%d) and thrown him into his car!",oname,playerid,pname,giveplayerid);
  SendClientMessageToAll(0x00C7FFAA, szstring);
  PutPlayerInVehicle(giveplayerid,KidCar[playerid],1);
  HasKidnapped[playerid] =1;
    format(szstring, sizeof(szstring), "~r~DRAGGED BY SWAT MEMBER~n~~w~%s(%d)",oname,playerid);
  GameTextForPlayer(giveplayerid,szstring,5000,3);
  return 1;
  }
pawn Код:
new KidCar[MAX_PLAYERS];

  if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER && gTeam[playerid] == TEAM_KIDNAPPER)
    {
    KidCar[playerid] = GetPlayerVehicleID(playerid);
    }
Reply
#2

OnPlayerExitVehicle save a gLastCar[playerid] and if gLastCar[playerid] == INVALID_VEHICLE_ID or w/e on the command you cannot use it...

pawn Код:
#define INVALID_VEHICLE_ID 500
pawn Код:
new gLastCar[MAX_PLAYERS];
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
gLastCar[playerid] = vehicleid;
return 1;
}
Then, on the command have..

pawn Код:
if(gLastCar[playerid] == INVALID_VEHICLE_ID) {
// do something here
return 1;
}
Reply
#3

But won't that just check to see if it's an invalid vehicle?


What i'm trying to do is,


/drag works if a player has previously entered a car, when you /drag someone, it puts them in the car you were previously in. What i want is, if someone has not previously entered a car, and a player trys to /drag someone, it displays "get a car please" or something
Reply
#4

That's exactly what I made..

EDIT: Assuming you don't have more than 500 vehicles.

pawn Код:
if(gLastCar[playerid] == INVALID_VEHICLE_ID) {
SendClientMessage(playerid, COLOR_ERROR, "You must have a vehicle before using this command!");
return 1; }
Then replace

pawn Код:
PutPlayerInVehicle(giveplayerid,KidCar[playerid],1);
with..

pawn Код:
PutPlayerInVehicle(giveplayerid,gLastCar[playerid],1);
Reply
#5

I'm getting a warning.


redefinition of constant/macro (symbol "INVALID_VEHICLE_ID")


On

#define INVALID_VEHICLE_ID 500
Reply
#6

Sorry, that means its already defined. Remove that line then.
Reply
#7

Quote:
Originally Posted by Antonio (eternalrp.webatu.com)
Sorry, that means its already defined. Remove that line then.
Ok, I tried the cmd now. After adding what you told me too, and now the command does not put me in a vehicle at all. It just freezes me.


Reply
#8

Nevermind, The command still works like it should, but it does not display


SendClientMessage(playerid, COLOR_ERROR, "You must have a vehicle before using this command!");


If i have not entered a car before.
Reply
#9

Can you show the command you have right now?

EDIT: Add under OnPlayerConnect

pawn Код:
gLastCar[playerid] = INVALID_VEHICLE_ID;
Reply
#10

Quote:
Originally Posted by Antonio (eternalrp.webatu.com)
Can you show the command you have right now?

EDIT: Add under OnPlayerConnect

pawn Код:
gLastCar[playerid] = INVALID_VEHICLE_ID;
I asked someone, and he helped me with it. This is what he said to do.

pawn Код:
if(gLastCar[playerid] == 0) {
    SendClientMessage(playerid, COLOR_ERROR, "You must have a vehicle before using this command!");
    return 1;
    }
and it works great.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)