function strfind() does NOT work
#1

So I've made this little function, which was supposed to return a simplified name of the weatherID (https://sampwiki.blast.hk/wiki/WeatherID).
PHP код:
new const _weathers[][] = {
    
"EXTRASUNNY_LA",
    
"SUNNY_LA",
    
"EXTRASUNNY_SMOG_LA",
    
"SUNNY_SMOG_LA",
    
"CLOUDY_LA",
    
"SUNNY_SF",
    
"EXTRASUNNY_SF",
    
"CLOUDY_SF",
    
"RAINY_SF",
    
"FOGGY_SF",
    
"SUNNY_VEGAS",
    
"EXTRASUNNY_VEGAS",
    
"CLOUDY_VEGAS",
    
"EXTRASUNNY_COUNTRYSIDE",
    
"SUNNY_COUNTRYSIDE",
    
"CLOUDY_COUNTRYSIDE",
    
"RAINY_COUNTRYSIDE",
    
"EXTRASUNNY_DESERT",
    
"SUNNY_DESERT"
};
stock GetWeatherSimplifiedNameFromID(weatherid) {
    new 
weathername[30];
    
weathername GetWeatherNameFromID(weatherid);
    new 
string[20];
    if (
strfind(weathername"SUNNY"true) != -1) {
        
string "Sunny";
        return 
string;
    }
    if (
strfind(weathername"ClOUDY"true) != -1) {
        
string "Cloudy";
        return 
string;
    }
    if (
strfind(weathername"RAINY"true) != -1) {
        
string "Rainy";
        return 
string;
    }
    if (
strfind(weathername"FOGGY"true) != -1) {
        
string "Foggy";
        return 
string;
    }
    else 
string "Unidentified";
    return 
string;

The function 'GetWeatherNameFromID()' returns the weather from the '_weathers' array and works perfectly fine (tested).

The problems:
  • The weathers that starts with 'SUNNY' returns 'Foggy'.
  • The weathers that starts with 'CLOUDY' returns 'Sunny'.
  • The weathers that starts with 'RAINY' returns 'Sunny'.
  • The weathers that starts with 'FOGGY' returns 'Sunny'.
NOTE: The weathers that starts with 'EXTRASUNNY' returns 'Sunny' as it should.

I've also considered to use `strcmp` (checking the first characters of the weather) instead of `strfind()`.

Any help/example/tutorial would be helpful.
Reply


Messages In This Thread
function strfind() does NOT work - by CeSuX - 22.03.2017, 13:46
Re: function strfind() does NOT work - by LetsOWN[PL] - 22.03.2017, 14:38

Forum Jump:


Users browsing this thread: 1 Guest(s)