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.)
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.
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.
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)
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
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.
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.
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".
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 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".
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: 0, Members: 0, Guests: 0)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.