AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Give the same functionality for the alive players to the dead players (https://forums.alliedmods.net/showthread.php?t=334782)

Natsheh 10-19-2021 00:36

Give the same functionality for the alive players to the dead players
 
As the title says i want to spawn a dead player but the player remains dead for example when all of the player teammates are officially dead the round ends even if the dead player is still alive.

I tried spawning the player and giving him the dead_dead flag but i assume the player functionality is changed on player think and the player returns to the dead spectating.

Celena Luna 10-19-2021 04:45

Re: Give the same functionality for the alive players to the dead players
 
As I check in gamerules.cpp, it don't have to be DEAD_DEAD to trigger round end, only need to be not DEAD_NO.
Maybe try DEAD_DYING or DEAD_RESPAWNABLE after spawn?

Reference
Spoiler

Natsheh 10-19-2021 05:01

Re: Give the same functionality for the alive players to the dead players
 
Quote:

Originally Posted by Natsheh (Post 2760977)

I tried spawning the player and giving him the dead_dead flag but i assume the player functionality is changed on player think and the player returns to the dead spectating.


Celena Luna 10-19-2021 05:35

Re: Give the same functionality for the alive players to the dead players
 
Quote:

Originally Posted by Natsheh (Post 2760987)
I tried spawning the player and giving him the dead_dead flag but i assume the player functionality is changed on player think and the player returns to the dead spectating.

Did I misunderstand something?
I mean "anything other than DEAD_NO will count as DEAD and will treat it as dead player."
You said you set DEAD_DEAD and it turn player back to spec so I thought changing to DEAD_RESPAWNABLE will work.

Natsheh 10-19-2021 05:48

Re: Give the same functionality for the alive players to the dead players
 
I found a solution i need to be able to hook PlayerDeathThink and block it for that specified player.

PHP Code:

void CBasePlayer::PlayerDeathThink(void)
{
    
float flForward;

    if (
FBitSet(pev->flagsFL_ONGROUND))
    {
        
flForward pev->velocity.Length() - 20;
        if (
flForward <= 0)
            
pev->velocity g_vecZero;
        else    
            
pev->velocity flForward pev->velocity.Normalize();
    }

    if ( 
HasWeapons() )
    {
        
// we drop the guns here because weapons that have an area effect and can kill their user
        // will sometimes crash coming back from CBasePlayer::Killed() if they kill their owner because the
        // player class sometimes is freed. It's safer to manipulate the weapons once we know
        // we aren't calling into any of their code anymore through the player pointer.
        
PackDeadPlayerItems();
    }


    if (
pev->modelindex && (!m_fSequenceFinished) && (pev->deadflag == DEAD_DYING))
    {
        
StudioFrameAdvance( );

        
m_iRespawnFrames++;                // Note, these aren't necessarily real "frames", so behavior is dependent on # of client movement commands
        
if ( m_iRespawnFrames 120 )   // Animations should be no longer than this
            
return;
    }

    
// once we're done animating our death and we're on the ground, we want to set movetype to None so our dead body won't do collisions and stuff anymore
    // this prevents a bug where the dead body would go to a player's head if he walked over it while the dead player was clicking their button to respawn
    
if ( pev->movetype != MOVETYPE_NONE && FBitSet(pev->flagsFL_ONGROUND) )
        
pev->movetype MOVETYPE_NONE;

    if (
pev->deadflag == DEAD_DYING)
        
pev->deadflag DEAD_DEAD;
    
    
StopAnimation();

    
pev->effects |= EF_NOINTERP;
    
pev->framerate 0.0;

    
BOOL fAnyButtonDown = (pev->button & ~IN_SCORE );
    
    
// wait for all buttons released
    
if (pev->deadflag == DEAD_DEAD)
    {
        if (
fAnyButtonDown)
            return;

        if ( 
g_pGameRules->FPlayerCanRespawnthis ) )
        {
            
m_fDeadTime gpGlobals->time;
            
pev->deadflag DEAD_RESPAWNABLE;
        }
        
        return;
    }

// if the player has been dead for one second longer than allowed by forcerespawn, 
// forcerespawn isn't on. Send the player off to an intermission camera until they 
// choose to respawn.
    
if ( g_pGameRules->IsMultiplayer() && ( gpGlobals->time > (m_fDeadTime 6) ) && !(m_afPhysicsFlags PFLAG_OBSERVER) )
    {
        
// go to dead camera. 
        
StartDeathCam();
    }

    if ( 
pev->iuser1 )    // player is in spectator mode
        
return;    
    
// wait for any button down,  or mp_forcerespawn is set and the respawn time is up
    
if (!fAnyButtonDown 
        
&& !( g_pGameRules->IsMultiplayer() && forcerespawn.value && (gpGlobals->time > (m_fDeadTime 5))) )
        return;

    
pev->button 0;
    
m_iRespawnFrames 0;

    
//ALERT(at_console, "Respawn\n");

    
respawn(pev, !(m_afPhysicsFlags PFLAG_OBSERVER) );// don't copy a corpse if we're in deathcam.
    
pev->nextthink = -1;



CrazY. 10-19-2021 08:31

Re: Give the same functionality for the alive players to the dead players
 
Hook CHalfLifeMultiplay::CheckWinConditions and check the number of alive players, excluding the ones who are supposed to be dead, then force the round to end. To finish the round, you'll need TerminateRound, you won't even need to hook that with orpheu, it can be implemented in amxx, it's just three lines.

https://github.com/s1lentq/reapi/blo...merules.h#L698


If using regamedll and reapi, there is RG_CSGameRules_CheckWinConditions and rg_round_end native.
There are two alternatives I can think of right now if you're not able to use orpheu at all to get the signature for CheckWinConditions.

You will do that same check
Quote:

check the number of alive players, excluding the ones who are supposed to be dead
but on Ham_Killed and client_remove, this may fail if you transfer a player from his team without actually killing him.

The other is to either set a loop task or create an entity and there do that check. To check if the round is not already ending you can use m_bRoundTerminating.


To show the player as dead in the scoreboard, hook ScoreAttrib and set the flag (1<<0), you don't need DEAD_DEAD.

There is also this plugin which does exactly what you are trying, you may want to check it. https://forums.alliedmods.net/showth...1851?p=1441851

Natsheh 10-19-2021 10:00

Re: Give the same functionality for the alive players to the dead players
 
i managed for it to work using this sequence of code

Code:


                ExecuteHamB(Ham_CS_RoundRespawn, id);
                set_pev(id, pev_deadflag, DEAD_RESPAWNABLE);
                set_pev(id, pev_solid, SOLID_SLIDEBOX);
                set_pev(id, pev_movetype, MOVETYPE_WALK);
                set_pev(id, pev_health, 100.0);
                set_pev(id, pev_maxspeed, 250.0);
                give_item(id, "weapon_knife");

but now people can't see each other properly because there's a delay on the model location.

Natsheh 10-20-2021 05:04

Re: Give the same functionality for the alive players to the dead players
 
Quote:

Originally Posted by Natsheh (Post 2761011)
but now people can't see each other properly because there's a delay on the model location.


Its because on player think post the player is thought dead and most of the alive functions are ignored.

Natsheh 10-20-2021 09:29

Re: Give the same functionality for the alive players to the dead players
 
New error there's a problem with switching weapons if anyone can post the function of switching weapons or deploying them because i can't find it.

The problem is when switching a weapon the holster weapon is been deployed again, the dead flag is some how preventing the new weapon from been deployed, i searched the SelectItem in player.cpp but I couldn't find anything useful.

Natsheh 10-21-2021 05:29

Re: Give the same functionality for the alive players to the dead players
 
Quote:

Originally Posted by Natsheh (Post 2761095)
New error there's a problem with switching weapons if anyone can post the function of switching weapons or deploying them because i can't find it.

The problem is when switching a weapon the holster weapon is been deployed again, the dead flag is some how preventing the new weapon from been deployed, i searched the SelectItem in player.cpp but I couldn't find anything useful.


Solved, by setting the player dead_flag to dead_no and re-executing the weapon selection then setting back the player to dead_respawn in client_command forward, the same thing for dropping the weapons.


All times are GMT -4. The time now is 22:39.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.