Code: Show/Hide signed int temp6 = 0; sscanf(c->final, "%d", &temp6); |
Code: Show/Hide void whatever(int greennum, string playername) ... //sendPrivate(playername,"*prize #" + (String)greennum); <--didnt work, not p sendPublic("priv green"); _listnode <Player> *parse = playerlist->head; while (parse) { Player *p = parse->item; if (p->name==playername) { sendPrivate(p,"*prize #" + (String)greennum); sendPrivate(p,"green pm"); sendPublic("priv green sent"); } parse = parse->next; } |
Code: Show/Hide Player* FindPlayerByName(char *name, bool exactmatch, _linkedlist <Player>* list) { _listnode <Player> *parse = list->head; //set to first link of the player linked list Player* bestmatchplayer = NULL; int bestmatchlength = 0; String nametofind = name; nametofind.lcase(); while (parse) //parse will be NULL when we reach the last link { Player *p = parse->item; //item is the actual data stored in the link String pname = (String) p->name; pname.lcase(); if (pname == nametofind) return p; if (!exactmatch) { int firstdifferent = FirstDifferentCharacter(nametofind, pname); if (bestmatchlength < firstdifferent) { bestmatchlength = firstdifferent; bestmatchplayer = p; } } parse = parse->next; //set parse to the next link } return bestmatchplayer; } |
Code: Show/Hide void whatever(int greennum, String playername) { //Find the target player; use 'true' as 2nd parameter if you don't want partial matches (i.e. "sam" can return the player "Samapico") Player * target = FindPlayerByName(playername, false, playerlist); if (target != NULL) { sendPrivate(target, "*prize #" + String(greennum)); } } |
Cheese wrote: |
but where is FirstDifferentCharacter()? =S |
Code: Show/Hide int FirstDifferentCharacter(const char *string1, const char *string2) { int i; for (i = 0 ; *string1 != '\0' && *string2 != '\0' && tolower(*string1) == tolower(*string2) ; i++, string1++, string2++) { } return i; } |