AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   emit_sound and model changing (https://forums.alliedmods.net/showthread.php?t=61638)

Mini_Midget 10-06-2007 07:47

emit_sound and model changing
 
The plugin is making the M249/Para fire faster. (No problems here)

The trouble is trying to change to M249 to my own custom model.
I'm using CurWeapon event at the moment but I'm also using it to detect a gun shot. Right now, I made it so it changes the model when the player FIRES the M249. Not when he actually has first when he switched to it.
Just wondering if theres another way around this besides event CurWeapon?

Also, my emit_sound line has an error on it. I have no idea whats wrong with it. Maybe you guys can take a look at it.
Code:

\my local folder\mini_gun.sma(147) : error 035: argument type mismatch (argument 3)
PHP Code:

#include <amxmodx>
#include <fakemeta>

#define PLUGIN "Mini-Gun"
#define VERSION "1.1"
#define AUTHOR "Mini_Midget"        

new VIEW_MODEL[]        = "models/mini_gun/v_minigun.mdl" 
new PLAYER_MODEL[]        = "models/mini_gun/p_minigun.mdl" 
new WORLD_MODEL[]    = "models/mini_gun/w_minigun.mdl"

new OLDWORLD_MODEL[]    = "models/w_m249.mdl"

#define M249_SHOT 2
new const g_M249SHOT[M249_SHOT][] = 
{
    
"weapons/m249-1.wav",
    
"weapons/m249-2.wav"
}

#define MINIGUN_SHOT 2
new const g_MINIGUN_SHOT[] = 
{
    
"mini_gun/mini_gun1.wav",
    
"mini_gun/mini_gun2.wav"
}

new 
cvar_rofcvar_speed
new g_CurWeap[33][2]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event"CurWeapon""Event_WeaponFire",  "b" )
    
register_event"CurWeapon""Event_ChangeWeapon",  "be""1=1" )
    
    
register_forward(FM_SetModel"fw_SetModel" )
    
register_forwardFM_EmitSound"fw_EmitSound" )
    
    
cvar_rof register_cvar"mg_rof""0.02" )
    
cvar_speed register_cvar"mg_speed""165" )
}

public 
plugin_precache() 
{    
    
precache_model(VIEW_MODEL)     
    
precache_model(PLAYER_MODEL
    
precache_model(WORLD_MODEL)
    
    for (new 
M249_SHOT i++ )
    {
        
precache_sound(g_M249SHOT[i])
        
precache_sound(g_MINIGUN_SHOT[i])
    }


public 
Event_WeaponFireid 

    new 
weapon read_data
    new 
ammo read_data
    
    if( 
g_CurWeap[id][0] != weapon // User Changed Weapons.. 
    

        
g_CurWeap[id][0] = weapon 
        g_CurWeap
[id][1] = ammo 
        
return PLUGIN_CONTINUE 
    

    if( 
g_CurWeap[id][1] < ammo // User Reloaded.. 
    

        
g_CurWeap[id][1] = ammo 
        
return PLUGIN_CONTINUE 
    

    if( 
g_CurWeap[id][1] == ammo // User did something else, but didn't shoot.. 
        
return PLUGIN_CONTINUE 
    
    g_CurWeap
[id][1] = ammo 
    g_CurWeap
[id][0] = weapon 
    
    
if(weapon == CSW_M249)
    {
        new 
weap[32]
        
get_weaponname(weapon,weap,31)
        new 
ent fm_find_ent_by_owner(-1,weap,id)
        if(
ent)
        {
            new 
Float:nextattack get_pdata_float(ent,46,4)
            if (
nextattack 0.0)
            {
                new 
Float:changednextattack nextattack get_pcvar_floatcvar_rof 
                if (
changednextattack 0.0)
                    
set_pdata_float(ent,46,changednextattack,4)
            }
        }
        
    }  
    return 
PLUGIN_CONTINUE
}

public 
Event_ChangeWeapon id )
{
    new 
weapon read_data )
    
    if ( 
weapon != CSW_M249 )
        return 
PLUGIN_HANDLED
    
    fm_set_user_maxspeed 
id get_pcvar_float cvar_speed ) )
    
set_pev idpev_viewmodel2VIEW_MODEL )        
    
set_pev idpev_weaponmodel2PLAYER_MODEL )
    
    
    return 
PLUGIN_CONTINUE
}

public 
fw_SetModel entitymodel[] )
{
    if (!
pev_valid(entity)) 
        return 
FMRES_IGNORED
    
    
if (!equali(modelOLDWORLD_MODEL)) 
        return 
FMRES_IGNORED
    
    
new className[33]
    
pev (entitypev_classnameclassName32)
    
    if (
equal(className"weaponbox") || equal(className"armoury_entity"))
    {
        
engfunc(EngFunc_SetModelentityWORLD_MODEL)
        return 
FMRES_SUPERCEDE
    
}
    return 
FMRES_IGNORED
}

public 
fw_EmitSound(idchannelsample[])
{    
    if ( !
is_user_alive id ) )
        return 
FMRES_IGNORED
    
    
for ( new iCount iCount MINIGUN_SHOT iCount++ )
        if ( 
equali sampleg_MINIGUN_SHOT[iCount] ) )
        {
            
engfunc EngFunc_EmitSoundidCHAN_WEAPONg_MINIGUN_SHOT[random_num(0MINIGUN_SHOT 1)], VOL_NORMATTN_NORM0PITCH_NORM )
            return 
FMRES_SUPERCEDE
        
}
    
    return 
FMRES_IGNORED
}

stock fm_find_ent_by_owner (index, const classname[], ownerjghgtype 0
{
    new 
strtype[11] = "classname"ent index
    
switch (jghgtype
    {
        case 
1strtype "target"
            
case 2strtype "targetname"
        
}
    
    while ((
ent engfunc(EngFunc_FindEntityByStringentstrtypeclassname)) && pev(entpev_owner) != owner) {}
    
    return 
ent
}

stock fm_set_user_maxspeed(indexFloat:speed = -1.0
{
    
engfunc(EngFunc_SetClientMaxspeedindexspeed)
    
set_pev(indexpev_maxspeedspeed)

    return 
1


EDIT:
I just edited the plugin a bit and decided to use EngFunc_EmitSound.
It compiles now but when I test it. It is still the default sounds in CS.
I've got the changing model thingy to work now. I'm just gonna use 2 curweapon events.
This emit sound thingy is really pissing me off because it just won't work. I've tried many methods and non work at all.

Wilson [29th ID] 10-10-2007 05:36

Re: emit_sound and model changing
 
Code:
#define MINIGUN_SHOT 2 new const g_MINIGUN_SHOT[] = {     "mini_gun/mini_gun1.wav",     "mini_gun/mini_gun2.wav" }

Now look at that....you have a big typo there. It's a one dimension array filled with two dimensions...you forgot a set of brackets :P
(Should be g_MINIGUN_SHOT[MINIGUN_SHOT][])

Apart from that, remove the const part to stop getting the warning.

purple_pixie 10-10-2007 05:52

Re: emit_sound and model changing
 
I don't think you can edit Weapon sounds by hooking EmitSound.

See GHW_Chronic's weapon model/sound replacer - same problem.

I assume there is some other way to do it ... maybe it just doesn't pass the right id (0 ?)

Wilson [29th ID] 10-10-2007 09:06

Re: emit_sound and model changing
 
Oh yeah, that too. The way to do it is to hook FM_PlayBackEvent and supercede it with one of your own.

Problem is, the client that is firing still hear's the sound. The only way around this is either to stop the attack and create your own bullet or to use hamsandwich for a really complex workaround.

purple_pixie 10-10-2007 11:13

Re: emit_sound and model changing
 
Both sound like far too much fun to avoid ... I might have to play with this later :-D


All times are GMT -4. The time now is 16:11.

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