Raised This Month: $32 Target: $400
 8% 

Modify Models Menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 08-21-2021 , 20:02   Modify Models Menu
Reply With Quote #1

Hi, I'm using this model menu from OxiCrom, but I would like to modify the following:

Everytime a player changes team, they stay with the same model they chose in the first place. I would like that everytime a player changes team they have to choose a model from the menu again.

Thanks!

PHP Code:
#include <amxmodx>
#include <cromchat>
#include <cstrike>
#include <hamsandwich>

#if !defined MAX_PLAYERS
const MAX_PLAYERS 32
#endif

enum _:ModelInfo
{
    
Name[32],
    
CsTeams:Team,
}

new const 
g_eModels[][ModelInfo] =
{
    { 
"Special_CT",  CS_TEAM_CT },
    { 
"Special_CT2"CS_TEAM_CT },
    { 
"Special_T",   CS_TEAM_T },
    { 
"Special_T2",  CS_TEAM_T }
}

const 
INVALID_SKIN = -1
const MENU_ACCESS_FLAG ADMIN_LEVEL_H
const Float:CONNECT_MSG_DELAY 5.0

new g_iModel[MAX_PLAYERS 1][CsTeams]

public 
plugin_init()
{
    
register_plugin("Models Menu""1.0""OciXCrom")
    
RegisterHam(Ham_Spawn"player""OnPlayerSpawn"1)

    
register_clcmd("say /vipskin""Cmd_VipSkin")
    
register_clcmd("say_team /vipskin""Cmd_VipSkin")

    
CC_SetPrefix("&x04[Prefix]")
}

public 
plugin_precache()
{
    for(new 
isizeof(g_eModels); i++)
    {
        
precache_player_model(g_eModels[i][Name])
    }
}

public 
client_putinserver(id)
{
    for(new 
CsTeams:iTeam CS_TEAM_UNASSIGNEDiTeam <= CS_TEAM_SPECTATORiTeam++)
    {
        
g_iModel[id][iTeam] = INVALID_SKIN
    
}

    
set_task(CONNECT_MSG_DELAY"DisplayMessage"id)
}

public 
DisplayMessage(id)
{
    if(
is_user_connected(id) && has_menu_access(id))
    {
        
CC_SendMessage(id"Type &x03/vipskin &x01to open the &x04VIP Skin Menu")
    }
}

public 
OnPlayerSpawn(id)
{
    if(!
is_user_alive(id))
    {
        return
    }

    new 
iModel g_iModel[id][cs_get_user_team(id)]

    if(
iModel == INVALID_SKIN)
    {
        return
    }

    
cs_set_user_model(idg_eModels[iModel][Name])
}

public 
Cmd_VipSkin(id)
{
    if(!
has_menu_access(id))
    {
        
CC_SendMessage(id"Only vips can open this menu, sorry!")
        return 
PLUGIN_HANDLED
    
}

    new 
iMenu menu_create("Select Your Skin""VipSkin_Handler")

    for(new 
CsTeams:iTeam cs_get_user_team(id), szNum[5], isizeof(g_eModels); i++)
    {
        if(
g_eModels[i][Team] == iTeam)
        {
            
num_to_str(iszNumcharsmax(szNum))
            
menu_additem(iMenug_eModels[i][Name], szNum)
        }
    }

    
menu_display(idiMenu)
    return 
PLUGIN_HANDLED
}

public 
VipSkin_Handler(idiMenuiItem)
{
    if(!
has_menu_access(id))
    {
        goto @
destroy
    
}

    static 
_unused[1]

    new 
szModelId[5]
    
menu_item_getinfo(iMenuiItem_unused[0], szModelIdcharsmax(szModelId), _unusedcharsmax(_unused), _unused[0])

    new 
iModel str_to_num(szModelId)
    new 
CsTeams:iTeam cs_get_user_team(id)

    if(
g_eModels[iModel][Team] != iTeam)
    {
        goto @
destroy
    
}

    
g_iModel[id][iTeam] = iModel
    CC_SendMessage
(id"You have selected the skin &x04%s"g_eModels[iModel][Name])

    if(
is_user_alive(id))
    {
        
cs_set_user_model(idg_eModels[iModel][Name])
    }

    @
destroy:
    
menu_destroy(iMenu)
    return 
PLUGIN_HANDLED
}

bool:has_menu_access(id)
{
    return (
get_user_flags(id) & MENU_ACCESS_FLAG) != 0
}

precache_player_model(const szModel[], &id 0)
{
    new 
model[128]
    
formatex(modelcharsmax(model), "models/player/%s/%sT.mdl"szModelszModel)

    if(
file_exists(model))
        
id precache_generic(model)

    static const 
extension[] = "T.mdl"
    
#pragma unused extension

    
copy(model[strlen(model) - charsmax(extension)], charsmax(model), ".mdl")
    return 
precache_model(model)


Last edited by JuanitoAlimana; 08-22-2021 at 16:25.
JuanitoAlimana is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 08-22-2021 , 11:05   Re: Modify Models Menu
Reply With Quote #2

I think you just need to enable the models menu plugin after the exclusive models one in plugins.ini, if it doesn't work you would also need to share the other plugin.
__________________








CrazY. is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 08-22-2021 , 16:22   Re: Modify Models Menu
Reply With Quote #3

Quote:
Originally Posted by CrazY. View Post
I think you just need to enable the models menu plugin after the exclusive models one in plugins.ini, if it doesn't work you would also need to share the other plugin.
I'm not using any other model plugin
JuanitoAlimana is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-22-2021 , 16:33   Re: Modify Models Menu
Reply With Quote #4

try this .. !!
Spoiler
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 08-22-2021 , 18:44   Re: Modify Models Menu
Reply With Quote #5

Quote:
Originally Posted by Natsheh View Post
try this .. !!
Spoiler
Not working, if I change teams, the model momentaneously goes to default but when you spawn it keeps the same model you had on the other team.
JuanitoAlimana is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 08-23-2021 , 10:17   Re: Modify Models Menu
Reply With Quote #6

The problem is cs_set_user_model. Try this:

Code:
#include <amxmodx>
#include <cromchat>
#include <cstrike>
#include <cs_player_models_api>
#include <hamsandwich>

#if !defined MAX_PLAYERS
const MAX_PLAYERS = 32
#endif

enum _:ModelInfo
{
    Name[32],
    CsTeams:Team,
}

new const g_eModels[][ModelInfo] =
{
    { "Special_CT",  CS_TEAM_CT },
    { "Special_CT2", CS_TEAM_CT },
    { "Special_T",   CS_TEAM_T },
    { "Special_T2",  CS_TEAM_T }
}

const INVALID_SKIN = -1
const MENU_ACCESS_FLAG = ADMIN_LEVEL_H
const Float:CONNECT_MSG_DELAY = 5.0

new g_iModel[MAX_PLAYERS + 1][CsTeams]

public plugin_init()
{
    register_plugin("Models Menu", "1.0", "OciXCrom")
    RegisterHam(Ham_Spawn, "player", "OnPlayerSpawn", 1)

    register_clcmd("say /vipskin", "Cmd_VipSkin")
    register_clcmd("say_team /vipskin", "Cmd_VipSkin")

    CC_SetPrefix("&x04[Prefix]")
}

public plugin_precache()
{
    for(new i; i < sizeof(g_eModels); i++)
    {
        precache_player_model(g_eModels[i][Name])
    }
}

public client_putinserver(id)
{
    for(new CsTeams:iTeam = CS_TEAM_UNASSIGNED; iTeam <= CS_TEAM_SPECTATOR; iTeam++)
    {
        g_iModel[id][iTeam] = INVALID_SKIN
    }

    set_task(CONNECT_MSG_DELAY, "DisplayMessage", id)
}

public DisplayMessage(id)
{
    if(is_user_connected(id) && has_menu_access(id))
    {
        CC_SendMessage(id, "Type &x03/vipskin &x01to open the &x04VIP Skin Menu")
    }
}

public OnPlayerSpawn(id)
{
    if(!is_user_alive(id))
    {
        return
    }

    new iModel = g_iModel[id][cs_get_user_team(id)]

    if(iModel == INVALID_SKIN)
    {
        return
    }

    cs_set_player_model(id, g_eModels[iModel][Name])
}

public Cmd_VipSkin(id)
{
    if(!has_menu_access(id))
    {
        CC_SendMessage(id, "Only vips can open this menu, sorry!")
        return PLUGIN_HANDLED
    }

    new iMenu = menu_create("Select Your Skin", "VipSkin_Handler")

    for(new CsTeams:iTeam = cs_get_user_team(id), szNum[5], i; i < sizeof(g_eModels); i++)
    {
        if(g_eModels[i][Team] == iTeam)
        {
            num_to_str(i, szNum, charsmax(szNum))
            menu_additem(iMenu, g_eModels[i][Name], szNum)
        }
    }

    menu_display(id, iMenu)
    return PLUGIN_HANDLED
}

public VipSkin_Handler(id, iMenu, iItem)
{
    if(!has_menu_access(id))
    {
        goto @destroy
    }

    static _unused[1]

    new szModelId[5]
    menu_item_getinfo(iMenu, iItem, _unused[0], szModelId, charsmax(szModelId), _unused, charsmax(_unused), _unused[0])

    new iModel = str_to_num(szModelId)
    new CsTeams:iTeam = cs_get_user_team(id)

    if(g_eModels[iModel][Team] != iTeam)
    {
        goto @destroy
    }

    g_iModel[id][iTeam] = iModel
    CC_SendMessage(id, "You have selected the skin &x04%s", g_eModels[iModel][Name])

    if(is_user_alive(id))
    {
        cs_set_player_model(id, g_eModels[iModel][Name])
    }

    @destroy:
    menu_destroy(iMenu)
    return PLUGIN_HANDLED
}

bool:has_menu_access(id)
{
    return (get_user_flags(id) & MENU_ACCESS_FLAG) != 0
}

precache_player_model(const szModel[], &id = 0)
{
    new model[128]
    formatex(model, charsmax(model), "models/player/%s/%sT.mdl", szModel, szModel)

    if(file_exists(model))
        id = precache_generic(model)

    static const extension[] = "T.mdl"
    #pragma unused extension

    copy(model[strlen(model) - charsmax(extension)], charsmax(model), ".mdl")
    return precache_model(model)
}
Attached Files
File Type: sma Get Plugin or Get Source (cs_player_models_api.sma - 121 views - 7.3 KB)
File Type: inc cs_player_models_api.inc (575 Bytes, 40 views)
__________________









Last edited by CrazY.; 08-23-2021 at 10:17.
CrazY. is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 08-23-2021 , 13:40   Re: Modify Models Menu
Reply With Quote #7

Quote:
Originally Posted by CrazY. View Post
The problem is cs_set_user_model. Try this:

Code:
#include <amxmodx>
#include <cromchat>
#include <cstrike>
#include <cs_player_models_api>
#include <hamsandwich>

#if !defined MAX_PLAYERS
const MAX_PLAYERS = 32
#endif

enum _:ModelInfo
{
    Name[32],
    CsTeams:Team,
}

new const g_eModels[][ModelInfo] =
{
    { "Special_CT",  CS_TEAM_CT },
    { "Special_CT2", CS_TEAM_CT },
    { "Special_T",   CS_TEAM_T },
    { "Special_T2",  CS_TEAM_T }
}

const INVALID_SKIN = -1
const MENU_ACCESS_FLAG = ADMIN_LEVEL_H
const Float:CONNECT_MSG_DELAY = 5.0

new g_iModel[MAX_PLAYERS + 1][CsTeams]

public plugin_init()
{
    register_plugin("Models Menu", "1.0", "OciXCrom")
    RegisterHam(Ham_Spawn, "player", "OnPlayerSpawn", 1)

    register_clcmd("say /vipskin", "Cmd_VipSkin")
    register_clcmd("say_team /vipskin", "Cmd_VipSkin")

    CC_SetPrefix("&x04[Prefix]")
}

public plugin_precache()
{
    for(new i; i < sizeof(g_eModels); i++)
    {
        precache_player_model(g_eModels[i][Name])
    }
}

public client_putinserver(id)
{
    for(new CsTeams:iTeam = CS_TEAM_UNASSIGNED; iTeam <= CS_TEAM_SPECTATOR; iTeam++)
    {
        g_iModel[id][iTeam] = INVALID_SKIN
    }

    set_task(CONNECT_MSG_DELAY, "DisplayMessage", id)
}

public DisplayMessage(id)
{
    if(is_user_connected(id) && has_menu_access(id))
    {
        CC_SendMessage(id, "Type &x03/vipskin &x01to open the &x04VIP Skin Menu")
    }
}

public OnPlayerSpawn(id)
{
    if(!is_user_alive(id))
    {
        return
    }

    new iModel = g_iModel[id][cs_get_user_team(id)]

    if(iModel == INVALID_SKIN)
    {
        return
    }

    cs_set_player_model(id, g_eModels[iModel][Name])
}

public Cmd_VipSkin(id)
{
    if(!has_menu_access(id))
    {
        CC_SendMessage(id, "Only vips can open this menu, sorry!")
        return PLUGIN_HANDLED
    }

    new iMenu = menu_create("Select Your Skin", "VipSkin_Handler")

    for(new CsTeams:iTeam = cs_get_user_team(id), szNum[5], i; i < sizeof(g_eModels); i++)
    {
        if(g_eModels[i][Team] == iTeam)
        {
            num_to_str(i, szNum, charsmax(szNum))
            menu_additem(iMenu, g_eModels[i][Name], szNum)
        }
    }

    menu_display(id, iMenu)
    return PLUGIN_HANDLED
}

public VipSkin_Handler(id, iMenu, iItem)
{
    if(!has_menu_access(id))
    {
        goto @destroy
    }

    static _unused[1]

    new szModelId[5]
    menu_item_getinfo(iMenu, iItem, _unused[0], szModelId, charsmax(szModelId), _unused, charsmax(_unused), _unused[0])

    new iModel = str_to_num(szModelId)
    new CsTeams:iTeam = cs_get_user_team(id)

    if(g_eModels[iModel][Team] != iTeam)
    {
        goto @destroy
    }

    g_iModel[id][iTeam] = iModel
    CC_SendMessage(id, "You have selected the skin &x04%s", g_eModels[iModel][Name])

    if(is_user_alive(id))
    {
        cs_set_player_model(id, g_eModels[iModel][Name])
    }

    @destroy:
    menu_destroy(iMenu)
    return PLUGIN_HANDLED
}

bool:has_menu_access(id)
{
    return (get_user_flags(id) & MENU_ACCESS_FLAG) != 0
}

precache_player_model(const szModel[], &id = 0)
{
    new model[128]
    formatex(model, charsmax(model), "models/player/%s/%sT.mdl", szModel, szModel)

    if(file_exists(model))
        id = precache_generic(model)

    static const extension[] = "T.mdl"
    #pragma unused extension

    copy(model[strlen(model) - charsmax(extension)], charsmax(model), ".mdl")
    return precache_model(model)
}
This works only if you choose a model beforehand from the other team. If its the first time you change teams, you will still appear as the first choice. So it "remembers" your selection but it won't work if you haven't selected "anything" before.

This whole thing wouldn't be a problem, but players are dishonest and they choose a model from one team and then they switch to the opposite side to look like an ally lol

Last edited by JuanitoAlimana; 08-23-2021 at 13:56.
JuanitoAlimana is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 08-24-2021 , 08:30   Re: Modify Models Menu
Reply With Quote #8

Can you try this one

Code:
#include <amxmodx>
#include <cromchat>
#include <cstrike>
#include <cs_player_models_api>
#include <hamsandwich>

#if !defined MAX_PLAYERS
const MAX_PLAYERS = 32
#endif

enum _:ModelInfo
{
	Name[32],
	CsTeams:Team,
}

new const g_eModels[][ModelInfo] =
{
	{ "Special_CT",  CS_TEAM_CT },
	{ "Special_CT2", CS_TEAM_CT },
	{ "Special_T",   CS_TEAM_T },
	{ "Special_T2",  CS_TEAM_T }
}

const INVALID_SKIN = -1
const MENU_ACCESS_FLAG = ADMIN_LEVEL_H
const Float:CONNECT_MSG_DELAY = 5.0

new g_iModel[MAX_PLAYERS + 1][CsTeams]

public plugin_init()
{
	register_plugin("Models Menu", "1.0", "OciXCrom")
	RegisterHam(Ham_Spawn, "player", "OnPlayerSpawn", 1)

	register_clcmd("say /vipskin", "Cmd_VipSkin")
	register_clcmd("say_team /vipskin", "Cmd_VipSkin")

	CC_SetPrefix("&x04[Prefix]")
}

public plugin_precache()
{
	for(new i; i < sizeof(g_eModels); i++)
	{
		precache_player_model(g_eModels[i][Name])
	}
}

public client_putinserver(id)
{
	for(new CsTeams:iTeam = CS_TEAM_UNASSIGNED; iTeam <= CS_TEAM_SPECTATOR; iTeam++)
	{
		g_iModel[id][iTeam] = INVALID_SKIN
	}

	set_task(CONNECT_MSG_DELAY, "DisplayMessage", id)
}

public DisplayMessage(id)
{
	if(is_user_connected(id) && has_menu_access(id))
	{
		CC_SendMessage(id, "Type &x03/vipskin &x01to open the &x04VIP Skin Menu")
	}
}

public OnPlayerSpawn(id)
{
	if(!is_user_alive(id) || !(CS_TEAM_T <= cs_get_user_team(id) <= CS_TEAM_CT))
	{
		return
	}

	new iModel = g_iModel[id][cs_get_user_team(id)]

	if(iModel == INVALID_SKIN)
	{
		ResetPlayerModel(id)
	}
	else
	{
		cs_set_player_model(id, g_eModels[iModel][Name])
	}    
}

public Cmd_VipSkin(id)
{
	if(!has_menu_access(id))
	{
		CC_SendMessage(id, "Only vips can open this menu, sorry!")
		return PLUGIN_HANDLED
	}

	new iMenu = menu_create("Select Your Skin", "VipSkin_Handler")

	for(new CsTeams:iTeam = cs_get_user_team(id), szNum[5], i; i < sizeof(g_eModels); i++)
	{
		if(g_eModels[i][Team] == iTeam)
		{
			num_to_str(i, szNum, charsmax(szNum))
			menu_additem(iMenu, g_eModels[i][Name], szNum)
		}
	}

	menu_display(id, iMenu)
	return PLUGIN_HANDLED
}

public VipSkin_Handler(id, iMenu, iItem)
{
	if(!has_menu_access(id))
	{
		goto @destroy
	}

	static _unused[1]

	new szModelId[5]
	menu_item_getinfo(iMenu, iItem, _unused[0], szModelId, charsmax(szModelId), _unused, charsmax(_unused), _unused[0])

	new iModel = str_to_num(szModelId)
	new CsTeams:iTeam = cs_get_user_team(id)

	if(g_eModels[iModel][Team] != iTeam)
	{
		goto @destroy
	}

	g_iModel[id][iTeam] = iModel
	CC_SendMessage(id, "You have selected the skin &x04%s", g_eModels[iModel][Name])

	if(is_user_alive(id))
	{
		cs_set_player_model(id, g_eModels[iModel][Name])
	}

	@destroy:
	menu_destroy(iMenu)
	return PLUGIN_HANDLED
}

bool:has_menu_access(id)
{
	return (get_user_flags(id) & MENU_ACCESS_FLAG) != 0
}

precache_player_model(const szModel[], &id = 0)
{
	new model[128]
	formatex(model, charsmax(model), "models/player/%s/%sT.mdl", szModel, szModel)

	if(file_exists(model))
		id = precache_generic(model)

	static const extension[] = "T.mdl"
	#pragma unused extension

	copy(model[strlen(model) - charsmax(extension)], charsmax(model), ".mdl")
	return precache_generic(model)
}

ResetPlayerModel(id)
{
	new buffer[32], model
	new CsTeams:team = cs_get_user_team(id, model)

	switch (team)
	{
		case CS_TEAM_T:
		{
			switch (model)
			{
				case CS_T_TERROR: copy(buffer, charsmax(buffer), "terror")
				case CS_T_LEET: copy(buffer, charsmax(buffer), "leet")
				case CS_T_ARCTIC: copy(buffer, charsmax(buffer), "arctic")
				case CS_T_GUERILLA: copy(buffer, charsmax(buffer), "guerilla")
				case CZ_T_MILITIA: copy(buffer, charsmax(buffer), "militia")
				default: copy(buffer, charsmax(buffer), "terror")
			}
		}
		case CS_TEAM_CT:
		{
			switch (model)
			{
				case CS_CT_URBAN: copy(buffer, charsmax(buffer), "urban")
				case CS_CT_GSG9: copy(buffer, charsmax(buffer), "gsg9")
				case CS_CT_GIGN: copy(buffer, charsmax(buffer), "gign")
				case CS_CT_SAS: copy(buffer, charsmax(buffer), "sas")
				case CS_CT_VIP: copy(buffer, charsmax(buffer), "vip")
				case CZ_CT_SPETSNAZ: copy(buffer, charsmax(buffer), "spetsnaz")
				default: copy(buffer, charsmax(buffer), "urban")
			}
		}
	}

	cs_set_player_model(id, buffer)
}
__________________








CrazY. is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 08-24-2021 , 19:35   Re: Modify Models Menu
Reply With Quote #9

Quote:
Originally Posted by CrazY. View Post
Can you try this one

Code:
#include <amxmodx>
#include <cromchat>
#include <cstrike>
#include <cs_player_models_api>
#include <hamsandwich>

#if !defined MAX_PLAYERS
const MAX_PLAYERS = 32
#endif

enum _:ModelInfo
{
	Name[32],
	CsTeams:Team,
}

new const g_eModels[][ModelInfo] =
{
	{ "Special_CT",  CS_TEAM_CT },
	{ "Special_CT2", CS_TEAM_CT },
	{ "Special_T",   CS_TEAM_T },
	{ "Special_T2",  CS_TEAM_T }
}

const INVALID_SKIN = -1
const MENU_ACCESS_FLAG = ADMIN_LEVEL_H
const Float:CONNECT_MSG_DELAY = 5.0

new g_iModel[MAX_PLAYERS + 1][CsTeams]

public plugin_init()
{
	register_plugin("Models Menu", "1.0", "OciXCrom")
	RegisterHam(Ham_Spawn, "player", "OnPlayerSpawn", 1)

	register_clcmd("say /vipskin", "Cmd_VipSkin")
	register_clcmd("say_team /vipskin", "Cmd_VipSkin")

	CC_SetPrefix("&x04[Prefix]")
}

public plugin_precache()
{
	for(new i; i < sizeof(g_eModels); i++)
	{
		precache_player_model(g_eModels[i][Name])
	}
}

public client_putinserver(id)
{
	for(new CsTeams:iTeam = CS_TEAM_UNASSIGNED; iTeam <= CS_TEAM_SPECTATOR; iTeam++)
	{
		g_iModel[id][iTeam] = INVALID_SKIN
	}

	set_task(CONNECT_MSG_DELAY, "DisplayMessage", id)
}

public DisplayMessage(id)
{
	if(is_user_connected(id) && has_menu_access(id))
	{
		CC_SendMessage(id, "Type &x03/vipskin &x01to open the &x04VIP Skin Menu")
	}
}

public OnPlayerSpawn(id)
{
	if(!is_user_alive(id) || !(CS_TEAM_T <= cs_get_user_team(id) <= CS_TEAM_CT))
	{
		return
	}

	new iModel = g_iModel[id][cs_get_user_team(id)]

	if(iModel == INVALID_SKIN)
	{
		ResetPlayerModel(id)
	}
	else
	{
		cs_set_player_model(id, g_eModels[iModel][Name])
	}    
}

public Cmd_VipSkin(id)
{
	if(!has_menu_access(id))
	{
		CC_SendMessage(id, "Only vips can open this menu, sorry!")
		return PLUGIN_HANDLED
	}

	new iMenu = menu_create("Select Your Skin", "VipSkin_Handler")

	for(new CsTeams:iTeam = cs_get_user_team(id), szNum[5], i; i < sizeof(g_eModels); i++)
	{
		if(g_eModels[i][Team] == iTeam)
		{
			num_to_str(i, szNum, charsmax(szNum))
			menu_additem(iMenu, g_eModels[i][Name], szNum)
		}
	}

	menu_display(id, iMenu)
	return PLUGIN_HANDLED
}

public VipSkin_Handler(id, iMenu, iItem)
{
	if(!has_menu_access(id))
	{
		goto @destroy
	}

	static _unused[1]

	new szModelId[5]
	menu_item_getinfo(iMenu, iItem, _unused[0], szModelId, charsmax(szModelId), _unused, charsmax(_unused), _unused[0])

	new iModel = str_to_num(szModelId)
	new CsTeams:iTeam = cs_get_user_team(id)

	if(g_eModels[iModel][Team] != iTeam)
	{
		goto @destroy
	}

	g_iModel[id][iTeam] = iModel
	CC_SendMessage(id, "You have selected the skin &x04%s", g_eModels[iModel][Name])

	if(is_user_alive(id))
	{
		cs_set_player_model(id, g_eModels[iModel][Name])
	}

	@destroy:
	menu_destroy(iMenu)
	return PLUGIN_HANDLED
}

bool:has_menu_access(id)
{
	return (get_user_flags(id) & MENU_ACCESS_FLAG) != 0
}

precache_player_model(const szModel[], &id = 0)
{
	new model[128]
	formatex(model, charsmax(model), "models/player/%s/%sT.mdl", szModel, szModel)

	if(file_exists(model))
		id = precache_generic(model)

	static const extension[] = "T.mdl"
	#pragma unused extension

	copy(model[strlen(model) - charsmax(extension)], charsmax(model), ".mdl")
	return precache_generic(model)
}

ResetPlayerModel(id)
{
	new buffer[32], model
	new CsTeams:team = cs_get_user_team(id, model)

	switch (team)
	{
		case CS_TEAM_T:
		{
			switch (model)
			{
				case CS_T_TERROR: copy(buffer, charsmax(buffer), "terror")
				case CS_T_LEET: copy(buffer, charsmax(buffer), "leet")
				case CS_T_ARCTIC: copy(buffer, charsmax(buffer), "arctic")
				case CS_T_GUERILLA: copy(buffer, charsmax(buffer), "guerilla")
				case CZ_T_MILITIA: copy(buffer, charsmax(buffer), "militia")
				default: copy(buffer, charsmax(buffer), "terror")
			}
		}
		case CS_TEAM_CT:
		{
			switch (model)
			{
				case CS_CT_URBAN: copy(buffer, charsmax(buffer), "urban")
				case CS_CT_GSG9: copy(buffer, charsmax(buffer), "gsg9")
				case CS_CT_GIGN: copy(buffer, charsmax(buffer), "gign")
				case CS_CT_SAS: copy(buffer, charsmax(buffer), "sas")
				case CS_CT_VIP: copy(buffer, charsmax(buffer), "vip")
				case CZ_CT_SPETSNAZ: copy(buffer, charsmax(buffer), "spetsnaz")
				default: copy(buffer, charsmax(buffer), "urban")
			}
		}
	}

	cs_set_player_model(id, buffer)
}
Sir, this works perfectly! It remembers your selection and makes you go to default in a second or two if you change teams!

Only thing left to make this plugin perfect would be to add a message saying "You have changed teams, please select your model again" when you change teams.

Thank you very much!
JuanitoAlimana is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 08-30-2021 , 09:03   Re: Modify Models Menu
Reply With Quote #10

This will show a message once a player spawn if he has changed teams

Untested

By the way, the 1-2 second delay you noticed is happening because of cs_player_models_api, this is to prevent the server from crashing but I didn't really test, not sure if that is still needed. You can decrease the delays by editing the following variables

Code:
// Delay between model changes (increase if getting SVC_BAD kicks)
new Float:g_ModelChangeDelay = 0.2

// Delay after roundstart (increase if getting kicks at round start)
new Float:g_RoundStartDelay = 2.0
Code:
#include <amxmodx>
#include <cromchat>
#include <cstrike>
#include <cs_player_models_api>
#include <hamsandwich>

#if !defined MAX_PLAYERS
const MAX_PLAYERS = 32
#endif

enum _:ModelInfo
{
	Name[32],
	CsTeams:Team,
}

new const g_eModels[][ModelInfo] =
{
	{ "Special_CT",  CS_TEAM_CT },
	{ "Special_CT2", CS_TEAM_CT },
	{ "Special_T",   CS_TEAM_T },
	{ "Special_T2",  CS_TEAM_T }
}

const INVALID_SKIN = -1
const MENU_ACCESS_FLAG = ADMIN_LEVEL_H
const Float:CONNECT_MSG_DELAY = 5.0

new g_iModel[MAX_PLAYERS + 1][CsTeams]
new CsTeams:g_iOldTeam[MAX_PLAYERS+1] = { CS_TEAM_UNASSIGNED, ... }

public plugin_init()
{
	register_plugin("Models Menu", "1.0", "OciXCrom")
	RegisterHam(Ham_Spawn, "player", "OnPlayerSpawn", 1)

	register_clcmd("say /vipskin", "Cmd_VipSkin")
	register_clcmd("say_team /vipskin", "Cmd_VipSkin")

	CC_SetPrefix("&x04[Prefix]")
}

public plugin_precache()
{
	for(new i; i < sizeof(g_eModels); i++)
	{
		precache_player_model(g_eModels[i][Name])
	}
}

public client_putinserver(id)
{
	for(new CsTeams:iTeam = CS_TEAM_UNASSIGNED; iTeam <= CS_TEAM_SPECTATOR; iTeam++)
	{
		g_iModel[id][iTeam] = INVALID_SKIN
	}

	g_iOldTeam[id] = CS_TEAM_UNASSIGNED

	set_task(CONNECT_MSG_DELAY, "DisplayMessage", id)
}

public DisplayMessage(id)
{
	if(is_user_connected(id) && has_menu_access(id))
	{
		CC_SendMessage(id, "Type &x03/vipskin &x01to open the &x04VIP Skin Menu")
	}
}

public OnPlayerSpawn(id)
{
	new CsTeams:team = cs_get_user_team(id)

	if(!is_user_alive(id) || !(CS_TEAM_T <= team <= CS_TEAM_CT))
	{
		return
	}

	new iModel = g_iModel[id][team]

	if(iModel == INVALID_SKIN)
	{
		ResetPlayerModel(id)

		if (g_iOldTeam[id] != CS_TEAM_UNASSIGNED && g_iOldTeam[id] != team)
			CC_SendMessage(id, "You have changed teams, please select your model again.")
	}
	else
	{
		cs_set_player_model(id, g_eModels[iModel][Name])
	}

	g_iOldTeam[id] = team
}

public Cmd_VipSkin(id)
{
	if(!has_menu_access(id))
	{
		CC_SendMessage(id, "Only vips can open this menu, sorry!")
		return PLUGIN_HANDLED
	}

	new iMenu = menu_create("Select Your Skin", "VipSkin_Handler")

	for(new CsTeams:iTeam = cs_get_user_team(id), szNum[5], i; i < sizeof(g_eModels); i++)
	{
		if(g_eModels[i][Team] == iTeam)
		{
			num_to_str(i, szNum, charsmax(szNum))
			menu_additem(iMenu, g_eModels[i][Name], szNum)
		}
	}

	menu_display(id, iMenu)
	return PLUGIN_HANDLED
}

public VipSkin_Handler(id, iMenu, iItem)
{
	if(!has_menu_access(id))
	{
		goto @destroy
	}

	static _unused[1]

	new szModelId[5]
	menu_item_getinfo(iMenu, iItem, _unused[0], szModelId, charsmax(szModelId), _unused, charsmax(_unused), _unused[0])

	new iModel = str_to_num(szModelId)
	new CsTeams:iTeam = cs_get_user_team(id)

	if(g_eModels[iModel][Team] != iTeam)
	{
		goto @destroy
	}

	g_iModel[id][iTeam] = iModel
	CC_SendMessage(id, "You have selected the skin &x04%s", g_eModels[iModel][Name])

	if(is_user_alive(id))
	{
		cs_set_player_model(id, g_eModels[iModel][Name])
	}

	@destroy:
	menu_destroy(iMenu)
	return PLUGIN_HANDLED
}

bool:has_menu_access(id)
{
	return (get_user_flags(id) & MENU_ACCESS_FLAG) != 0
}

precache_player_model(const szModel[], &id = 0)
{
	new model[128]
	formatex(model, charsmax(model), "models/player/%s/%sT.mdl", szModel, szModel)

	if(file_exists(model))
		id = precache_generic(model)

	static const extension[] = "T.mdl"
	#pragma unused extension

	copy(model[strlen(model) - charsmax(extension)], charsmax(model), ".mdl")
	return precache_generic(model)
}

ResetPlayerModel(id)
{
	new buffer[32], model
	new CsTeams:team = cs_get_user_team(id, model)

	switch (team)
	{
		case CS_TEAM_T:
		{
			switch (model)
			{
				case CS_T_TERROR: copy(buffer, charsmax(buffer), "terror")
				case CS_T_LEET: copy(buffer, charsmax(buffer), "leet")
				case CS_T_ARCTIC: copy(buffer, charsmax(buffer), "arctic")
				case CS_T_GUERILLA: copy(buffer, charsmax(buffer), "guerilla")
				case CZ_T_MILITIA: copy(buffer, charsmax(buffer), "militia")
				default: copy(buffer, charsmax(buffer), "terror")
			}
		}
		case CS_TEAM_CT:
		{
			switch (model)
			{
				case CS_CT_URBAN: copy(buffer, charsmax(buffer), "urban")
				case CS_CT_GSG9: copy(buffer, charsmax(buffer), "gsg9")
				case CS_CT_GIGN: copy(buffer, charsmax(buffer), "gign")
				case CS_CT_SAS: copy(buffer, charsmax(buffer), "sas")
				case CS_CT_VIP: copy(buffer, charsmax(buffer), "vip")
				case CZ_CT_SPETSNAZ: copy(buffer, charsmax(buffer), "spetsnaz")
				default: copy(buffer, charsmax(buffer), "urban")
			}
		}
	}

	cs_set_player_model(id, buffer)
}
__________________









Last edited by CrazY.; 08-30-2021 at 09:12.
CrazY. is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:37.


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