PDA

View Full Version : Setting Model Body


Drak
04-30-2008, 18:55
I'm trying to make the scope on Half-Life's 357 weapon. (It's in the model, second body)
Setting "pev_body" doesn't work, alone atleast. This is how I'm doing it:

UTIL_SetModel(id,bool:OnOff)
{
new ent = fm_get_user_weapon_entity(id);

if(ent)
{
if(OnOff)
{
set_pev(ent,pev_body,1);
_UTIL_SendWpnAnination(id,5,1,ent);
}
else
{
set_pev(ent,pev_body,0);
_UTIL_SendWpnAnination(id,0,0,ent);
}
}
}


_UTIL_SendWpnAnination(id,anim,body,ent)
{
set_pev(id,pev_viewmodel2,"models/v_357.mdl");
message_begin(MSG_ONE,SVC_WEAPONANIM,{0,0,0}, id);
write_byte(anim);
write_byte(pev(ent,pev_body))
message_end();
}

// Below code is copied from fakemeta_util.inc by VEN
// if weapon index isn't passed then assuming that it's the current weapon
stock fm_get_user_weapon_entity(id, wid = 0)
{
new weap = wid, clip, ammo
if (!weap && !(weap = get_user_weapon(id, clip, ammo)))
return 0

new class[32]
get_weaponname(weap, class, sizeof class - 1)

return fm_find_ent_by_owner(-1, class, id)
}

stock fm_find_ent_by_owner(index, const classname[], owner, jghgtype = 0)
{
new strtype[11] = "classname", ent = index
switch (jghgtype) {
case 1: strtype = "target"
case 2: strtype = "targetname"
}

while ((ent = engfunc(EngFunc_FindEntityByString, ent, strtype, classname)) && pev(ent, pev_owner) != owner) {}

return ent
}

When setting the model "UTIL_SetModel(id,true)" works. Soon as the weapon plays an animation, the body is set back to zero. Putting "UTIL_SetModel" in prethink, doesn't seem like a good idea. Even though it works. Is there anyway other way I can get this to work?

Styles
04-30-2008, 19:21
During ClientUpdatePlayerData or w/e why don't you just update the animation?

Drak
04-30-2008, 19:48
During ClientUpdatePlayerData or w/e why don't you just update the animation?
Example?
I made this really quick. But I guess it calls every frame.
So it costently set's it body, and then "freezes" the animations, and they won't play.

public forward_UpdateClientData(id,iSendWeapons,cd_h andle)
{
if(!is_user_alive(id) || !get_pcvar_num(p_Enable))
return FMRES_HANDLED

new clip,ammo
if(get_user_weapon(id,clip,ammo) == HLW_PYTHON)
{
//UTIL_SetModel(id,get_pcvar_num(p_Model) ? true : false);
UTIL_SetModel(id,true);
}

return FMRES_HANDLED
}

Styles
04-30-2008, 20:32
You could try setting the animation if they are not in a specific one already. Like

pev(id, pev_gaitsequence) != 1

Idk what seq # you would want but yeah. if its not that already, then set it.

Drak
04-30-2008, 21:02
You could try setting the animation if they are not in a specific one already. Like

pev(id, pev_gaitsequence) != 1

Idk what seq # you would want but yeah. if its not that already, then set it.
The thing is, I don't want to set any animations, I have to for the 'updated' body to take effect. And I'm trying to figure out a way to set it, without having to send any weapon animations. Since, If I do. They get all screwy and what not.