AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Restarting rounds without resetting team scores (https://forums.alliedmods.net/showthread.php?t=172863)

reinert 11-26-2011 17:50

Restarting rounds without resetting team scores
 
- TITLE -

How to do that ?

jim_yang 11-26-2011 18:02

Re: Restarting rounds without resetting team scores
 
orpheu, two way
1. jump cross the code of resetting team scores (efficient)
2. save scores, hook round restart, set it back. (less efficient than #1)

reinert 11-26-2011 18:03

Re: Restarting rounds without resetting team scores
 
What you mean with first method ?

jim_yang 11-26-2011 18:05

Re: Restarting rounds without resetting team scores
 
find the asm codes which do the reset stuff, mempatch a jmp bytes before it.

reinert 11-26-2011 18:08

Re: Restarting rounds without resetting team scores
 
Found this: g_OfSwapAllPlayers
Which swaps player teams and swaps team scores, but after swaping, people still got weapons they had, money they had :)

Arkshine 11-26-2011 19:41

Re: Restarting rounds without resetting team scores
 
You want only team scores ? Because there are others things resetted.

reinert 11-27-2011 04:25

Re: Restarting rounds without resetting team scores
 
Yeah I need to switch teams, switch team scores, then do restart, set scores back.

Arkshine 11-27-2011 07:22

Re: Restarting rounds without resetting team scores
 
1 Attachment(s)
You can test that.
Unzip in amxmodx/ directory.

What it does :

1/ Hook when a round restart is triggered
2/ Retrieve current team scores
3/ Block coming TeamScore message (because it's updated right away)
4/ Switch team scores
5/ Update scores on scoreboard.

PHP Code:

#include <amxmodx>
#include <orpheu>
#include <orpheu_memory>

/*
    │ PLUGIN
*/
    
new const PluginName   [] = "Switch Team Score On Restart";
    new const 
PluginVersion[] = "1.0";
    new const 
PluginAuhtor [] = "Arkshine";

/*
    | RESTART HANDLING
*/
    
enum GameRulesMembers
    
{
        
m_iNumTerroristWins,
        
m_iNumCTWins,
        
m_bCompleteReset,
        
m_bFirstConnected,
    };

    new const 
GameRulesMIGameRulesMembers ][] =
    {
        
"m_iNumTerroristWins",
        
"m_iNumCTWins",
        
"m_bCompleteReset",
        
"m_bFirstConnected"
    
};

    new 
g_pGameRules;

    
#define set_mp_pdata(%1,%2)  ( OrpheuMemorySetAtAddress( g_pGameRules, GameRulesMI[ %1 ], 1, %2 ) )
    #define get_mp_pdata(%1)     ( OrpheuMemoryGetAtAddress( g_pGameRules, GameRulesMI[ %1 ] ) )

    
new CurrentTerroristWins;
    new 
CurrentCTWins;
    
    new 
TeamScoreMessageIndex;
    
    new 
bool:ReadyToSwitch;


public 
plugin_precache()
{
    
OrpheuRegisterHookOrpheuGetFunction"InstallGameRules" ), "OnInstallGameRules"OrpheuHookPost );
}

public 
OnInstallGameRules()
{
    
g_pGameRules OrpheuGetReturn();
}

public 
plugin_init()
{
    
register_pluginPluginNamePluginVersionPluginAuhtor );
    
    
handleForward();
}

public 
plugin_cfg()
{
    
TeamScoreMessageIndex get_user_msgid"TeamScore" );
}

handleForward()
{
    new 
OrpheuFunction:handleFunc OrpheuGetFunctionFromObjectg_pGameRules"RestartRound""CGameRules" );

    
OrpheuRegisterHookhandleFunc"OnRestartRound_Pre" OrpheuHookPre );
    
OrpheuRegisterHookhandleFunc"OnRestartRound_Post" OrpheuHookPost );
}

public 
OnRestartRound_Pre( const handleGameRules )
{
    if( 
get_mp_pdatam_bCompleteReset ) )
    {
        
CurrentTerroristWins get_mp_pdatam_iNumTerroristWins );
        
CurrentCTWins        get_mp_pdatam_iNumCTWins );

        
set_msg_blockTeamScoreMessageIndexBLOCK_SET );

        
ReadyToSwitch true;
    }
}

public 
OnRestartRound_Post( const handleGameRules )
{
    if( 
ReadyToSwitch )
    {
        
ReadyToSwitch false;

        
set_mp_pdatam_iNumTerroristWinsCurrentCTWins );
        
set_mp_pdatam_iNumCTWinsCurrentTerroristWins );

        
set_msg_blockTeamScoreMessageIndexBLOCK_NOT );
        
updateTeamScore();
    }
}

updateTeamScore()
{
    static 
OrpheuFunction:handleFunchandleFunc || ( handleFunc OrpheuGetFunction"UpdateTeamScores""CHalfLifeMultiplay" ) );
    
OrpheuCallSuperhandleFuncg_pGameRules );



colossus 05-13-2015 22:42

Re: Restarting rounds without resetting team scores
 
Quote:

Originally Posted by Arkshine (Post 1603518)
You can test that.
Unzip in amxmodx/ directory.

What it does :

1/ Hook when a round restart is triggered
2/ Retrieve current team scores
3/ Block coming TeamScore message (because it's updated right away)
4/ Switch team scores
5/ Update scores on scoreboard.

PHP Code:

#include <amxmodx>
#include <orpheu>
#include <orpheu_memory>

/*
    │ PLUGIN
*/
    
new const PluginName   [] = "Switch Team Score On Restart";
    new const 
PluginVersion[] = "1.0";
    new const 
PluginAuhtor [] = "Arkshine";

/*
    | RESTART HANDLING
*/
    
enum GameRulesMembers
    
{
        
m_iNumTerroristWins,
        
m_iNumCTWins,
        
m_bCompleteReset,
        
m_bFirstConnected,
    };

    new const 
GameRulesMIGameRulesMembers ][] =
    {
        
"m_iNumTerroristWins",
        
"m_iNumCTWins",
        
"m_bCompleteReset",
        
"m_bFirstConnected"
    
};

    new 
g_pGameRules;

    
#define set_mp_pdata(%1,%2)  ( OrpheuMemorySetAtAddress( g_pGameRules, GameRulesMI[ %1 ], 1, %2 ) )
    #define get_mp_pdata(%1)     ( OrpheuMemoryGetAtAddress( g_pGameRules, GameRulesMI[ %1 ] ) )

    
new CurrentTerroristWins;
    new 
CurrentCTWins;
    
    new 
TeamScoreMessageIndex;
    
    new 
bool:GameCommencing;
    new 
bool:ReadyToSwitch;


public 
plugin_precache()
{
    
OrpheuRegisterHookOrpheuGetFunction"InstallGameRules" ), "OnInstallGameRules"OrpheuHookPost );
}

public 
OnInstallGameRules()
{
    
g_pGameRules OrpheuGetReturn();
}

public 
plugin_init()
{
    
register_pluginPluginNamePluginVersionPluginAuhtor );
    
    
handleForward();
}

public 
plugin_cfg()
{
    
TeamScoreMessageIndex get_user_msgid"TeamScore" );
}

handleForward()
{
    
register_event"TextMsg""OnGameCommencing""a""2=#Game_Commencing" );

    new 
OrpheuFunction:handleFunc OrpheuGetFunctionFromObjectg_pGameRules"RestartRound""CGameRules" );

    
OrpheuRegisterHookhandleFunc"OnRestartRound_Pre" OrpheuHookPre );
    
OrpheuRegisterHookhandleFunc"OnRestartRound_Post" OrpheuHookPost );
}

public 
OnGameCommencing()
{
    
GameCommencing true;
}

public 
OnRestartRound_Pre( const handleGameRules )
{
    if( 
GameCommencing )
    {
        
GameCommencing false;
        return;
    }

    if( 
get_mp_pdatam_bCompleteReset ) )
    {
        
CurrentTerroristWins get_mp_pdatam_iNumTerroristWins );
        
CurrentCTWins        get_mp_pdatam_iNumCTWins );

        
set_msg_blockTeamScoreMessageIndexBLOCK_SET );

        
ReadyToSwitch true;
    }
}

public 
OnRestartRound_Post( const handleGameRules )
{
    if( 
ReadyToSwitch )
    {
        
ReadyToSwitch false;

        
set_mp_pdatam_iNumTerroristWinsCurrentCTWins );
        
set_mp_pdatam_iNumCTWinsCurrentTerroristWins );

        
set_msg_blockTeamScoreMessageIndexBLOCK_NOT );
        
updateTeamScore();
    }
}

updateTeamScore()
{
    static 
OrpheuFunction:handleFunchandleFunc || ( handleFunc OrpheuGetFunction"UpdateTeamScores""CHalfLifeMultiplay" ) );
    
OrpheuCallSuperhandleFuncg_pGameRules );



RoundRestart Pre don't work
the score is reset before RoundRestart Pre Hook

the correct way is to get CurrentTerroristWins and CurrentCTWins is in TextMsg


PHP Code:

register_message(get_user_msgid("TextMsg"), "message_textmsg")

public 
message_textmsg()
{
    static 
textmsg[22]
    
    
get_msg_arg_string(2textmsgcharsmax(textmsg))
    
    if (
equal(textmsg"#Game_will_restart_in"))
    {
        
g_iNumTerroristWins get_mp_pdatam_iNumTerroristWins )
        
g_iNumCTWins get_mp_pdatam_iNumCTWins )
    }



Arkshine 05-14-2015 04:29

Re: Restarting rounds without resetting team scores
 
No, score is reset inside RestartRound, but I'm not sure why I'm checking against GameCommencing and returning. It's likely wrong, it should not return.
You can remove anything related to GameCommencing, it's not needed. since when round is restarting (so when Game Commencing is triggered), m_bCompleteReset is set to true.


All times are GMT -4. The time now is 08:34.

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