Страница 1 из 11
Форум » Программирование в Pawno » Стандартные функции » PreloadAllAnimLibs (Воспроизведение с первого раза анимаций)
PreloadAllAnimLibs
Добавлено 12.05.2016 в 20:14 | Сообщение №1
Сообщений: 263 Репутация: 0
Администраторы
Наверное, многие из вас замечали, что иногда при вызове ApplyAnimation() для игрока она проигрывается не с первого раза. Этот баг можно наблюдать очень часто.
Почему так происходит? Дело в том, что в оперативную память клиента еще не подгружена библиотека с нужной анимацией. При вызове функции из не подгруженной библиотеки искомая библиотека подгружается, при вызове функции второй раз - анимация уже сможет проиграться, так как библиотека подгружена. Это надо исправить.
Код
stock PreloadAnimLib(playerid, animlib[])
{
   ApplyAnimation(playerid,animlib,"null",0.0,0,0,0,0,0);
   return 1;
}

Что мы здесь наблюдаем? Мы, по сути, вызываем анимацию NULL из библиотеки animlib. Так как NULL - это отсутствие анимации, библиотека подгружается, но никаких анимаций не проигрывается.
Теперь, по-хорошему, нужно подгрузить все анимации для игрока. Поскольку библиотек много, рекомендую подключать только часто используемые (полный список можно посмотреть на SA:MP Wiki), но на всякий случай - прилагаю код, где подгружаются ВСЕ библиотеки анимации. Вынесем ее в отдельную функцию, для которой параметром будет ID игрока.

Код
stock PreloadAllAnimLibs (playerid)
{
        PreloadAnimLib(playerid,"AIRPORT");             
        PreloadAnimLib(playerid,"Attractors");          
        PreloadAnimLib(playerid,"BAR");         
        PreloadAnimLib(playerid,"BASEBALL");            
        PreloadAnimLib(playerid,"BD_FIRE");             
        PreloadAnimLib(playerid,"BEACH");               
        PreloadAnimLib(playerid,"benchpress");          
        PreloadAnimLib(playerid,"BF_injection");                
        PreloadAnimLib(playerid,"BIKED");               
        PreloadAnimLib(playerid,"BIKEH");                 
        PreloadAnimLib(playerid,"BIKELEAP");              
        PreloadAnimLib(playerid,"BIKES");                 
        PreloadAnimLib(playerid,"BIKEV");                 
        PreloadAnimLib(playerid,"BIKE_DBZ");              
        PreloadAnimLib(playerid,"BLOWJOBZ");              
        PreloadAnimLib(playerid,"BMX");           
        PreloadAnimLib(playerid,"BOMBER");                
        PreloadAnimLib(playerid,"BOX");           
        PreloadAnimLib(playerid,"BSKTBALL");              
        PreloadAnimLib(playerid,"BUDDY");                 
        PreloadAnimLib(playerid,"BUS");           
        PreloadAnimLib(playerid,"CAMERA");                
        PreloadAnimLib(playerid,"CAR");           
        PreloadAnimLib(playerid,"CARRY");                 
        PreloadAnimLib(playerid,"CAR_CHAT");              
        PreloadAnimLib(playerid,"CASINO");                
        PreloadAnimLib(playerid,"CHAINSAW");              
        PreloadAnimLib(playerid,"CHOPPA");                
        PreloadAnimLib(playerid,"CLOTHES");               
        PreloadAnimLib(playerid,"COACH");                 
        PreloadAnimLib(playerid,"COLT45");                
        PreloadAnimLib(playerid,"COP_AMBIENT");           
        PreloadAnimLib(playerid,"COP_DVBYZ");             
        PreloadAnimLib(playerid,"CRACK");                 
        PreloadAnimLib(playerid,"CRIB");                  
        PreloadAnimLib(playerid,"DAM_JUMP");              
        PreloadAnimLib(playerid,"DANCING");               
        PreloadAnimLib(playerid,"DEALER");                
        PreloadAnimLib(playerid,"DILDO");                 
        PreloadAnimLib(playerid,"DODGE");                 
        PreloadAnimLib(playerid,"DOZER");                 
        PreloadAnimLib(playerid,"DRIVEBYS");              
        PreloadAnimLib(playerid,"FAT");           
        PreloadAnimLib(playerid,"FIGHT_B");               
        PreloadAnimLib(playerid,"FIGHT_C");               
        PreloadAnimLib(playerid,"FIGHT_D");               
        PreloadAnimLib(playerid,"FIGHT_E");               
        PreloadAnimLib(playerid,"FINALE");                
        PreloadAnimLib(playerid,"FINALE2");               
        PreloadAnimLib(playerid,"FLAME");                 
        PreloadAnimLib(playerid,"Flowers");               
        PreloadAnimLib(playerid,"FOOD");                  
        PreloadAnimLib(playerid,"Freeweights");           
        PreloadAnimLib(playerid,"GANGS");                 
        PreloadAnimLib(playerid,"GHANDS");                
        PreloadAnimLib(playerid,"GHETTO_DB");             
        PreloadAnimLib(playerid,"goggles");               
        PreloadAnimLib(playerid,"GRAFFITI");              
        PreloadAnimLib(playerid,"GRAVEYARD");             
        PreloadAnimLib(playerid,"GRENADE");               
        PreloadAnimLib(playerid,"GYMNASIUM");             
        PreloadAnimLib(playerid,"HAIRCUTS");              
        PreloadAnimLib(playerid,"HEIST9");                
        PreloadAnimLib(playerid,"INT_HOUSE");             
        PreloadAnimLib(playerid,"INT_OFFICE");            
        PreloadAnimLib(playerid,"INT_SHOP");              
        PreloadAnimLib(playerid,"JST_BUISNESS");                  
        PreloadAnimLib(playerid,"KART");                  
        PreloadAnimLib(playerid,"KISSING");               
        PreloadAnimLib(playerid,"KNIFE");                 
        PreloadAnimLib(playerid,"LAPDAN1");               
        PreloadAnimLib(playerid,"LAPDAN2");               
        PreloadAnimLib(playerid,"LAPDAN3");               
        PreloadAnimLib(playerid,"LOWRIDER");              
        PreloadAnimLib(playerid,"MD_CHASE");              
        PreloadAnimLib(playerid,"MD_END");                
        PreloadAnimLib(playerid,"MEDIC");                 
        PreloadAnimLib(playerid,"MISC");                  
        PreloadAnimLib(playerid,"MTB");           
        PreloadAnimLib(playerid,"MUSCULAR");              
        PreloadAnimLib(playerid,"NEVADA");                
        PreloadAnimLib(playerid,"ON_LOOKERS");            
        PreloadAnimLib(playerid,"OTB");           
        PreloadAnimLib(playerid,"PARACHUTE");             
        PreloadAnimLib(playerid,"PARK");                  
        PreloadAnimLib(playerid,"PAULNMAC");              
        PreloadAnimLib(playerid,"ped");           
        PreloadAnimLib(playerid,"PLAYER_DVBYS");                  
        PreloadAnimLib(playerid,"PLAYIDLES");             
        PreloadAnimLib(playerid,"POLICE");                
        PreloadAnimLib(playerid,"POOL");                  
        PreloadAnimLib(playerid,"POOR");                  
        PreloadAnimLib(playerid,"PYTHON");                
        PreloadAnimLib(playerid,"QUAD");                  
        PreloadAnimLib(playerid,"QUAD_DBZ");              
        PreloadAnimLib(playerid,"RAPPING");               
        PreloadAnimLib(playerid,"RIFLE");                 
        PreloadAnimLib(playerid,"RIOT");                  
        PreloadAnimLib(playerid,"ROB_BANK");              
        PreloadAnimLib(playerid,"ROCKET");                
        PreloadAnimLib(playerid,"RUSTLER");               
        PreloadAnimLib(playerid,"RYDER");                 
        PreloadAnimLib(playerid,"SCRATCHING");            
        PreloadAnimLib(playerid,"SHAMAL");                
        PreloadAnimLib(playerid,"SHOP");                  
        PreloadAnimLib(playerid,"SHOTGUN");               
        PreloadAnimLib(playerid,"SILENCED");              
        PreloadAnimLib(playerid,"SKATE");                 
        PreloadAnimLib(playerid,"SMOKING");               
        PreloadAnimLib(playerid,"SNIPER");                
        PreloadAnimLib(playerid,"SPRAYCAN");              
        PreloadAnimLib(playerid,"STRIP");                 
        PreloadAnimLib(playerid,"SUNBATHE");              
        PreloadAnimLib(playerid,"SWAT");                  
        PreloadAnimLib(playerid,"SWEET");                 
        PreloadAnimLib(playerid,"SWIM");                  
        PreloadAnimLib(playerid,"SWORD");                 
        PreloadAnimLib(playerid,"TANK");                  
        PreloadAnimLib(playerid,"TATTOOS");               
        PreloadAnimLib(playerid,"TEC");           
        PreloadAnimLib(playerid,"TRAIN");                 
        PreloadAnimLib(playerid,"TRUCK");                 
        PreloadAnimLib(playerid,"UZI");           
        PreloadAnimLib(playerid,"VAN");           
        PreloadAnimLib(playerid,"VENDING");               
        PreloadAnimLib(playerid,"VORTEX");                
        PreloadAnimLib(playerid,"WAYFARER");              
        PreloadAnimLib(playerid,"WEAPONS");               
        PreloadAnimLib(playerid,"WUZI");                  
   return 1;
}

Теперь в паблике OnPlayerSpawn достаточно вызвать функцию PreloadAllAnimLibs(playerid), чтобы все библиотеки подгрузились и анимация работала с первого раза и без перебоев.

Что делать с данными функциями - Ваше дело. Можно устанавливать проверку на то, подгружены ли анимации, можно подгружать библиотеки по необходимости. Я лишь даю основу для размышлений.

Автор: Неизвестен


Программист любитель :)
Форум » Программирование в Pawno » Стандартные функции » PreloadAllAnimLibs (Воспроизведение с первого раза анимаций)
Страница 1 из 11
Поиск: