Raised This Month: $ Target: $400
 0% 

Weapon Change Model


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DarthMan
Veteran Member
Join Date: Aug 2011
Old 03-07-2017 , 06:17   Weapon Change Model
Reply With Quote #1

Hello. I am trying to make a plugin that is supossed to change the weapon skin for v,w and p.
I failed to do it, so, can anyone fix the plugin for me? Thanks !

Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <engine> 
#include <fakemeta>

#define PLUGIN "Weapon Changer"
#define VERSION "1.0"
#define AUTHOR "DarthMan"

new file_model[128]
new p_modelsnum


public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_event("CurWeapon", "Event_CurWeapon", "be","1=1")
	register_forward(FM_SetModel, "fw_SetModel")
}

public plugin_precache()
{
    new conffile_mdl[200]
    new configdir_mdl[200]
 
    get_configsdir(configdir_mdl,199)
    format(conffile_mdl,199,"%s/weapons-models.ini",configdir_mdl)
    if(!file_exists(conffile_mdl))
    {
        log_amx("amxmodx/configs/weapons-models.ini is missing!")
        return 0
    }
    
    new line = 0, textline[256], len
    const SIZE = 63
    new line_model[SIZE + 1], line_model_replace[SIZE + 1], parsedParams;  
    new model_path[128];
    new linetoread[512];
    
    while ((line = read_file(conffile_mdl, line, textline, 255, len)))
    {
	if (len == 0 || equal(textline, ";", 1))
	continue // comment line
	formatex(linetoread, 511, "%s^" ^"%s^"", line_model, line_model_replace)
	parsedParams = parse(textline, line_model, SIZE, line_model_replace)
	if (parsedParams == 2)
	{
	format(model_path, charsmax(model_path), "models/max/%s.mdl",line_model_replace)
	precache_model(model_path);
	p_modelsnum++;
	}
	if (parsedParams != 2)
	continue	// Send warning/error?
    }
    return PLUGIN_HANDLED;
}

public Event_CurWeapon(id) 
{     
    new szModel[32] , szReplace[32], parsedParams;
    new conffile_mdl[200];
    new configdir_mdl[200];
    get_configsdir(configdir_mdl,199)
    format(conffile_mdl,199,"%s/weapons-models.ini",configdir_mdl)
    for(new i=0;i<p_modelsnum;i++)
    {
    	new buffer;
	read_file(conffile_mdl, i, file_model, 127, buffer)
	parsedParams = parse(file_model,szModel,charsmax(szModel),szReplace,charsmax(szReplace))
	if (parsedParams == 2)
	{
		set_pev(id,pev_viewmodel2,szReplace[i]);
		set_pev(id,pev_weaponmodel2,szReplace[i]);
	}
	if (parsedParams != 2)
	continue		
    }
    return PLUGIN_CONTINUE;	
}

public fw_SetModel(entity, model[])
{
    new szModel[32] , szReplace[32], parsedParams;
    new conffile_mdl[200];
    new configdir_mdl[200];
    get_configsdir(configdir_mdl,199)
    format(conffile_mdl,199,"%s/weapons-models.ini",configdir_mdl)
    for(new i=0;i<p_modelsnum;i++)
    {
    	new buffer;
	read_file(conffile_mdl, i, file_model, 127, buffer)
	parsedParams = parse(file_model,szModel,charsmax(szModel),szReplace,charsmax(szReplace))
	if (parsedParams == 2)
	{
		engfunc(EngFunc_SetModel, entity, szReplace)
		return FMRES_SUPERCEDE
	}
	if (parsedParams != 2)
	continue		
    }
    return FMRES_IGNORED
}
DarthMan is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-07-2017 , 06:29   Re: Weapon Change Model
Reply With Quote #2

This already been made.. Try to search
__________________
@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
DarthMan
Veteran Member
Join Date: Aug 2011
Old 03-07-2017 , 07:34   Re: Weapon Change Model
Reply With Quote #3

Quote:
Originally Posted by Natsheh View Post
This already been made.. Try to search
It is, but it's mostly for CS and it crashes some of my server maps like arcticescape_r for an unknown reason.
DarthMan is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-07-2017 , 08:36   Re: Weapon Change Model
Reply With Quote #4

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>
#include <tfcx>

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

new const FILE[] = "weapons_models.ini";
new const 
DIRECTOR[] = "addons/amxmodx/configs";

new Array:
g_arraygarraysize;

public 
plugin_precache()
{
    
g_array ArrayCreate(641)
    
garraysize xmod_get_maxweapons();
    for(new 
0garraysizei++)
        
ArrayPushString(g_array"")
    
    static 
strFile[64];
    
formatex(strFile63"%s/%s"DIRECTORFILE)
    
    if(!
file_exists(strFile)) return; // file isnt exists
    
new fp fopen(strFile"rt")
    if(!
fp) return; // file isnt exists or failed to open.
    
new sBuffer[128], sParam[2][64], paramj;
    
    while(!
feof(fp)) // reading file line by line
    
{
        
fgets(fpsBuffer127// getting line info..
        
trim(sBuffer//. trim all spaces..
        
        
if(sBuffer[0] == ';' || sBuffer[0] == '/' && sBuffer[1] == '/' || strlen(sBuffer) <= 3) continue;
        
        
param parse(sBuffersParam[0], charsmax(sParam[]), sParam[1], charsmax(sParam[]))
        if(
param != 2) continue;
        for(
0<= charsmax(sParam); j++)
            
remove_quotes(sParam[j]);
        
        if(
tfc_weapon_exists(sParam[0]))
        {
            
ArraySetString(g_arrayjsParam[1])
        }
    }
    
    
fclose(fp// closing the file...,after we  finished from it
}

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_forward(FM_SetModel"fw_SetModel_pre")
}

public 
fw_SetModel_pre(const ent, const model[])
{
    if(!
pev_valid(ent)) // if its an entity ( NOT A WORLD )
        
return FMRES_IGNORED;
    
    if(
containi(model"w_") != -&& pev(entpev_owner) == 0)
    {
        new 
sName[32], sModel[64];
        
xmod_get_wpnname(ent,sName,31)
        new 
tfc_weapon_exists(sName)
        if(
== -1) return FMRES_IGNORED;
        
ArrayGetString(g_arrayjsModelcharsmax(sModel))
        
set_pev(entpev_modelsModel)
        return 
FMRES_SUPERCEDE;
    }
    return 
FMRES_IGNORED;
}

stock tfc_weapon_exists(const weapon[])
{
    new 
sWpnname[32], i;
    for(
0garraysizei++)
    {
        
xmod_get_wpnname(i,sWpnname,charsmax(sWpnname))
        if(
equali(sWpnnameweapon))
        {
            return 
i;
        }
    }
    return -
1;

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


Last edited by Natsheh; 03-07-2017 at 08:54.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
DarthMan
Veteran Member
Join Date: Aug 2011
Old 03-07-2017 , 13:33   Re: Weapon Change Model
Reply With Quote #5

Quote:
Originally Posted by Natsheh View Post
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>
#include <tfcx>

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

new const FILE[] = "weapons_models.ini";
new const 
DIRECTOR[] = "addons/amxmodx/configs";

new Array:
g_arraygarraysize;

public 
plugin_precache()
{
    
g_array ArrayCreate(641)
    
garraysize xmod_get_maxweapons();
    for(new 
0garraysizei++)
        
ArrayPushString(g_array"")
    
    static 
strFile[64];
    
formatex(strFile63"%s/%s"DIRECTORFILE)
    
    if(!
file_exists(strFile)) return; // file isnt exists
    
new fp fopen(strFile"rt")
    if(!
fp) return; // file isnt exists or failed to open.
    
new sBuffer[128], sParam[2][64], paramj;
    
    while(!
feof(fp)) // reading file line by line
    
{
        
fgets(fpsBuffer127// getting line info..
        
trim(sBuffer//. trim all spaces..
        
        
if(sBuffer[0] == ';' || sBuffer[0] == '/' && sBuffer[1] == '/' || strlen(sBuffer) <= 3) continue;
        
        
param parse(sBuffersParam[0], charsmax(sParam[]), sParam[1], charsmax(sParam[]))
        if(
param != 2) continue;
        for(
0<= charsmax(sParam); j++)
            
remove_quotes(sParam[j]);
        
        if(
tfc_weapon_exists(sParam[0]))
        {
            
ArraySetString(g_arrayjsParam[1])
        }
    }
    
    
fclose(fp// closing the file...,after we  finished from it
}

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_forward(FM_SetModel"fw_SetModel_pre")
}

public 
fw_SetModel_pre(const ent, const model[])
{
    if(!
pev_valid(ent)) // if its an entity ( NOT A WORLD )
        
return FMRES_IGNORED;
    
    if(
containi(model"w_") != -&& pev(entpev_owner) == 0)
    {
        new 
sName[32], sModel[64];
        
xmod_get_wpnname(ent,sName,31)
        new 
tfc_weapon_exists(sName)
        if(
== -1) return FMRES_IGNORED;
        
ArrayGetString(g_arrayjsModelcharsmax(sModel))
        
set_pev(entpev_modelsModel)
        return 
FMRES_SUPERCEDE;
    }
    return 
FMRES_IGNORED;
}

stock tfc_weapon_exists(const weapon[])
{
    new 
sWpnname[32], i;
    for(
0garraysizei++)
    {
        
xmod_get_wpnname(i,sWpnname,charsmax(sWpnname))
        if(
equali(sWpnnameweapon))
        {
            return 
i;
        }
    }
    return -
1;

This one's not working but thanks anyway for trying.
DarthMan is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 03-07-2017 , 13:52   Re: Weapon Change Model
Reply With Quote #6

I am looking for a content replacer for weapons that works with TFC
DarthMan 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 17:48.


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