vivi.inc 800 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Common Includes
  2. // www.github.com/sporkyspork
  3. // For Southland RP.
  4. // Made this quickly without really thinking about the best way
  5. // It should truncate a string nicely (whole words) and add trailing elipsis at the end if it was truncated
  6. stock GetTruncatedString(str[])
  7. {
  8. new returnstr[64];
  9. if (strlen(str) < 64)
  10. {
  11. strmid(returnstr, str, 0, 64);
  12. return returnstr;
  13. }
  14. new workingstr[60];
  15. strmid(workingstr, str, 0, sizeof(workingstr));
  16. new lastSpaceAt = 0;
  17. for (new c = 0; c < strlen(workingstr); c ++)
  18. {
  19. if (str[c] == ' ')
  20. {
  21. lastSpaceAt = c;
  22. }
  23. }
  24. if (lastSpaceAt != 0)
  25. {
  26. strmid(returnstr, workingstr, 0, lastSpaceAt);
  27. }
  28. strcat(returnstr, "...");
  29. return returnstr;
  30. }