28.04.2018, 00:57
I'm trying to improve the ease at which a player's name can be used in a command (for example /wave TestDucati). The problem is that the method I'm currently using is not very efficient, currently the server will only correctly identify the player I'm aiming the command toward if I include the first part of their name, if that makes any sense.
For example:
/wave TestDucati = works
/wave TestDu = works (if nobody else online has a name starting with TestDu)
/wave T = works (if nobody else online has a name starting with T)
/wave Ducati = Doesn't work (returns invalid command) as the identifier doesn't have the beginning of the username
This might not sound like much of a problem but with a growing server I am beginning to get players who share similar (or the same) words at the start of their names.
For example two players named TestJon and TestMike.
The command "/wave Test" returns an Invalid command as there are multiple usernames starting with the word Test. This means that to /wave one of them I need to type either the entire name or the name up until the unique character (/wave TestJ) which is very annoying due to /wave Jon or /wave Mike not correctly identifying the player I am trying to wave at
How easy would it be to adjust my commands to identify the player more efficiently?
(I'm aware of not needing to type an ID in the "wave" example, due to it finding the nearest player, but this is mainly a problem with commands like /info and /stats)
An example of one of the commands which I need to improve:
For example:
/wave TestDucati = works
/wave TestDu = works (if nobody else online has a name starting with TestDu)
/wave T = works (if nobody else online has a name starting with T)
/wave Ducati = Doesn't work (returns invalid command) as the identifier doesn't have the beginning of the username
This might not sound like much of a problem but with a growing server I am beginning to get players who share similar (or the same) words at the start of their names.
For example two players named TestJon and TestMike.
The command "/wave Test" returns an Invalid command as there are multiple usernames starting with the word Test. This means that to /wave one of them I need to type either the entire name or the name up until the unique character (/wave TestJ) which is very annoying due to /wave Jon or /wave Mike not correctly identifying the player I am trying to wave at
How easy would it be to adjust my commands to identify the player more efficiently?
(I'm aware of not needing to type an ID in the "wave" example, due to it finding the nearest player, but this is mainly a problem with commands like /info and /stats)
An example of one of the commands which I need to improve:
Код:
COMMAND:wave(playerid, params[]) { if (PlayerInfo[playerid][pSpawned] == 1) { new idx,TargetID,string[256],tmp[256]; if(PlayerInfo[playerid][pWaveTime] > 0) { SendClientMessage(playerid,COLOR_ERROR,"Please Wait Before Using This Command Again."); return 1; } tmp = strtok(params, idx); if (!strlen(tmp)) { TargetID = GetClosestPlayer(playerid); if (TargetID == INVALID_PLAYER_ID) { SendClientMessage(playerid, COLOR_ERROR, "No Players Close Enough To Wave At."); return 1; } }else{ if (!isNumeric(tmp)) { TargetID = ReturnUser(tmp, playerid); if (TargetID == INVALID_PLAYER_ID) { return 1; } } else { TargetID = strval(tmp); if (!IsPlayerConnected(TargetID)) { format(string, sizeof(string), "%d Is Not A Valid ID.", TargetID); SendClientMessage(playerid, COLOR_ERROR, string); return 1; } } } if (TargetID == playerid) { SendClientMessage(playerid, COLOR_ERROR, "You Cannot Wave At Yourself."); return 1; } if (GetDistanceBetweenPlayers(playerid,TargetID) > 9) { format(string, sizeof(string), "%s (%d) Is Not Close Enough. You Cannot Wave At %s.",PlayerInfo[TargetID][pName],TargetID, ObjectGenderPronouns[PlayerInfo[TargetID][pGender]]); SendClientMessage(playerid, COLOR_ERROR, string); return 1; } if (GetPlayerVirtualWorld(playerid) != GetPlayerVirtualWorld(TargetID)) { format(string, sizeof(string), "%s (%d) Is Not Close Enough. You Cannot Wave At %s.",PlayerInfo[TargetID][pName],TargetID, ObjectGenderPronouns[PlayerInfo[TargetID][pGender]]); SendClientMessage(playerid, COLOR_ERROR, string); return 1; } if (GetPlayerState(TargetID) == PLAYER_STATE_WASTED) { format(string, sizeof(string), "%s (%d) Waves at %s (%d)'s Corpse.",PlayerInfo[playerid][pName],playerid,PlayerInfo[TargetID][pName],TargetID); SendClientMessageToAll(GetPlayerColor(playerid), string); PlayerInfo[playerid][pWaveTime] = 10; }else{ format(string, sizeof(string), "%s (%d) Waves at %s (%d).",PlayerInfo[playerid][pName],playerid,PlayerInfo[TargetID][pName],TargetID); SendClientMessageToAll(GetPlayerColor(playerid), string); PlayerInfo[playerid][pWaveTime] = 10; } if (!IsPlayerInAnyVehicle(playerid)) { ApplyAnimation(playerid, "ON_LOOKERS", "wave_loop", 3.0, 0, 0, 0, 0, 0, 1); } } else { SendClientMessage(playerid, COLOR_ERROR, "You Cannot Use This Command When You're Dead."); } return 1; }