AleksCore Posted July 4, 2014 Share Posted July 4, 2014 (edited) Привет, комьюнити. Снова нужна ваша помощь. Как можно упростить код такого вида? addEventHandler("onPlayerFinish", getRootElement(), function ( rank ) if rank == 1 then givePlayerMoney(source, 1000) elseif rank == 2 then givePlayerMoney(source, 900) elseif rank == 3 then givePlayerMoney(source, 800) elseif rank == 4 then givePlayerMoney(source, 700) elseif rank == 5 then givePlayerMoney(source, 600) elseif rank == 6 then givePlayerMoney(source, 500) elseif rank == 7 then givePlayerMoney(source, 400) elseif rank == 8 then givePlayerMoney(source, 300) elseif rank == 9 then givePlayerMoney(source, 200) elseif rank == 10 then givePlayerMoney(source, 100) end end ) Покажите, пожалуйста, на примере. Edited July 4, 2014 by Guest Link to comment
lil Toady Posted July 4, 2014 Share Posted July 4, 2014 Математикой: addEventHandler ( "onPlayerFinish", getRootElement(), function ( rank ) if ( rank >= 10 ) then return end givePlayerMoney ( source, 1000 - 100 * ( rank - 1 ) ) end ) Или, если все же хочется хранить, то в таблице: local rewards = { 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100 } addEventHandler ( "onPlayerFinish", getRootElement(), function ( rank ) if ( not rewards[rank] ) then return end givePlayerMoney ( source, rewards[rank] ) end ) Link to comment
AleksCore Posted July 4, 2014 Author Share Posted July 4, 2014 Спасибо! Второй вариант - то, что нужно. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now