Get Closest Criminal // Taze // MMB
#1

How do i do it i want it so like when i click MMB it tazes the nearest player here is the taze comamnd

Quote:

if(strcmp(cmd, "/taze", true) == 0) {
if(IsSpawned[playerid] == 0) {
SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
return 1;
}
if(gTeam[playerid] >= 3) {
SendClientMessage(playerid, COLOR_ERROR, "Only Law Enforcement 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;
}
if(Jailed[playerid] == 1) {
SendClientMessage(playerid, COLOR_ERROR, "You cannot use this command in jail");
return 1;
}
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_ERROR, "USAGE: /taze (id)");
return 1;
}
giveplayerid = strval(tmp);
if(!IsNumeric(tmp)) {
SendClientMessage(playerid, COLOR_ERROR, "USAGE: /taze (id) ID Must be a number");
return 1;
}
if(!IsPlayerConnected(giveplayerid)) {
format(string, sizeof(string), "ID (%d) Is not an active player", giveplayerid);
SendClientMessage(playerid, COLOR_ERROR, string);
return 1;
}
if(gTeam[giveplayerid] <= 2) {
SendClientMessage(playerid, COLOR_ERROR, "You cannot taze another Law Enforcement agent");
return 1;
}
new oname[24];
new pname[24];
GetPlayerName(playerid,oname, 24);
GetPlayerName(giveplayerid, pname, 24);
if(GetPlayerWantedLevel(giveplayerid) <= 3) {
format(string, sizeof(string), "%s(%d) Does not have a warrant. You cannot use your tazer on this player",pname,giveplayerid);
SendClientMessage(playerid, COLOR_ERROR, string);
return 1;
}
if(GetDistanceBetweenPlayers(playerid,giveplayerid ) > 15) {
format(string, sizeof(string), "%s(%d) Is not close enough to taze",pname,giveplayerid);
SendClientMessage(playerid, COLOR_ERROR, string);
return 1;
}
if(cuffed[giveplayerid] == 1) {
format(string, sizeof(string), "%s(%d) Is in handcuffs and is restrained. You cannot taze a handcuffed player",pname, giveplayerid);
SendClientMessage(playerid, COLOR_ERROR, string);
return 1;
}
if(IsPlayerInAnyVehicle(giveplayerid)) {
format(string, sizeof(string), "%s(%d) Is in a vehicle. Get the player out the vehicle then use your tazer",pname,giveplayerid);
SendClientMessage(playerid, COLOR_ERROR, string);
return 1;
}
if(IsPlayerInAnyVehicle(playerid)) {
SendClientMessage(playerid, COLOR_ERROR, "You cannot taze a player from inside a vehicle");
return 1;
}
if(Tazed[giveplayerid] == 1) {
format(string, sizeof(string), "%s(%d) Is being tazed right now. You cannot taze a player while the player is being tazed",pname,giveplayerid);
SendClientMessage(playerid, COLOR_ERROR, string);
}
else{

Tazed[giveplayerid] =1;
new tazername[30];
GetPlayerName(playerid,tazername,30);
format(string, sizeof(string), "Law Enforcement agent %s(%d) Has tazed suspect %s(%d)",tazername,playerid,pname,giveplayerid);
SendClientMessageToAll(0x00C7FFAA, string);
SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Law Enforcement Action_|");
format(string, sizeof(string), "Officer %s(%d) Has tazed you", oname,playerid);
SendClientMessage(giveplayerid,COLOR_DODGERBLUE, string);
ApplyAnimation(giveplayerid,"PED","BIKE_fall_off", 4.1,0,1,1,1,1);
SetTimer("Tazingtime",3000,0);
}
return 1;
}

Thanks can you tell me how to do it ty
Reply
#2

Okay, since i dont know the keystoke names, ill tell you a step by step process.

1. In a local server, add to your script under the OnPlayerKeyStateChange add in the following code:
pawn Код:
printf("NewKeys:%d OldKeys:%d Playerid:%d",newkeys,oldkeys,playerid);
2. Compile it. For best results, put it at the top of the function.
3. Start a local server, and join it. Go in and spawn. Do not do anything else but spawn.
4. After spawning, press the MMB and release. Alt Tab to desktop and look at the server output.
5. Look at the Messages printed. Newkeys on the first output is the MMB key number you need.
6. Go back to the script, and copy the Command /taze, without the command brackets.. You should get this:
pawn Код:
if(IsSpawned[playerid] == 0) {
  SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
   return 1;
   }
  if(gTeam[playerid] >= 3) {
  SendClientMessage(playerid, COLOR_ERROR, "Only Law Enforcement 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;
   }
  if(Jailed[playerid] == 1) {
  SendClientMessage(playerid, COLOR_ERROR, "You cannot use this command in jail");
   return 1;
   }
  tmp = strtok(cmdtext, idx);
   if(!strlen(tmp)) {
   SendClientMessage(playerid, COLOR_ERROR, "USAGE: /taze (id)");
   return 1;
   }
   giveplayerid = strval(tmp);
   if(!IsNumeric(tmp)) {
   SendClientMessage(playerid, COLOR_ERROR, "USAGE: /taze (id) ID Must be a number");
   return 1;
   }
   if(!IsPlayerConnected(giveplayerid)) {
   format(string, sizeof(string), "ID (%d) Is not an active player", giveplayerid);
   SendClientMessage(playerid, COLOR_ERROR, string);
   return 1;
   }
   if(gTeam[giveplayerid] <= 2) {
   SendClientMessage(playerid, COLOR_ERROR, "You cannot taze another Law Enforcement agent");
   return 1;
   }
   new oname[24];
   new pname[24];
   GetPlayerName(playerid,oname, 24);
   GetPlayerName(giveplayerid, pname, 24);
   if(GetPlayerWantedLevel(giveplayerid) <= 3) {
  format(string, sizeof(string), "%s(%d) Does not have a warrant. You cannot use your tazer on this player",pname,giveplayerid);
   SendClientMessage(playerid, COLOR_ERROR, string);
   return 1;
   }
   if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 15) {
   format(string, sizeof(string), "%s(%d) Is not close enough to taze",pname,giveplayerid);
   SendClientMessage(playerid, COLOR_ERROR, string);
   return 1;
   }
   if(cuffed[giveplayerid] == 1) {
   format(string, sizeof(string), "%s(%d) Is in handcuffs and is restrained. You cannot taze a handcuffed player",pname, giveplayerid);
   SendClientMessage(playerid, COLOR_ERROR, string);
   return 1;
   }
   if(IsPlayerInAnyVehicle(giveplayerid)) {
   format(string, sizeof(string), "%s(%d) Is in a vehicle. Get the player out the vehicle then use your tazer",pname,giveplayerid);
   SendClientMessage(playerid, COLOR_ERROR, string);
   return 1;
   }
  if(IsPlayerInAnyVehicle(playerid)) {
  SendClientMessage(playerid, COLOR_ERROR, "You cannot taze a player from inside a vehicle");
   return 1;
   }
  if(Tazed[giveplayerid] == 1) {
  format(string, sizeof(string), "%s(%d) Is being tazed right now. You cannot taze a player while the player is being tazed",pname,giveplayerid);
   SendClientMessage(playerid, COLOR_ERROR, string);
  }
  else{
 
   Tazed[giveplayerid] =1;
   new tazername[30];
   GetPlayerName(playerid,tazername,30);
   format(string, sizeof(string), "Law Enforcement agent %s(%d) Has tazed suspect %s(%d)",tazername,playerid,pname,giveplayerid);
   SendClientMessageToAll(0x00C7FFAA, string);
   SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Law Enforcement Action_|");
   format(string, sizeof(string), "Officer %s(%d) Has tazed you", oname,playerid);
   SendClientMessage(giveplayerid,COLOR_DODGERBLUE, string);
   ApplyAnimation(giveplayerid,"PED","BIKE_fall_off",4.1,0,1,1,1,1);
   SetTimer("Tazingtime",3000,0);
   }
7. Go to OnPlayerKeyStateChange and make a if statement checking if newkeys == the number you got from the server print out. Be sure to make the open and close brackets.
8. Take the code you copied from the command and paste it in between the brackets.
9. This should produce a working taze keystroke, but a timer is highly recommended. Otherwise it may be over clicked causing Server lag, Crashing, or possibly tazing forever.

Hope that helped some.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)