transhumandesign / kag-base

King Arthur's Gold base folder.
257 stars 119 forks source link

Bug in Seats.as #2037

Closed mugg91 closed 3 weeks ago

mugg91 commented 5 months ago

Description

Seats.as has:

void onAttach(CBlob@ this, CBlob@ attached, AttachmentPoint @attachedPoint)
{
    if (attachedPoint.socket)
    {
        attached.Tag("seated");
        Sound::Play("GetInVehicle.ogg", attached.getPosition());

        if (this.getDamageOwnerPlayer() is null) {
            this.SetDamageOwnerPlayer(attached.getPlayer());
        }
    }
}

void onDetach(CBlob@ this, CBlob@ detached, AttachmentPoint@ attachedPoint)
{
    if (attachedPoint.socket)
    {
        detached.Untag("seated");

        if (!detached.getShape().isRotationsAllowed())
        {
            detached.setAngleDegrees(0.0f);
        }

        if (detached.getPlayer() is this.getDamageOwnerPlayer()) {
            this.SetDamageOwnerPlayer(null);
        }
    }
}

This code sets the sitting player as the damage owner and unsets him when he stops sitting.

However, when the sitting player dies, the code in onDetach() doesn't run and the player will still be the damage owner even when not sitting anymore.

When getting killed while sitting on a Bison, all kills the Bison does will be counted towards that player. Someone else sitting on the Bison will not override the damage owner due to the check for if (this.getDamageOwnerPlayer() is null).

Also, when the damage owner player gets killed by the Bison, the game will say that the player killed himself.

I you do this bug with a catapult, - although not tested - it may be possible that someone else riding over enemies will count towards the player that previously sat in the catapult. I did verify that a catapult I'm no longer sitting in will attribute kills to me at least.


In a match, I tamed a Bison and got killed while riding. After respawning, I saw kills getting attributed to me which is the reason I found this. 222

mugg91 commented 5 months ago

~It looks like onDetach() does get run after all, and successfully unsets the damage player. But then I'm not unterstanding why the bug is happening ...~

The

        if (detached.getPlayer() is this.getDamageOwnerPlayer()) {
            this.SetDamageOwnerPlayer(null);
        }

code is successful on client but it fails on server. I guess the detached blob is already treated as null.