View Single Post
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-24-2015 , 11:45   Re: Change VIP on as_ maps
Reply With Quote #4

In order to get next vip game use a function called CHalfLifeMultiplay:: PickNextVIP. It calls CHalfLifeMultiplay::ResetCurrentVIP which remove the old vip and CBasePlayer::MakeVip which is the function that actually make someone "vip".

So, all you have to do is to call CHalfLifeMultiplay::ResetCurrentVIP and CBasePlayer::MakeVip

PHP Code:
#include <amxmodx>
#include <orpheu>

new g_pGameRules
new gmsgScoreAttrib

new OrpheuFunction:CHalfLifeMultiplayResetVIP
new OrpheuFunction:CBasePlayerMakeVip

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

public 
OrpheuHookReturn:OnInstallGameRules() 
{
    
g_pGameRules OrpheuGetReturn()
}

public 
plugin_init()
{
    
CHalfLifeMultiplayResetVIP OrpheuGetFunction("ResetCurrentVIP""CHalfLifeMultiplay")
    
CBasePlayerMakeVip         OrpheuGetFunction("MakeVip""CBasePlayer")
    
    
gmsgScoreAttrib get_user_msgid"ScoreAttrib" )
    
    
register_clcmd("test""test")
}

public 
test(id)
{
    
OrpheuCall(CHalfLifeMultiplayResetVIPg_pGameRules)
    
OrpheuCall(CBasePlayerMakeVipid)
    
    
message_begin(MSG_ALLgmsgScoreAttrib)
    {
        
write_byte(id)
        
write_byte(<< 2)
        
message_end()
    }


Look at this test plugin. Call RemoveVIP to remove the old one and MakeVip with the new vip index to give someone else vip.

Code:
{
	"name" : "InstallGameRules",
	"library" : "mod",
	"return" :
	{
		"type" : "CGameRules *"
	},
	"identifiers":
	[
		{
			"os" : "windows",
			"mod" : "cstrike",
			"value" : [0x68,"*","*","*","*",0xFF,"*","*","*","*","*",0x83,"*","*",0xFF,"*","*","*","*","*",0xA1,"*","*","*","*",0xD9,"*","*",0xD8,"*","*","*","*","*",0xDF]
		},
		{
			"os" : "linux",
			"mod" : "cstrike",
			"value" : "_Z16InstallGameRulesv"
		}
	]
}
Signatures here: https://forums.alliedmods.net/showpo...6&postcount=35

I don't know why, but yesterday calling ResetVIP resulted in a crash, maybe because I was too tired. So, I rewrote the two functions and I think I'll post them too, maybe someone could use them as reference or idk. And yes, some parts could be done with cs_set_user_vip, but I wanted to fully redo it.

PHP Code:
#include <amxmodx>
#include <orpheu>
#include <orpheu_memory>
#include <fakemeta>

#if AMXX_VERSION_NUM < 183

#define INT_BYTES        4 
#define BYTE_BITS        8 

stock set_pdata_bool(entcharbased_offsetbool:valueintbase_linuxdiff 5

    
set_pdata_char(entcharbased_offset_:valueintbase_linuxdiff
}
stock set_pdata_char(entcharbased_offsetvalueintbase_linuxdiff 5

    
value &= 0xFF 
    
new int_offset_value get_pdata_int(entcharbased_offset INT_BYTESintbase_linuxdiff
    new 
bit_decal = (charbased_offset INT_BYTES) * BYTE_BITS 
    int_offset_value 
&= ~(0xFF<<bit_decal// clear byte 
    
int_offset_value |= value<<bit_decal 
    set_pdata_int
(entcharbased_offset INT_BYTESint_offset_valueintbase_linuxdiff
    return 



#endif

new gmsgScoreAttrib
new HandlepGameRules
new MaxPlayers

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

public 
plugin_init() 
{
    
gmsgScoreAttrib get_user_msgid"ScoreAttrib" )
    
MaxPlayers get_maxplayers()
}

stock ResetCurrentVIP(const NewVip)
{
    const 
m_bIsVip         837
    
const m_bNotKilled  452
    
const m_iModelName  126
    
const m_iTeam       114
    
const XoPlayer      5
    
    
new CurrentVip OrpheuMemoryGetAtAddress(HandlepGameRules"m_pVIP")
    if(
<= CurrentVip <= MaxPlayers)
    {
        
set_pdata_bool(CurrentVipm_bIsVipfalse)
        
set_pdata_bool(CurrentVipm_bNotKilledfalse)
        
        
SendScoreAttribMessage(CurrentVip0)
        
        
enum
        
{
            
MODEL_UNASSIGNED 0,
            
MODEL_URBAN,
            
MODEL_TERROR,
            
MODEL_LEET,
            
MODEL_ARCTIC,
            
MODEL_GSG9,
            
MODEL_GIGN,
            
MODEL_SAS,
            
MODEL_GUERILLA,
            
MODEL_VIP,
            
MODEL_MILITIA,
            
MODEL_SPETSNAZ
        

        
        
#pragma unused MODEL_MILITIA
        #pragma unused MODEL_GUERILLA
        #pragma unused MODEL_ARCTIC
        #pragma unused MODEL_LEET
        #pragma unused MODEL_TERROR
        #pragma unused MODEL_UNASSIGNED
        #pragma unused MODEL_SPETSNAZ
        
        
enum ModelData
        
{
            
ModelIndex,
            
ModelName[10]
        }
        
        new const 
Models[][ModelData] = 
        {
            {
MODEL_URBAN,    "gsg9"    },
            {
MODEL_GSG9 ,    "sas"    },
            {
MODEL_SAS    ,    "gign"    },
            {
MODEL_GIGN    ,    "urban"    }
        }
        
        new 
RandomModel random_num(03)
        
set_pdata_int(CurrentVipm_iModelNameModels[RandomModel][ModelIndex], XoPlayer)
        
engfunc(EngFunc_SetClientKeyValueCurrentVipengfunc(EngFunc_GetInfoKeyBufferCurrentVip), "model"Models[RandomModel][ModelName])
        
        if(
<= NewVip <= MaxPlayers)
        {
            
OrpheuMemorySetAtAddress(HandlepGameRules"m_pVIP"1NewVip)
            
OrpheuMemorySetAtAddress(HandlepGameRules"m_iConsecutiveVIP"11)
            
            
SendScoreAttribMessage(NewVip, (<< 2))
            
set_pdata_bool(NewVipm_bIsViptrue)
            
set_pdata_bool(NewVipm_bNotKilledfalse)
            
            
set_pev(NewVippev_body0)
            
set_pdata_int(NewVipm_iModelNameMODEL_VIPXoPlayer)
            
set_pdata_int(NewVipm_iTeam2)
            
            
engfunc(EngFunc_SetClientKeyValueNewVipengfunc(EngFunc_GetInfoKeyBufferNewVip), "model""vip")
        }
    }
}

stock SendScoreAttribMessage(idFlag)
{
    
message_begin(MSG_ALLgmsgScoreAttrib_id)
    {
        
write_byte(id)
        
write_byte(Flag)
        
message_end()
    }

Offets for code above
Code:
[
	{
        "name"        : "m_iConsecutiveVIP",
        "type"        : "int",
        "memoryType"  : "data",
        "identifiers" : 
        [
            {
                "os"    : "windows",
                "mod"   : "cstrike",
                "value" : 192
            },
            {
                "os"    : "linux",
                "mod"   : "cstrike",
                "value" : 184
            }
        ]
    },
    {
        "name"        : "m_pVIP",
        "type"        : "CBaseEntity *",
        "memoryType"  : "data",
        "identifiers" : 
        [
            {
                "os"    : "windows",
                "mod"   : "cstrike",
                "value" : 652
            },
            {
                "os"    : "linux",
                "mod"   : "cstrike",
                "value" : 644
            }
        ]
    }
]
__________________

Last edited by HamletEagle; 08-01-2015 at 09:39.
HamletEagle is offline