A bit of a problem...

Status
Not open for further replies.

Snu

YEAAHHHHHHHHH
Hey, I kinda ran into a Lua error while testing out this Lua file I made that restricts Knuckles from being played in Coop or Race.

Here's what is in the Lua file: http://pastebin.com/z14HqJTA

and here is the error I get: WARNING: ./Editing Stuff/Lua/NoKnux.lua:4: unexpected symbol near 'if'

Could anyone assist me in what I am doing wrong?
Thanks
 
Just wondering -As I suck in Lua-, but aren't you supposed to replace the "and if" (At line 4) by "and" (without quotes?) Sorry if my awnser didn't help you at all...
 
Yes, he is supposed to do that. And he should supply a map header number for use with the mapheader table. Even then, it checks for the supported gametype, and there he also only checks for if it's only co-op or only race. And he's trying to check for variable numbers within the same variable using an "or". Also, I doubt setting the state to PST_DEAD has any effect on its own, but I may be wrong. I very highly doubt it'll kill the player, at least. And even then, one would keep dying and dying and dying unless one changes skin by oneself. And ThinkFrame should be avoided if possible. And for what reason does/will it return nil? Also, nothing really stops the hook.
Code:
//Stop Knux in Co-op, and Race gametypes
addHook("MobjThinker", function()
        for player in players.iterate
                if (gametype == TOL_COOP or gametype == TOL_RACE)
                and player.mo and player.mo.skin == "knuckles"
                        R_SetPlayerSkin(player, "sonic")
                        print(player.name+" tried to use Knux and has been changed to Sanic")
                end
        end
end
, MT_PLAYER)
The code I supplied (I'm sorry) simply changes the skin from Knuckles to Sonic, and prints out "[player name] tried to use Knux and has been changed to Sanic". (Credit not necessary at all.)
 
Yes, he is supposed to do that. And he should supply a map header number for use with the mapheader table. Even then, it checks for the supported gametype, and there he also only checks for if it's only co-op or only race. And he's trying to check for variable numbers within the same variable using an "or". Also, I doubt setting the state to PST_DEAD has any effect on its own, but I may be wrong. I very highly doubt it'll kill the player, at least. And even then, one would keep dying and dying and dying unless one changes skin by oneself. And ThinkFrame should be avoided if possible. And for what reason does/will it return nil? Also, nothing really stops the hook.
Code:
//Stop Knux in Co-op, and Race gametypes
addHook("MobjThinker", function()
        for player in players.iterate
                if (gametype == TOL_COOP or gametype == TOL_RACE)
                and player.mo and player.mo.skin == "knuckles"
                        R_SetPlayerSkin(player, "sonic")
                        print(player.name+" tried to use Knux and has been changed to Sanic")
                end
        end
end
, MT_PLAYER)
The code I supplied (I'm sorry) simply changes the skin from Knuckles to Sonic, and prints out "[player name] tried to use Knux and has been changed to Sanic". (Credit not necessary at all.)

Thanks for trying to help, but the script doesn't even do anything.
Thanks anyway. ;)
 
This should work:
Code:
addHook("ThinkFrame", do
    for player in players.iterate // Load the player iterate
        if G_PlatformGametype() // Checks if it's a platforming gametype (Coop or race)
        and (player.mo.skin=="knuckles") // Checks for Knuckles
        and not (player.mo.state==S_PLAY_DIE) // Checks if the player is already dead so he doesn't die 9001 times
            print(player.name+" tried to use Knuckles and died.") // Just player.name is good enough
            P_KillMobj(player.mo) // Kill the player
        end // Close 'if'
    end // Close 'for'
end) // Close addHook. Remember to close addHook's parenthesis as well!
From what I could see in your original code, you didn't close the addHook's parenthesis at the last end. You also used and if, which is incorrect. Just use and. You didn't need that return, either. I'm not sure what the mapheader is; I don't think that exists.
 
This should work:
Code:
addHook("ThinkFrame", do
    for player in players.iterate // Load the player iterate
        if G_PlatformGametype() // Checks if it's a platforming gametype (Coop or race)
        and (player.mo.skin=="knuckles") // Checks for Knuckles
        and not (player.mo.state==S_PLAY_DIE) // Checks if the player is already dead so he doesn't die 9001 times
            print(player.name+" tried to use Knuckles and died.") // Just player.name is good enough
            P_KillMobj(player.mo) // Kill the player
        end // Close 'if'
    end // Close 'for'
end) // Close addHook. Remember to close addHook's parenthesis as well!
From what I could see in your original code, you didn't close the addHook's parenthesis at the last end. You also used and if, which is incorrect. Just use and. You didn't need that return, either. I'm not sure what the mapheader is; I don't think that exists.

This works!
But is there a way to make competition and single player a exception?
 
This works!
But is there a way to make competition and single player a exception?
I can't test it right now, but making if into if not should work.

EDIT: Oops, misunderstood. Nevermind that. Lemme look into it.

EDIT 2: I'm at school at the moment now, so it's sorta difficult to help when I'm not at my PC. Anyone else is free to help out.
 
Last edited:
go ahead and try this code. it should just affect race and coop like it it was originally intended to.
Code:
addHook("MobjThinker", function()
      for player in players.iterate
            if (gametype == TOL_COOP or gametype == TOL_RACE)
                  if player.mo and player.mo.skin == "knuckles"
                        R_SetPlayerSkin(player, "sonic")
                        print(player.name+" tried to use Knux and has been changed to Sanic")
                  end
            end
      end
end)
 
Well, we ended up fixing it in the IRC, thx for everyone that helped!

*Hugs all that helped*
 
go ahead and try this code. it should just affect race and coop like it it was originally intended to.
Code:
addHook("MobjThinker", function()
      for player in players.iterate
            if (gametype == TOL_COOP or gametype == TOL_RACE)
                  if player.mo and player.mo.skin == "knuckles"
                        R_SetPlayerSkin(player, "sonic")
                        print(player.name+" tried to use Knux and has been changed to Sanic")
                  end
            end
      end
end)
No, that's wrong. Gametype must use GT_ constants, which you aren't using, and won't work for his purposes.

I think this should work (took forever to do mobile, lol):

Code:
addHook("ThinkFrame", do
    for player in players.iterate // Load the player iterate
        if (maptol(TOL_COOP) or maptol(TOL_RACE)) // Check if it's Coop or Race
 
        and (player.mo.skin=="knuckles") // Checks for Knuckles
        and not (player.mo.state==S_PLAY_DIE) // Checks if the player is already dead so he doesn't die 9001 times
            print(player.name+" tried to use Knuckles and died.") // Just player.name is good enough
            P_KillMobj(player.mo) // Kill the player
        end // Close 'if'
    end // Close 'for'
EDIT: Hooray for being ninja'd! Good thing you got it figured out.

EDIT 2: Fixed a slight error, even though the issue has already been resolved

EDIT 3: It doesn't work, ignore me.
 
Last edited:
How do you use the TOL_ constants then?
As Monster Iestyn said, "maptol" isn't a function, but he left out it's a variable, like "gametype". "if maptol==TOL_COOP". I'm a bit surprised my thing didn't work, though.
MessageOfTheDaySpark, why would the script you supplied work if mine wouldn't? Yours is the exact same, just without being restricted to player objects only.
And Sky, what's the point of checking a variable of player.mo before checking if that object even exists? I'm not sure, but that might cause the hook to be removed in-game if any player is a spectator.

Anyway, Snow got it working, everyone's happy, except me since my Lua skills apparently suck off the top of my head.
 
Last edited:
Code:
addHook("MobjThinker", function(mobj)
    local player = mobj.player
    if ((gametype == GT_COOP) or (gametype == GT_RACE))
    and ((player.mo) and (player.mo.skin == "knuckles")) then
        R_SetPlayerSkin(player, "sonic")
    end
end, MT_PLAYER)

I know this was solved, but please, all of you need to start reading the fucking wiki.
 
Code:
addHook("MobjThinker", function(mobj)
    local player = mobj.player
    if ((gametype == GT_COOP) or (gametype == GT_RACE))
    and ((player.mo) and (player.mo.skin == "knuckles")) then
        R_SetPlayerSkin(player, "sonic")
    end
end, MT_PLAYER)
I know this was solved, but please, all of you need to start reading the fucking wiki.
...Ohhh, GT, not TOL. That was my biggest mistake, wasn't it? Also, you need to start reading "the fucking wiki", as you say. "then" does absolutely nothing in Sonic Robo Blast 2's Lua, just like "do".
 
Code:
addHook("MobjThinker", function(mobj)
    local player = mobj.player
    if ((gametype == GT_COOP) or (gametype == GT_RACE))
    and ((player.mo) and (player.mo.skin == "knuckles")) then
        R_SetPlayerSkin(player, "sonic")
    end
end, MT_PLAYER)
I know this was solved, but please, all of you need to start reading the fucking wiki.
I don't think that was directed at me, but in case it was, I did state above that gametype can't use the TOL constants:
No, that's wrong. Gametype must use GT_ constants, which you aren't using, and won't work for his purposes.
I don't think your code solves it 100% either, since he said he wanted Single Player and Competition to be excluded. GT_COOP, according to the wiki, includes both Single Player and Coop.

This code should work 100%:
Code:
addHook("MobjThinker", function(mobj)
    local player = mobj.player
    if ((gametype == GT_COOP) or (gametype == GT_RACE))
    and (multiplayer)
    and ((player.mo) and (player.mo.skin == "knuckles")) then
        R_SetPlayerSkin(player, "sonic")
    end
end, MT_PLAYER)

...Ohhh, GT, not TOL. That was my biggest mistake, wasn't it? Also, you need to start reading "the fucking wiki", as you say. "then" does absolutely nothing in Sonic Robo Blast 2's Lua, just like "do".
Because it doesn't do anything doesn't mean he can't use it. He's probably using it out of habit or just to check himself or something.
 
Because it doesn't do anything doesn't mean he can't use it. He's probably using it out of habit or just to check himself or something.

It never really stopped my scripts from executing, so I never bother to change it, but it kind of is a habit, because I nearly ALWAYS write it.
 
Because it doesn't do anything doesn't mean he can't use it. He's probably using it out of habit or just to check himself or something.
I know, but does that mean I'm not allowed to point out to him it's a little stupid to say "when do people start reading the fucking wiki" when he types something the Wiki says isn't needed at all?
 
I know, but does that mean I'm not allowed to point out to him it's a little stupid to say "when do people start reading the fucking wiki" when he types something the Wiki says isn't needed at all?

I use then and do statements along with vanilla Lua comments and concatenation in order to stay consistent with the vanilla Lua standard. I use Lua outside of SRB2. BLUA syntax doesn't highlight properly in my text editor so I typically avoid dealing with it at all costs. It's not stupid, it's me choosing not to make use of the changes in SRB2's implementation in order to stay consistent with everything else I use the language for.
 
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top