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

[Problem] Model set


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ognjen7
Junior Member
Join Date: Nov 2015
Old 12-30-2020 , 08:56   [Problem] Model set
Reply With Quote #1

So:

Code:
#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <fakemeta>

#define PLUGIN "knife menu"
#define VERSION "1.0"
#define AUTHOR "author"

new const choose[][] = {
	"Classic Knives",
	"VIP Knives"
}

enum _:Knives
{
	Name,
	bool:Special,
	vModel,
	pModel
}

//new _iData[Knives];

new knife_model[33];

new const knifeData[2][Knives][] = 
{
	{	"Classic Knife",	false,		"models/v_knife.mdl",			"models/p_knife.mdl"		},
	{	"Test",			true,		"models/v_vip_katana.mdl",		"models/p_knife.mdl"		}
}

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_clcmd("say /knife", "ChooseMenu");
	
	register_event("CurWeapon", "CurWeapon", "be", "1=1");
}

public plugin_precache()
{
	for(new i; i < sizeof(knifeData); i++)
	{
		precache_model(knifeData[i][vModel]);
		precache_model(knifeData[i][pModel]);
	}
}

public ChooseMenu(id)
{
	if(!is_user_connected(id))
		return PLUGIN_CONTINUE
		
	new menu = menu_create("\wKnife Menu", "ChooseMenuH");
	
	for(new i; i < sizeof(choose); i++)
	{
		new _choose[512];
		formatex(_choose, charsmax(_choose), "%s", choose[i]);
		menu_additem(menu, _choose);
	}
	menu_display(id, menu);
	
	return PLUGIN_CONTINUE;
}

public ChooseMenuH(id, menu, item)
{
	if(item == MENU_EXIT)
	{
		menu_destroy(menu);
		return PLUGIN_CONTINUE;
	}
	
	switch(item)
	{
		case 0:	ClassicKnivesMenu(id);
		case 1:
		{
			if(get_user_flags(id) & ADMIN_LEVEL_H)
				VIPKnivesMenu(id);
			else
				ColorChat(id, GREEN, "[Knife] ^1You don't have access to this menu.");
		}
				
	}
	return PLUGIN_CONTINUE;
}

public ClassicKnivesMenu(id)
{
	if(!is_user_connected(id))
		return PLUGIN_CONTINUE;
		
	new menu = menu_create("\wClassic Knives", "ClassicKnivesMenuH");
	
	new new_menu[64];
	
	for(new i; i < sizeof(knifeData); i++)
	{
		if(knifeData[i][Special][0] == 0)
		{
			formatex(new_menu, charsmax(new_menu), "%s", knifeData[i][Name]);
			menu_additem(menu, new_menu);
		}
	}
	menu_display(id, menu);
	
	return PLUGIN_CONTINUE;
	
}

public ClassicKnivesMenuH(id, menu, item)
{
	if(item == MENU_EXIT)
	{
		menu_destroy(menu);
		return PLUGIN_CONTINUE;
	}
	
	new command[6], name[64], access, callback;
	menu_item_getinfo(menu, item, access, command, sizeof command - 1, name, sizeof name - 1, callback);
	
	SetKnife(id, item);
	ColorChat(id, GREEN, "Set");
	
	menu_destroy(menu);
	
	return PLUGIN_CONTINUE;
}

public VIPKnivesMenu(id)
{
	if(!is_user_connected(id))
		return PLUGIN_CONTINUE;
		
	new menu = menu_create("\wVIP Knives", "VIPKnivesMenuH");
	
	new new_menu[64];
	
	for(new i; i < sizeof(knifeData); i++)
	{
		if(knifeData[i][Special][0] == 1)
		{
			formatex(new_menu, charsmax(new_menu), "%s", knifeData[i][Name]);
			menu_additem(menu, new_menu);
		}
	}
	menu_display(id, menu);
	
	return PLUGIN_CONTINUE;
}

public VIPKnivesMenuH(id, menu, item)
{
	if(item == MENU_EXIT)
	{
		menu_destroy(menu);
		return PLUGIN_CONTINUE;
	}
	
	new command[6], name[64], access, callback;
	menu_item_getinfo(menu, item, access, command, sizeof command - 1, name, sizeof name - 1, callback);
	
	SetKnife(id, item);
	ColorChat(id, GREEN, "VIP Set");
	
	menu_destroy(menu);
	
	return PLUGIN_CONTINUE;
}

public SetKnife(id, knife)
{
	new clip, ammo, weapon = get_user_weapon(id, clip, ammo);
			
	if(weapon != CSW_KNIFE)
		return;
		
	knife_model[id] = knife;
		
	new v_Model[56];
	new p_Model[56];
	
	format(v_Model, 55, knifeData[knife][vModel]);
	format(p_Model, 55, knifeData[knife][pModel]);

	set_pev(id, pev_viewmodel2, v_Model)
	set_pev(id, pev_weaponmodel2, p_Model)
}

public CurWeapon(id)
{
	SetKnife(id, knife_model[id]);
}
This is the first problem I've encountered in years, and uhm I don't exactly know what's wrong here, am I blind that I can't see the problem or is it just wrong like this (I have one mod I made on this writing and it's working fine and this part of the code isn't for some reason).

So let's go straight to the problem. The problem is that when I choose knife model I wanna set on me (in this case Test), it doesn't work. I tried to see, is the function even working at all (Set / VIP Set) and it seems it works, so I guess the problem is in SetKnife or that I didn't add something very important which it seems I can't guess what it is. So yeah in short setting model on a knife isn't working.

Code:
public SetKnife(id, knife)
{
	new clip, ammo, weapon = get_user_weapon(id, clip, ammo);
			
	if(weapon != CSW_KNIFE)
		return;
		
	knife_model[id] = knife;
		
	new v_Model[56];
	new p_Model[56];
	
	format(v_Model, 55, knifeData[knife][vModel]);
	format(p_Model, 55, knifeData[knife][pModel]);

	set_pev(id, pev_viewmodel2, v_Model)
	set_pev(id, pev_weaponmodel2, p_Model)
}

public CurWeapon(id)
{
	SetKnife(id, knife_model[id]);
}
Btw I was doing some tests and I wrote this literally like 30m ago and it surprised me that it isn't working whatever I try, so that's why I'm curious what is the problem here. Would mean a lot if someone could explain

Last edited by Ognjen7; 12-30-2020 at 09:02.
Ognjen7 is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 12-30-2020 , 12:14   Re: [Problem] Model set
Reply With Quote #2

As i'm thinking you can code yourself, i'll just post this code here so you could try and figure out what the problem exactly is.

PHP Code:
/* Sublime AMXX Editor v2.2 */

#include <amxmodx>
// #include <amxmisc>
// #include <cstrike>
// #include <engine>
#include <fakemeta>
// #include <hamsandwich>
// #include <fun>
// #include <xs>
// #include <sqlx>

#pragma semicolon 1

#if !defined MAX_PLAYERS
    
const MAX_PLAYERS 32;
#endif

#define PLUGIN  "VIP Knife"
#define VERSION "1.0"
#define AUTHOR  "NapoleoN#"

new const szModel[][] = {
    
"p_vipknife.mdl",
    
"v_vipknife.mdl"
};

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);

    
register_event("CurWeapon""ResetModel""be""1=1""2=29");
}

public 
plugin_precache() {
    for(new 
isizeof(szModel); i++) {
        
precache_model(szModel[i]);
    }
}

public 
ResetModel() {
    new 
id read_data(1);

    if(
get_user_flags(id) & ADMIN_LEVEL_H) {
        
set_pev(idpev_viewmodel2szModel[1]);
        
set_pev(idpev_weaponmodel2szModel[0]);
    }

PS: Try setting the knives the way i do (without an extra function, just comment the function for testing purposes) as i believe your problem is on how you're setting the models.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Ognjen7
Junior Member
Join Date: Nov 2015
Old 12-30-2020 , 13:16   Re: [Problem] Model set
Reply With Quote #3

You mean what is the problem here you wrote ?

EDIT: I guess that isn't actually the problem. I added another knife in menu (Classic one) and when I select it, it does change the model but for some reason when I select submenu and select that VIP knife there it changes to Classic Knife while it shouldn't change to that.

EDIT2: I fixed everything, I created some include files which helped. Btw thanks a lot for help and hint

Last edited by Ognjen7; 12-31-2020 at 06:34.
Ognjen7 is offline
Reply


Thread Tools
Display Modes

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 22:06.


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