I know MI responded as I was typing this up, but I'm not about to let half an hour go to waste so I'd like to try to explain why the things that are wrong as wrong. Bear with me here, because I'm about to dump a ton of comments on this script and it'll probably be hard to understand unless you reread everything a couple of times and ask questions about what you don't understand. I'm going to add line numbers to make explaining the problems easier.
1 local MachSpeed = false
2 local CurrentSpeed = player.mo.speed
3 local PlayerMachSpeed = player.mo.normalspeed - 5
4 AddHook ("ThinkFrame", do
5 for player in players.iterate
6 if player.mo then --Is player there?
7 if CurrentSpeed > PlayerMachSpeed then --Is speed above the max speed minus 5?
8 MachSpeed = true --Set value true
9 if CurrentSpeed < PlayerMachSpeed then --Is speed below the max speed minus 5?
10 MachSpeed = false --Set value false
11 if CurrentSpeed == PlayerMachSpeed then --Is speed equal to the max speed minus 5?
12 PF_THOK --Make damageable
13 end
14 end
15 end
16 if player.mo and --Is player there?
17 if MachSpeed = true --Is value true?
18 then P_ElementalFireTrail(player) --Spawn a fire trail
19 and PF_GODMODE --Make invincible
20 and local print("88 MPH!") --Print out reference
21 and if P_CheckMeleeRange(actor) = true --Is player in hugging distance?
22 then P_DoPlayerPain(player, source, inflictor) --Knock 'em out!
23 and PF_THOK --Make damageable
24 end
25 end
26 end)
27 end
28 end
Line 1: This technically runs, but you won't be able to support multiple players with this. My suggestion would be to remove this line, and replace any references to MachSpeed with player.mo.MachSpeed.
Lines 2-3: player does not exist yet. You'll get an error trying to access a property of nil. I'd move these inside the ThinkFrame hook's function.
Line 3: player.mo.normalspeed isn't a valid property. Are you thinking of mo.normalspeed? Also, subtracting 5 from a value like mo.normalspeed is the equivalent of subtracting 0.00009 from a floating-point value that would represent similar. (Floating-point values don't exist in SRB2) If you want to subtract five units from the value, you'd subtract 5*FRACUNIT.
Line 4: Lua is case sensitive; AddHook is undefined by default. You want to use addHook. That is, make the A lowercase.
Lines 7, 9 and 11: These if statements aren't closed properly. Every if block needs a matching end. You can either add one after the following statements for each of these, or, since these statements are all mutually exclusive, change the latter two ifs to elseifs to connect them together, and only add the end after the final statement in the whole block. Something like this:
Lines 8, 10, and 12: This is a minor nitpick, but for readability you should always indent one level farther for each nested if/for/etc block.
Line 12: PF_THOK is not a valid statement and makes no sense. If you're trying to set the thokked flag, the statement would look something like player.pflags = $1 | PF_THOKKED, but that wouldn't do what the comment is suggesting. In fact, the conditional right above it (on line 12) is nearly impossible to achieve, since you're asking for a fixed-point value to have an exact match, which means it'll return false on even a 0.000015 difference. The best way to handle making the player undamagable conditionally would be to use a ShouldDamage hook and check the conditions desired.
Line 15: Assuming you added an end to close the if blocks above, you're now left with one too many end statements in this chain. The one right here would close out the entire function, which is unintended judging by the code after this.
Line 16: You've left the for player in players.iterate loop by this point, so player is no longer defined. You'll be accessing a nil value here. However, before you do anything, scroll down to my comments on lines 18-23. (Skip the line 17 comment for now)
Line 17: The if immediately following an and will throw off the interpreter and should be removed. Additionally, = is an assignment operator, not a comparison operator; in other languages this would cause MachSpeed to be set to true and the condition to always pass, but in Lua you get a syntax error. I believe you know about ==, but you could also simply remove the == true part of this statement, since having a conditional statement consist solely of a variable name will pass the condition if the variable is truthy (anything that isn't false, nil or (in SRB2's Lua) 0), and fail if it isn't. Finally, I'd recommend moving the then from the following line up here, for the sake of readability.
Lines 18-23: Considering the conditional checks surrounding this block are also satisfied with the checks on lines 6 and 7, and the latter have no extra conditions that would cause changed behavior, you can move all of these lines to right after line 8 and save some redundant checking. You'd then be left with an empty if statement that you can comment out.
Lines 19-21, and 23: The ands here are syntactically wrong. and is supposed to be used exclusively for comparisons, not to join statements. Simply removing them will fix the issues.
Line 19: Again, a variable by itself is not a valid statement. What you're looking for here is player.pflags = $1 | PF_GODMODE.
20: local should only be used immediately preceding function/variable declarations. Calling print is neither of those, so simply remove the local from this line.
21-23: ??? I'm highly confused by what these are supposed to accomplish. I can tell you they're syntactically incorrect, but no more than that.
27-28: These ends are extraneous and will cause syntax errors. Just remove them.