'Sup
*"Straight outta end statements" intensifies*
I didn't read the quest that much because I should sleep, but what I can notice is the large amount of "end" statements. To be sure, you must put an "end" to close the statement each time you put something like "when, if, for or while", but not for something like "else".
I suggest you to use tabs (for your eyes, it's better looking, plus it's easiest to modify, otherwise, lua doesn't give a flying damn about tabs, contrary to python, so you should be fine) and close the statements once you open it.
You must also add a close statement for "quest x begin" "state x begin" "when x begin".
By the way - excuse me I'm tired it's 01:01 AM so it's maybe me, but I don't think so - your quest won't work because the if and elseif seem to be misused.
I think it'd be better to ask here or at least explain what you wanted to do, then someone will help you or even create the quest for you, then you'd be able to know where you failed in order not to reproduce the same error again !
Good night (because you're polish so it's night too) !