Lua Questions

TheMinero

oh yeah,! this is happening!
Hello, I am theminero, and I have several questions and problems with lua things, what I want to do is like a summon spring and this is the code:

Lua::
addHook("PlayerThink",function(player)
if player.mo.skin == "sonic" and
player.cmd.buttons & BT_CUSTOM1
player.spring = true
player.spring = P_SpawnMobjFromMobj(player.mo,0*FRACUNIT,0*FRACUNIT,-1*FRACUNIT,MT_YELLOWSPRING)
if not (player.cmd.buttons & BT_CUSTOM1)
and player.spring == true then
P_KillMobj(player.spring)
player.pflags = $|PF_THOKKED
end
end
end)

is that I do not understand the P_SpawnMobj and the P_SpawnMobjFromMobj.
 

Bloopsdoob

The Resident Carrot!
the difference between the two functions can be found on the wiki, but put simply
P_SpawnMobj will spawn a mobj at the selected coordinates, this returns the summoned mobj.
whereas P_SpawnMobjFromMobj will instead spawn a mobj at the selected coordinates *relative* to a specified source, and share attributes with the source, such as gravity and scale.

the main issue here is that you're assigning a boolean to player.spring, and then overwriting it with your spawned mobj, which in of itself will NOT return true.
what you may want to do is specify it's fuse instead. Which can be found on the userdata page.
What I would do as a suggestion is:


Lua:
if p.mo.skin == 'sonic'
    if p.cmd.buttons & BT_CUSTOM1 and not p.c1down
    and not (p.pflags & PF_THOKKED)
        local spring = P_SpawnMobjFromMobj(p.mo, 0,0,0, MT_YELLOWSPRING)
        spring.fuse = TICRATE --change this to be the desired lifetime of the mobj
        p.pflags = $ | PF_THOKKED
    end
    p.c1down = (p.cmd.buttons & BT_CUSTOM1)
end
 

TheMinero

oh yeah,! this is happening!
the difference between the two functions can be found on the wiki, but put simply
P_SpawnMobj will spawn a mobj at the selected coordinates, this returns the summoned mobj.
whereas P_SpawnMobjFromMobj will instead spawn a mobj at the selected coordinates *relative* to a specified source, and share attributes with the source, such as gravity and scale.

the main issue here is that you're assigning a boolean to player.spring, and then overwriting it with your spawned mobj, which in of itself will NOT return true.
what you may want to do is specify it's fuse instead. Which can be found on the userdata page.
What I would do as a suggestion is:


Lua:
if p.mo.skin == 'sonic'
    if p.cmd.buttons & BT_CUSTOM1 and not p.c1down
    and not (p.pflags & PF_THOKKED)
        local spring = P_SpawnMobjFromMobj(p.mo, 0,0,0, MT_YELLOWSPRING)
        spring.fuse = TICRATE --change this to be the desired lifetime of the mobj
        p.pflags = $ | PF_THOKKED
    end
    p.c1down = (p.cmd.buttons & BT_CUSTOM1)
end
thx
 

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

Top