Quote:
Originally Posted by Saorp
Код:
//--------------------[BlindFold]------------------------------------------------------------------------
if(strcmp(cmd, "/blindfold", true) == 0)
{
if(IsPlayerConnected(playerid))
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD1, "USAGE: //blindfold [player name]");
return 1;
}
SetPlayerCameraPos(playerid, -833.5241,-1358.8575,86.9054);
SetPlayerCameraLookAt(playerid, -830.8118,-1360.3612,87.0289);
return 1;
}
if(strcmp(cmd, "/unblindfold", true) == 0)
{
if(IsPlayerConnected(playerid))
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD1, "USAGE: //unblindfold [player name]");
return 1;
}
SetCameraBehindPlayer(playerid);
return 1;
}
|
Firstly, you are performing an unnecessary check, seeing if playerid is connected. If he/she just typed a command, of course they are connected. Secondly, your check doesn't act how you would like. If you do not place braces after the 'if()', it will only take the first single statement: "tmp = strtok(cmdtext, idx);"
Try this:
[pawn]
// Using
pawn Код:
tags!
if(strcmp(cmd, "/blindfold", true) == 0) // '/blindfold'
{
tmp = strtok(cmdtext, idx); // Making 'tmp' hold the id. Remains as a string.
if(!strlen(tmp)) // If the length of 'tmp' is 0:
return SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /blindfold [player id]"); // Send the message AND end the command here (thus avoiding the 'SERVER: Unknown command.' message).
new id = strval(tmp); // New integer which holds the value of 'tmp'. EG: /blindfold 6. 'id' would become 6.
if(IsPlayerConnected(id)) // If the id is connected:
{ // We are using more than a single statement, so we use braces.
SetPlayerCameraPos(id, -833.5241,-1358.8575,86.9054); // Setting the camera position for 'id'.
return SetPlayerCameraLookAt(id, -830.8118,-1360.3612,87.0289); // Setting the camera to look at X for 'id' AND end the command here (thus avoiding the 'SERVER: Unknown command.' message).
} // Closing brace for the id check.
}
if(strcmp(cmd, "/unblindfold", true) == 0) // '/unblindfold'
{
tmp = strtok(cmdtext, idx); // Making 'tmp' hold the id. Remains as a string.
if(!strlen(tmp)) // If the length of 'tmp' is 0:
return SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /unblindfold [player id]"); // Send the message AND end the command here (thus avoiding the 'SERVER: Unknown command.' message).
new id = strval(tmp); // New integer which holds the value of 'tmp'. EG: /blindfold 6. 'id' would become 6.
if(IsPlayerConnected(id)) // If the id is connected:
return SetCameraBehindPlayer(id); // Set the camera of 'id' behind them, as well as ending the command.
return 1; // If the id was not connected, add an else statement here. This will just stop the 'SERVER: Unknown command.' message.
}
This will work, and if you are still wanting names to work (EG: /blindfold Cueball), head on over to the Useful Functions topic (
search for it), and then search for a name checker (EG: GetPlayerID() ). Then simply assign 'id' to the function:
pawn Код:
new id = GetPlayerID(tmp);
This should do the trick
~Cueball~