Lua Help

Status
Not open for further replies.

Prisima

Member
I can't seem to find the state that a Thing is in when it is able to carry something/someone else. I tried looking for the code that lets Tails carry things, and I looked in the Wiki at the (Old) Brak Eggman Missile, but to no avail. Any help?
 
Last edited:
Thanks Deadpool, but that's when the player is the one being carried. I need some code that marks the object as being elgible to be something that can be hanged onto, like the Brak Missile.
 
There is no "this object can carry other things" flag. What you'd need to do is use some collision hook to set PF_ITEMHANG on a player and set its tracer to the object in question.
 
I'm a bit inexperienced in Lua and I can't seem to make a collision hook. Would it be easier to have a hangable object (such as "Chain (Hang)") become invisible and capechase the object in question, in this case being another player?
 
Monster Iestyn brought to my attention that I could use a custom object, so I did. I tried to make it so that the invisible hanger (modified Brak Eggman missile) would spawn if you are gliding or flying, and would delete itself when you aren't gliding or flying. Do delete it, I'd have to use P_RemoveMobj, but as the wiki says, "The object cannot be referenced again in Lua after using this." I want it to respawn when the player is gliding or flying. Is there any workaroud to this?

Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo
		and not (player.pflags & PF_NIGHTSMODE) //No Nights Mode Hanger
			if (player.pflags & PF_CARRIED & PF_GLIDING) //Gliders and carried players get a hanger
				player.mo.hang = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_BLACKEGGMAN_MISSILE)
				player.mo.hang.target = player.mo
			if not (player.pflags & PF_CARRIED & PF_GLIDING)
				player.mo.hang = P_RemoveMobj(mobj_t mobj)
			end
		end
	end
 
Monster Iestyn brought to my attention that I could use a custom object, so I did. I tried to make it so that the invisible hanger (modified Brak Eggman missile) would spawn if you are gliding or flying, and would delete itself when you aren't gliding or flying. Do delete it, I'd have to use P_RemoveMobj, but as the wiki says, "The object cannot be referenced again in Lua after using this." I want it to respawn when the player is gliding or flying. Is there any workaroud to this?
Well, how do you expect to reference objects you delete? (You can respawn new ones using the same variable name as the first one spawned. You just can't change or read ("reference") attributes from non-existant objects.)
 
Thanks Zappy, so this code is ok for what I'm trying to do?
Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo
		and not (player.pflags & PF_NIGHTSMODE) //No Nights Mode Hanger
			if (player.pflags & PF_CARRIED & PF_GLIDING) //Gliders and carried players get a hanger
				player.mo.hang = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_BLACKEGGMAN_MISSILE)
				player.mo.hang.target = player.mo
			if not (player.pflags & PF_CARRIED & PF_GLIDING)
				player.mo.hang = P_RemoveMobj(MT_BLACKEGGMAN_MISSILE)
			end
		end
	end
 
Thanks Zappy, so this code is ok for what I'm trying to do?
Code:
addHook("ThinkFrame", do
    for player in players.iterate
        if player.mo
        and not (player.pflags & PF_NIGHTSMODE) //No Nights Mode Hanger
            if (player.pflags & PF_CARRIED & PF_GLIDING) //Gliders and carried players get a hanger
                player.mo.hang = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_BLACKEGGMAN_MISSILE)
                player.mo.hang.target = player.mo
            if not (player.pflags & PF_CARRIED & PF_GLIDING)
                player.mo.hang = P_RemoveMobj(MT_BLACKEGGMAN_MISSILE)
            end
        end
    end
Well, either the "& PF_CARRIED & PF_GLIDING" things will confuse Sonic Robo Blast 2, making it remove the Lua hook, or else the player has to be both carried and gliding (which is impossible in-game). Replace those lines with "if player.pflags & PF_CARRIED or player.pflags & PF_GLIDING".

Then, it also spawns a missile every single tic, so you should also check "if player.mo.hang == nil" before spawning the missile. You can also just use player.hang instead of player.mo.hang (same goes for other occurrences of it). Also set player.mo.hang.variable to player.mo.variable, variable in this case being x, y, z and angle (separate lines recommended for that), if player.mo.hang is not nil.

And when removing the object, you tell Lua to set the variable player.mo.hang to what the function P_RemoveObj(MT_BLACKEGGMAN_MISSILE) will return? If I'm not mistaking, it won't return anything. Plus you're trying to remove the MT_BLACKEGGMAN_MISSILEnth object that has spawned in the level, not the object itself. Replace that with "P_RemoveObj(player.mo.hang)" and another line of "player.mo.hang = nil".

I'm not going to mention you using the ThinkFrame hook instead of the MobjThinker hook. Whoops, mentioned it. (Ultimately it doesn't matter that much, though.)

Speaking of hooks, you have one "end" too little, and you don't have an ending bracket, ")", to close the hook.

Though honestly, I don't know if it'll work or not.
 
Thanks and done, Zappy.
Code:
addHook("MobjThinker", do
    for player in players.iterate
        if player.mo
        and not (player.pflags & PF_NIGHTSMODE) //No Nights Mode Hanger
            if (player.pflags & PF_CARRIED or player.pflags & PF_GLIDING) //Gliders and carried players get a hanger
            if player.hang == nil
                player.hang = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_BLACKEGGMAN_MISSILE)
                player.hang.target = player.mo
            if not (player.pflags & PF_CARRIED & PF_GLIDING)
                P_RemoveObj(player.hang)
                player.hang = nil
            end
        end
    end
end)
Also, my SRB2 freezes while trying to load the MAINCFG. It was working fine before I added the freeslots.
Code:
FREESLOT
S_HANGON_1
S_HANGON_2
SPR_HANG

Object MT_BLACKEGGMAN_MISSILE
MapThingNum = -1
SpawnState = S_HANGON_1
SpawnHealth = 9999
SeeState = 0
SeeSound = sfx_None
ReactionTime = 8
AttackSound = 0
PainState = S_NULL
PainChance = 0
PainSound = sfx_None
MeleeState = S_NULL
MissileState = S_NULL
DeathState = S_NULL
XDeathState = S_NULL
DeathSound = sfx_None
Speed = 0
Radius = 16*FRACUNIT
Height = 5*FRACUNIT
Mass = 100
Damage = 0
ActiveSound = 0
Flags = MF_RUNSPAWNFUNC|MF_SPECIAL|MF2_DONTDRAW
RaiseState = 0


State S_HANGON_1
SpriteName = HANG
SpriteFrame = A
Duration = 1
Next = S_HANGON_2
Action None


State S_HANGON_2
SpriteName = HANG
SpriteFrame = A
Duration = 70
Next = S_HANGON_2
Action A_CapeChase
 
Thanks and done, Zappy.
Code:
addHook("MobjThinker", do
    for player in players.iterate
        if player.mo
        and not (player.pflags & PF_NIGHTSMODE) //No Nights Mode Hanger
            if (player.pflags & PF_CARRIED or player.pflags & PF_GLIDING) //Gliders and carried players get a hanger
            if player.hang == nil
                player.hang = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_BLACKEGGMAN_MISSILE)
                player.hang.target = player.mo
            if not (player.pflags & PF_CARRIED & PF_GLIDING)
                P_RemoveObj(player.hang)
                player.hang = nil
            end
        end
    end
end)
Hm. Actually, you might want to check "if not player.hang == nil" before removing the object, I forgot that. And I'm pretty sure that's not exactly how MobjThinker works. If you're lazy, you can replace "do" at the start with "function()". If you're not, you can replace "do" with "function(mobj)", replace "for player in players.iterate" with "local player = mobj.player", remove one of the "end"s at the end, and add ", MT_PLAYER" between the last "end" and the closing bracket. If you do the second method, you can remove the "if player.mo" line, and change "and" to "if" in the Nights mode check thing. Also, you forgot an "end" for the "if player.hang == nil" check.

Also, my SRB2 freezes while trying to load the MAINCFG. It was working fine before I added the freeslots.
Code:
FREESLOT
S_HANGON_1
S_HANGON_2
SPR_HANG

Object MT_BLACKEGGMAN_MISSILE
-Snip-

State S_HANGON_1
-Snip-

State S_HANGON_2
SpriteName = HANG
SpriteFrame = A
Duration = 70
Next = S_HANGON_2
Action A_CapeChase
*Shrug* I'm not a Sanic Oopsie Control (Sonic Object Configuration/SOC) guy, I'm a Lua guy, and even then I'm not that good at being one. But I don't see anything wrong with the MainCfg thing you have there, other than possibly you have "duration 70" instead of 1 for S_HANGON_2 (the CapeChase only executes every 70th tic currently). That should not cause a crash, though.
 
Thanks and done, Zappy.
Code:
addHook("MobjThinker", do
    for player in players.iterate
        if player.mo
        and not (player.pflags & PF_NIGHTSMODE) //No Nights Mode Hanger
            if (player.pflags & PF_CARRIED or player.pflags & PF_GLIDING) //Gliders and carried players get a hanger
            if player.hang == nil
                player.hang = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_BLACKEGGMAN_MISSILE)
                player.hang.target = player.mo
            if not (player.pflags & PF_CARRIED & PF_GLIDING)
                P_RemoveObj(player.hang)
                player.hang = nil
            end
        end
    end
end)
Also, my SRB2 freezes while trying to load the MAINCFG. It was working fine before I added the freeslots.
Code:
FREESLOT
S_HANGON_1
S_HANGON_2
SPR_HANG

Object MT_BLACKEGGMAN_MISSILE
MapThingNum = -1
SpawnState = S_HANGON_1
SpawnHealth = 9999
SeeState = 0
SeeSound = sfx_None
ReactionTime = 8
AttackSound = 0
PainState = S_NULL
PainChance = 0
PainSound = sfx_None
MeleeState = S_NULL
MissileState = S_NULL
DeathState = S_NULL
XDeathState = S_NULL
DeathSound = sfx_None
Speed = 0
Radius = 16*FRACUNIT
Height = 5*FRACUNIT
Mass = 100
Damage = 0
ActiveSound = 0
Flags = MF_RUNSPAWNFUNC|MF_SPECIAL|MF2_DONTDRAW
RaiseState = 0


State S_HANGON_1
SpriteName = HANG
SpriteFrame = A
Duration = 1
Next = S_HANGON_2
Action None


State S_HANGON_2
SpriteName = HANG
SpriteFrame = A
Duration = 70
Next = S_HANGON_2
Action A_CapeChase

All I can see is that MT_BLACKEGGMAN_MISSILE is missing from the FREESLOT, maybe if you add that it might fix it, but I am not entirely sure
 
All I can see is that MT_BLACKEGGMAN_MISSILE is missing from the FREESLOT, maybe if you add that it might fix it, but I am not entirely sure
MT_BLACKEGGMAN_MISSILE exists in Sonic Robo Blast 2 itself, unless a post-2.1.0 update removed 2.0 Brak EggHead's missile objects. I don't see how it should have any effect.
 
I took your advice Zappy, and the LUA part of the wad looks fine. The MainCFG, however, keeps crashing. I'll have to diagnose it further. Thanks for your help everyone!
 
LUA_XXXX lumps are loaded before MAINCFG lumps, which means your objects are not being defined until after the Lua script starts running- causing a crashy crashy. Your only solution is to use the wiki's/#srb2fun's/ZZZ's help to convert your SOC into a Lua-readable format, at which point you'll put it in the LUA_XXXX lump.
 
The wad - now named "Multi-Pickup" - is basically a cosmetic item with an action. Those small wads don't crash, do they? I've dissected a cosmetic item wad and the MainCFG was after the Lua and it didn't crash in a netgame.
 
I can't seem to figure out what's wrong. I got some players together on a server and we tried it out, only to find out that the hanger doesn't work! Here's the link for the wad: tinyurl.com/srb2mpu001

EDIT: By the way, I got the MAINCFG working. It was that I used some wrong values in it.
 
I don't like downloading Wad files only to diagnose an error (yes, I know that's stupid)... Could you copy-paste the Lua script here? I'd like to check if something is wrong with it, or if it's just not possible to do hanging stuff this way.
 
Status
Not open for further replies.

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

Back
Top