You have to set the max_entities variable _before_ calling load_level() in your script.