Comments (7)
It's the first full-match... @maddinat0r you should implement a Levenshtein distance algorithm for matching play names. That would be a great way around this. The same would be great for k.
from sscanf.
Temporarily, I decided to provide @ykosovskyi a solution.
mathMin(inp1,inp2)
return (inp1 > inp2 ? inp2 : inp1);
LevenshteinDistance(strs[], strt[])
{
new n = strlen(strs), m = strlen(strt);
new d[128][128];
if (n == 0)
return m;
if (m == 0)
return n;
for (new i; i <= n; i++)
d[i][0] = i;
for (new j; j <= m; j++)
d[0][j] = j;
for (new j = 1; j <= m; j++)
{
for (new i = 1; i <= n; i++)
{
if (strs[i - 1] == strt[j - 1])
d[i][j] = d[i - 1][j - 1];
else
d[i][j] = mathMin(mathMin(d[i - 1][j] + 1, d[i][j - 1] + 1), d[i - 1][j - 1] + 1);
}
}
return d[n][m];
}
SSCANF:pname(string[])
{
new Iterator:selected<MAX_PLAYERS>;
new distance[MAX_PLAYERS], least = MAX_PLAYER_NAME;
foreach(new i: Player)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(i, name, sizeof(name));
if(strfind(name, string, true) != -1)
{
distance = LevenshteinDistance(string, name);
if(least > distance)
{
Iter_Add(selected, i);
least = distance;
}
}
}
return Iter_Last(selected);
}
As I suggested previously, this uses Levenshtein distance to calculate which player's name matches best. This example uses y_iterate, which vastly simplifies this entire snippet and makes it run pretty darn fast.
In case you don't know how to use "kustom" sscanf params, simply change u
to k<pname>
.
from sscanf.
Thank, @Crayder . I did that. While in the sscanf will not be fixed.
new Array_GetPlayerID[MAX_PLAYERS];
stock GetPlayerIDFromName(name[])
{
new need_len = strlen(name);
new count = 0;
forPlayers(i)
{
if(strlen(PN(i)) == need_len) Array_GetPlayerID[count++] = i;
}
for(new i = 0; i < count; i++)
{
if(!strcmp(name, PN(Array_GetPlayerID[i]), false))
{
return Array_GetPlayerID[i];
}
}
return INVALID_PLAYER_ID;
}
from sscanf.
It's not something that needs "fixed" in my opinion, it works as it should. It returns the first full matching player name. That's why I suggested the distance function separately.
from sscanf.
It would be nice to fix this way:
In the specifier "u" add a check for the length of the input nickname and the one that found, if not the same - continue the search.
from sscanf.
The input can be any length however, so that will not help
from sscanf.
Check the MATCH_NAME_PARTIAL
and CELLMIN_ON_MATCHES
options.
from sscanf.
Related Issues (20)
- Version mess HOT 3
- Unicode symbols? HOT 2
- Small typo
- Problems with "_ALS" error using 2.11.4 HOT 2
- Add open.mp support for sscanf HOT 2
- Using Latest version of sscanf2 HOT 2
- More warnings HOT 1
- Run time error 19: "File or function is not found" HOT 2
- Run time error 19: "File or function is not found" HOT 1
- Error 017: undefined symbol sscanf HOT 1
- fatal error 111 HOT 1
- New, more optimized, bug-free version of sscanf HOT 1
- new version - shit HOT 4
- OMP B11| Version: 2.13.4.0 | It crashes my server while having crashdetect plugin
- String buffer overflow HOT 1
- Is ARM supported?
- Y_Less sscanf problem on ARM processor
- Does not detect sscanf HOT 1
- SetPlayerName problems with sscanf 2.13.8 HOT 4
- Variants problem
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sscanf.