View Single Post
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-04-2007 , 05:09   Re: [REQ] Automatic precaching (speech.ini)
#7

amx2006.3 miscstats.sma
Code:
public plugin_precache() {
  new filename[64]
  build_path(filename, 63, "$configdir/stats.ini")
  if(file_exists(filename)) {
    new text[256], name[32]
    new len, pos = 0, xid
    while((pos = read_file(filename, pos, text, 255, len))) {
      if(text[0] == ';' || !len) continue // line is a comment
      parse(text, name, 31)
      if((xid = get_xvar_id(name)) != -1)
        set_xvar_num(xid, 1)
    }
  }
#if defined AUTOMATIC_PRECACHING
  if(MultiKillSound || KillingStreakSound) {
    for(new i = 0; i < 7; i++)
      precache_sound_custom(g_Sounds[i])
  }
  if(BombPlantedSound) {
    precache_sound_custom("djeyl/c4powa")
  }
  if(BombDefusedSound) {
    precache_sound_custom("djeyl/laugh")
  }
  if(BombFailedSound || GrenadeSuicideSound) {
    precache_sound_custom("djeyl/witch")
  }
  if(LastManSound) {
    precache_sound_custom("misc/maytheforce")
    precache_sound_custom("misc/oneandonly")
  }
  if(KnifeKillSound) {
    precache_sound_custom("misc/humiliation")
  }
  if(GrenadeKillSound) {
    precache_sound_custom("djeyl/grenade")
  }
  if(HeadShotKillSound) {
    precache_sound_custom("misc/headshot")
  }
  if(RoundCounterSound) {
    precache_sound_custom("misc/prepare")
  }
  if(DoubleKillSound) {
    precache_sound_custom("misc/doublekill")
  }
  if(FirstBloodSound) {
    precache_sound_custom("misc/firstblood")
  }
#endif
}

#if defined AUTOMATIC_PRECACHING
new g_precSoundCust[64]
public precache_sound_custom(sound[]) {
  format(g_precSoundCust, 63, "sound/%s.wav", sound)
  if(file_exists(g_precSoundCust)) {
    replace(g_precSoundCust, 63, "sound/", "")
    precache_sound(g_precSoundCust)
  }
}
#endif
amx2006.3 cmdmenu.sma :
Code:
#if defined AUTOMATIC_PRECACHING
public plugin_precache() {
  new szFilename[64]
  build_path(szFilename, 63, "$configdir/speech.ini")
  if(!file_exists(szFilename))
    return 0

  new text[256], szName[32], szSound[128], szFlags[32], szAccess[32]
  new num = 0, a, pos = 0
  new ext[5]
  new arg1[32], arg2[64], arg3[64]
  
  while(num < MAX_CMDS && (pos = read_file(szFilename, pos, text, 255, a))) {
    if(!a || text[0] == ';' || text[0] == '/') continue

    if(parse(text, szName, 31, szSound, 127, szFlags, 31, szAccess, 31) > 3) {
      new parsedNums = parse(szSound, arg1, 31, arg2, 63, arg3, 63)
      if(parsedNums == 2 && equali(arg1, "spk")) {
        copy(szSound, 127, arg2)
        copy(ext, 4, ".wav")
      }
      else if(parsedNums == 3 && equali(arg1, "mp3") && (equali(arg2, "play") || equali(arg2, "loop"))) {
        copy(szSound, 127, arg3)
        copy(ext, 4, ".mp3")
      }
      else continue

      replace_all(szSound, 127, "\'", "")

      if(szSound[0] == '/') replace(szSound, 127, "/", "")

      if(ext[1] == 'm' || (!equali(szSound, "vox", 3) && !equali(szSound, "barney", 6) && !equali(szSound, "hgrunt", 6))) {
        new len = strlen(szSound)
        if(len > 3 && !equali(szSound[len-4], ext)) add(szSound, 127, ext)
        if(ext[1] == 'w') format(szSound, 127, "sound/%s", szSound)
        if(file_exists(szSound)) {
          if(ext[1] == 'm') {
            precache_generic(szSound)
          }
          else {
            replace(szSound, 127, "sound/", "")
            precache_sound(szSound)
          }
        }
      }
      num++
    }
  }
  return 0
}
#endif
That's exactly what we want, let the #define commented by defaut if you think it's better ;)
ConnorMcLeod is offline