You can buy a long gun from a DEALER in any state, provided both the state's laws and IL law permit this.
You cannot buy a handgun in other than your state of residence.
For military, only PCS orders establish you as a resident of the state in which you're stationed, not TDY.
So, if your permanent state of residence (home of record, whatever) is FL, and you're stationed permanently in IL, you could buy a handgun in FL on your FL ID, or in IL with a copy of your PCS orders, but not in any other state.
Being a student in a state other than your home of record also establishes you as a resident of the school state, provided you reside there instead of commuting from your permanent home, and only for the time period in which you're actually in residence at the school.
Lastly, if you have a vacation home or property in a state other than your home of record, you can be considered a resident of the other state during the time period where you're actually residing at your vacation home or on property.