AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Switch team scores (https://forums.alliedmods.net/showthread.php?t=155667)

reinert 04-25-2011 06:39

Switch team scores
 
Would someone make a plugin that switches team scores by admin command /switchscores.

PHP Code:

#include <cshack>

register_clcmd("say /switchscores""swap_scores")

public 
swap_scores()
{
    new 
scoreCT cs_get_team_score(_:CS_TEAM_CT)
    new 
scoreT cs_get_team_score(_:CS_TEAM_T)
    
    
cs_set_team_score(_:CS_TEAM_CTscoreT)
    
cs_set_team_score(_:CS_TEAM_TscoreCT)


This is not working, It crashes the server.

Also I've this code, but somewhy it makes both team scores to -1 instead of swaping them.

PHP Code:

#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

#define SCORE_T 0
#define SCORE_CT 1

new g_TeamScore[2];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("TeamScore""eventTeamScore""a");
    
    
register_clcmd("say /swap""switchScores")
}

public 
eventTeamScore()
{
    new 
sTeam[2];
    
read_data(1sTeam1);
    if( 
sTeam[0] == 'T' )
    {
        
g_TeamScore[SCORE_T] = read_data(2);
    }
    else
    {
        
g_TeamScore[SCORE_CT] = read_data(2);
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
switchScores()
{
    
cs_set_team_score(,g_TeamScore[SCORE_CT])
    
cs_set_team_score(,g_TeamScore[SCORE_T])
}

stock cs_set_team_score(const team , const score) {     
    new 
buffer[10];     
    
    switch(
team)
    {         
        case 
1copy(buffer "TERRORIST");
        case 
2copy(buffer "CT");
        
        default: return 
0;     
    }     
    
    
message_begin(MSG_ALL get_user_msgid("TeamScore") , {0,0,0});
    
write_string(buffer);
    
write_byte(score);
    
message_end();
    
    return 
1;



ConnorMcLeod 04-25-2011 08:54

Re: Switch team scores
 
Are you plaining to swap players as well ?

reinert 04-25-2011 09:37

Re: Switch team scores
 
Yes, but it's not necessary right now, because how to swap players I already know.

Well I think I've figured out by looking at amx_teamscore plugin, but it's very complicated.

It's done with orpheu, but isn't there another way ?

ConnorMcLeod 04-25-2011 09:44

Re: Switch team scores
 
2 Attachment(s)
I asked that because there is a cs function that switches teams and teams scores.

Command : amx_swap_teams
-> swap teams on next new round (better to use it at this time).

! Not tested on linux but should work fine.

Edit : Without orpheu, you can't change team scores, you can only change what players see in scoreboard so you would need to change every message sent.

reinert 04-25-2011 10:26

Re: Switch team scores
 
Oh ok, I've made it myself something like:

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <orpheu>
#include <orpheu_memory>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

#define SCORE_T 0
#define SCORE_CT 1

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

new g_pGameRules;
new 
g_TeamScore[2];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("TeamScore""eventTeamScore""a");
    
    
register_clcmd"say /swap""ClientCommand_SetTeamScore");
}

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

public 
OnInstallGameRules()
{
    
g_pGameRules OrpheuGetReturn();
}

public 
eventTeamScore()
{
    new 
sTeam[2];
    
read_data(1sTeam1);
    if( 
sTeam[0] == 'T' )
    {
        
g_TeamScore[SCORE_T] = read_data(2);
    }
    else
    {
        
g_TeamScore[SCORE_CT] = read_data(2);
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
ClientCommand_SetTeamScore ()
{                
    
set_mp_pdata"m_iNumCTWins"g_TeamScore[SCORE_T] );
           
    
set_mp_pdata"m_iNumTerroristWins"g_TeamScore[SCORE_CT] );
        
    
UpdateTeamScores( .notifyAllPlugins true );
}

UpdateTeamScores ( const bool:notifyAllPlugins false )
    {
        static 
OrpheuFunction:handleFuncUpdateTeamScores;

        if ( !
handleFuncUpdateTeamScores )
        {
            
handleFuncUpdateTeamScores OrpheuGetFunction"UpdateTeamScores""CHalfLifeMultiplay" )
        }

        ( 
notifyAllPlugins ) ?

            
OrpheuCallSuperhandleFuncUpdateTeamScoresg_pGameRules ) :
            
OrpheuCallhandleFuncUpdateTeamScoresg_pGameRules );
    } 

Tested and it works, but I think ur code is better anyways ? is it ?

ConnorMcLeod 04-25-2011 10:28

Re: Switch team scores
 
If you want to swap players as well, yes.

reinert 04-25-2011 10:30

Re: Switch team scores
 
Ok thanks, <3 ;D

emaya93 01-02-2014 18:03

Re: Switch team scores
 
doesn't work on linux...

Code:

12/31/2013 - 13:45:03: [ORPHEU] Function "InstallGameRules" not found  12/31/2013 - 13:45:03: [AMXX] Displaying debug trace (plugin "swap_teams.amxx")  12/31/2013 - 13:45:03: [AMXX] Run time error 10: native error (native "OrpheuGetFunction")  12/31/2013 - 13:45:03: [AMXX] [0] swap_teams.sma::plugin_precache (line 126) [AMXX] Loaded 1 admin from file Cmd_AddCommand: say already defined  12/31/2013 - 13:45:03: [ORPHEU] Function "CHalfLifeMultiplay::SwapAllPlayers" not found  12/31/2013 - 13:45:03: [AMXX] Displaying debug trace (plugin "swap_teams.amxx")  12/31/2013 - 13:45:03: [AMXX] Run time error 10: native error (native "OrpheuGetFunction")  12/31/2013 - 13:45:03: [AMXX] [0] swap_teams.sma::plugin_init (line 58)

4ever16 11-18-2015 00:19

Re: Switch team scores
 
Any help?


Quote:

L 11/17/2015 - 03:28:21: [ORPHEU] Invalid memory structure "m_iNumCTWins"
L 11/17/2015 - 03:28:21: [AMXX] Run time error 10 (plugin "swap_teams.amxx") (native "OrpheuMemorySetAtAddress") - debug not enabled!
L 11/17/2015 - 03:28:21: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).
Debug.

Quote:

L 11/17/2015 - 03:35:35: [ORPHEU] Invalid memory structure "m_iNumCTWins"
L 11/17/2015 - 03:35:35: [AMXX] Displaying debug trace (plugin "swap_teams.amxx")
L 11/17/2015 - 03:35:35: [AMXX] Run time error 10: native error (native "OrpheuMemorySetAtAddress")
L 11/17/2015 - 03:35:35: [AMXX] [0] swap_teams.sma::ClientCommand_SetTeamScore (line 56)
Quote:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <orpheu>
#include <orpheu_memory>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

#define SCORE_T 0
#define SCORE_CT 1

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

new g_pGameRules;
new
g_TeamScore[2];

public
plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)

register_event("TeamScore", "eventTeamScore", "a");

register_clcmd( "say /swap", "ClientCommand_SetTeamScore");
}

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

public
OnInstallGameRules()
{
g_pGameRules = OrpheuGetReturn();
}

public
eventTeamScore()
{
new
sTeam[2];
read_data(1, sTeam, 1);
if(
sTeam[0] == 'T' )
{
g_TeamScore[SCORE_T] = read_data(2);
}
else
{
g_TeamScore[SCORE_CT] = read_data(2);
}

return
PLUGIN_CONTINUE;
}

public
ClientCommand_SetTeamScore ()
{
set_mp_pdata( "m_iNumCTWins", g_TeamScore[SCORE_T] );

set_mp_pdata( "m_iNumTerroristWins", g_TeamScore[SCORE_CT] );

UpdateTeamScores( .notifyAllPlugins = true );
}

UpdateTeamScores ( const bool:notifyAllPlugins = false )
{
static
OrpheuFunction:handleFuncUpdateTeamScores;

if ( !
handleFuncUpdateTeamScores )
{
handleFuncUpdateTeamScores = OrpheuGetFunction( "UpdateTeamScores", "CHalfLifeMultiplay" )
}

(
notifyAllPlugins ) ?

OrpheuCallSuper( handleFuncUpdateTeamScores, g_pGameRules ) :
OrpheuCall( handleFuncUpdateTeamScores, g_pGameRules );
}



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

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