28.08.2013, 06:24
Hello, I have recently started programming in pawn, and am trying to create a /su command that will search an array of strings (charges), and find the closest match if any. For this, I have used the ReturnUser function from the GF script (though modified), and can't figure out where I'm going wrong.
Here's a little test array I used for testing if this can work or not.
Here's the stock code where I think my problem lies. Keep in mind that this was used to search for partial names before in the GF script, so I haven't removed those comments:
And here is where I'm using that stock code in my actual program:
I am getting the argument mismatch error on "crimeID = ReturnSu(crimSearch);" As far as I can tell, I am passing it a string, which it should accept as an argument.
I use the zcmd format for commands, but from what I understand, the "s" in the sscanf line searches for the first string in the command, and assigns it to crimSearch. If you need any more information, feel free to ask.
Here's a little test array I used for testing if this can work or not.
Код:
new crimeArray[600]={"Reckless Driving", "Vehicular Homicide", "vehicular manslaughter", "vehicular assault", "hit and run", "water eluding", "air eluding"};
Код:
stock ReturnSu(text[], playerid) { new pos = 0; while (text[pos] < 0x21) // Strip out leading spaces { if (text[pos] == 0) return 0; // No passed text pos++; } // They entered [part of] a name or the id search failed (check names just incase) new len = strlen(text[pos]); new count = 0; new crimeID; new crime[MAX_PLAYER_NAME]; for (new i = 0; i < sizeof(crimeArray); i++) { if (strcmp(crimeArray[i], text[pos], true, len) == 0) // Check segment of name { if (len == strlen(text)) // Exact match { return i; // Return the exact player on an exact match } else // Partial match { count++; crimeID = i; } } } if (count != 1) { if (count) { SendClientMessage(playerid, 0xFF0000AA, "Multiple charges found, please narrow search."); } else { SendClientMessage(playerid, 0xFF0000AA, "No matching charge found."); } } return crimeID; // INVALID_PLAYER_ID for bad return }
Код:
COMMAND:su(playerid, params[]) { new crimSearch, crimeID; if(!sscanf(params, "s[64]", crimSearch)) { crimeID = ReturnSu(crimSearch); SCM(playerid, RED, crimeArray[crimeID]); } else SCM(playerid, YELLOW, "Usage: /su (player id/part of name)"); }
I use the zcmd format for commands, but from what I understand, the "s" in the sscanf line searches for the first string in the command, and assigns it to crimSearch. If you need any more information, feel free to ask.