How to get if player is being carried. And if so, whose carrying the player?

Saxa2007

gangsta sonic
I wanted to make a thing for a friend's character and mine, but I can't seem to find how i would get the player to check if its being carried. How would I go along with this?
 
In SRB2 2.1 there used to be a player state S_PLAY_CARRY that indicated whether or not a player was being carried.

Such state is missing from the 2.2 list of states however since the wiki page says that it might be incomplete, I believe it's worth a shot trying it out anyway:

Lua: Checking for S_PLAY_CARRY state:
addHook("PlayerThink", function(player)
    if player.mo.state == S_PLAY_CARRY then
        print("Player is being carried!")
    end
end)

If this does not work then the state was probably renamed (I doubt it was removed because you  can still be carried by Tails).

If this  does work however, just beware that the player can be carried by more things than just Tails (Arid Canyon's belts for example). So you might have to throw a bit of extra logic in there to make sure it only works when a player object is carrying the player.

EDIT
Even though you already said you figured the carrying part out I'm adjusting my answer because the information above isn't correct.
As it seems, in SRB2 2.2 whether or not you're being carried (and by what) is controlled by the pw_carry power:

A little snippet from the respective wiki page:
[...]
The values for carry types are as follows:
ValueNameDescription
0CR_NONENot being carried.
1CR_GENERICGeneric, default case for miscellaneous objects.
2CR_PLAYERBeing carried by a flying Tails player.
3CR_NIGHTSMODEThe player is currently in NiGHTS mode.
4CR_NIGHTSFALLThe player has ran out of time in NiGHTS.
5CR_BRAKGOOPStuck in old Brak Eggman's goop.
6CR_ZOOMTUBEUsing a Zoom Tube.
7CR_ROPEHANGUsing a Rope Hang.
8CR_MACESPINUsing a Mace swing.
9CR_MINECARTUsing a Minecart.
10CR_ROLLOUTUsing a Rollout Rock.
11CR_PTERABYTEBeing carried by a Pterabyte.
12CR_DUSTDEVILBeing carried by a Dust Devil.
[...]

So to check if you're being carried by a player you'd have simply have to check: if player.powers[pw_carry] & CR_PLAYER;
Or, alternatively, if player.powers[pw_carry] == 2 if you don't want to use the constants.
Either case can be done inside a "PlayerThink" or "ThinkFrame" hook, which you'll probably be using anyway for your logic.
 
Last edited:
In SRB2 2.1 there used to be a player state S_PLAY_CARRY that indicated whether or not a player was being carried.

Such state is missing from the 2.2 list of states however since the wiki page says that it might be incomplete, I believe it's worth a shot trying it out anyway:

Lua: Checking for S_PLAY_CARRY state:
addHook("PlayerThink", function(player)
    if player.mo.state == S_PLAY_CARRY then
        print("Player is being carried!")
    end
end)

If this does not work then the state was probably renamed (I doubt it was removed because you  can still be carried by Tails).

If this  does work however, just beware that the player can be carried by more things than just Tails (Arid Canyon's belts for example). So you might have to throw a bit of extra logic in there to make sure it only works when a player object is carrying the player.
Thanks, but I already got a way. But for some reason, I can't get player inputs...
 
is custom 3, when i switch player.mo.tracer.player our with player, it works, but not with tracer

I'm not 100% sure, this is an issue I never encountered before, but if I'd take a guess I think it could be because the code is interpreting the player from player and the player from player.mo.tracer.player (the last player in the line) as the same thing.

If it's not too much trouble could you rename the player in your hooked function to something else? To anything really.
Do make sure the change any reference to it to the new name you gave it. Liiike so:

Lua:
addHook("PlayerThink", function(plyr)
    -- Whatever code you had up to this point

    -- "top level" player is now named plyr as defined in the function parameter.
    if plyr.mo.tracer.player.cmd.buttons & BT_CUSTOM3 then
        -- Player who is carrying this player is pressing/holding Custom 3
        print("Custom 3 is being pressed!")
    end
end)
 
I'm not 100% sure, this is an issue I never encountered before, but if I'd take a guess I think it could be because the code is interpreting the player from player and the player from player.mo.tracer.player (the last player in the line) as the same thing.

If it's not too much trouble could you rename the player in your hooked function to something else? To anything really.
Do make sure the change any reference to it to the new name you gave it. Liiike so:

Lua:
addHook("PlayerThink", function(plyr)
    -- Whatever code you had up to this point

    -- "top level" player is now named plyr as defined in the function parameter.
    if plyr.mo.tracer.player.cmd.buttons & BT_CUSTOM3 then
        -- Player who is carrying this player is pressing/holding Custom 3
        print("Custom 3 is being pressed!")
    end
end)
well, it is already named as p
i think the inputs for buttons are registered client-side instead, no?
 

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

Back
Top