PDA

View Full Version : Rememering Weapons


Mini_Midget
04-29-2008, 01:21
#include <amxmodx>
#include <fakemeta>

new bool: g_sprint[33]
new cvar_speed

public plugin_init()
{
register_plugin("Sprint", "0.1", "Mini_Midget");
cvar_speed = register_cvar("sprint_speed", "400");
register_forward(FM_CmdStart, "FW_CmdStart" );
register_forward(FM_PlayerPreThink, "FW_PreThink" );
register_forward(FM_UpdateClientData, "FW_UpdateClientData", 1)

}

public client_putinserver(id)
{
g_sprint[id] = false
}

public FW_CmdStart( id, uc_handle, randseed )
{
if (!is_user_alive(id))
return FMRES_IGNORED

new Float:fmove, Float:smove;
get_uc(uc_handle, UC_ForwardMove, fmove);
get_uc(uc_handle, UC_SideMove, smove );

new Float:maxspeed;
pev(id, pev_maxspeed, maxspeed);
new Float:walkspeed = (maxspeed * 0.52);
fmove = floatabs( fmove );
smove = floatabs( smove );

if(fmove <= walkspeed && smove <= walkspeed && !(fmove == 0.0 && smove == 0.0))
{
//client_print( id, print_center, "WALKING" );
g_sprint[id] = true
}
else
{
//client_print( id, print_center, "RUNNING" );
g_sprint[id] = false
}

return FMRES_IGNORED
}

public FW_PreThink(id)
{
if (!is_user_alive(id))
return FMRES_IGNORED

static flag ; flag = pev(id, pev_flags)
static button ; button = pev(id, pev_button)

//Block not on ground or ducking or left, back, right movement keys
if ( !(flag & FL_ONGROUND) || (flag & FL_DUCKING) || !(button & IN_FORWARD) )
return FMRES_IGNORED

static Float: sprinting[3], Float: normal[3]
static speed ; speed = get_pcvar_num(cvar_speed)

velocity_by_aim(id, speed, sprinting) //Speed
pev(id, pev_velocity, normal)
sprinting[2] = normal[2]

if (g_sprint[id] == true) //Walking
{
set_pev(id, pev_velocity, sprinting) //Set the speed of sprinting
set_pev(id, pev_button, button & ~IN_ATTACK );
set_pev(id, pev_button, button & ~IN_ATTACK2 );
//engclient_cmd(id, "weapon_knife")
//set_pev(id, pev_viewmodel2, "")
}
else if (g_sprint[id] == false) //Running
{
set_pev(id, pev_velocity, normal) //Return to normal speed
}

return FMRES_IGNORED
}

public FW_UpdateClientData(id, sendweapons, cd_handle )
{
if ( !is_user_alive(id) || !g_sprint[id] || !(pev(id, pev_button) & IN_FORWARD) )
return FMRES_IGNORED;

set_cd(cd_handle, CD_ID, 0);

return FMRES_HANDLED;
}


While sprinting, I'm trying to make it you have nothing in your hands rather than running around with your knife. But the problem is when I set the view model to nothing. It will stay like that even if you change weapons and such. What I want to do is to remember the weapon you had BEFORE you started sprinting so then I can set the view model back to normal when you stop sprinting.

I also want to try and make a small delay before you can fire when you just release the sprint key.

Alka
04-29-2008, 01:38
Take a look at BlockMaker[BM]...when you move a block the weapon model is hided, then restored.

EDIT:Store the model where you set the "g_sprint[id] = true;" (or w/e when you start sprinting...) in a global string "new g_WpnModel[32][33]" "pev(id, pev_viewmodel, g_WpnModel[id])" then hide the model using model name ""...and when you stop sprinting...set back the old model.

v3x
04-29-2008, 02:44
set_pev(id, pev_weaponmodel, "");
set_pev(id, pev_weaponmodel2, "");Try that in your PreThink code where you check if he's sprinting.

You could also try pev_viewmodel2.

Mini_Midget
04-29-2008, 03:41
I did what you guys told me but it doesn't work the way I want it to.
It makes the viewmodel to nothing ONLY when I press the FORWARD key. Very odd.... It also doesn't set the model back to the way it was before unless I change weapon. For some reason, I can shoot while sprinting forward now... I thought I blocked it...?

@v3x
weaponmodel(2) is used to change the player models. Such as p_ak47, p_m4a1 and so on.


#include <amxmodx>
#include <fakemeta>

new bool: g_sprint[33]
new g_WpnModel[32][33]
new cvar_speed

public plugin_init()
{
register_plugin("Sprint", "0.1", "Mini_Midget");
cvar_speed = register_cvar("sprint_speed", "400");
register_forward(FM_CmdStart, "FW_CmdStart" );
register_forward(FM_PlayerPreThink, "FW_PreThink" );
register_forward(FM_UpdateClientData, "FW_UpdateClientData", 1)

}

public client_putinserver(id)
{
g_sprint[id] = false
}

public FW_CmdStart( id, uc_handle, randseed )
{
if (!is_user_alive(id))
return FMRES_IGNORED

new Float:fmove, Float:smove;
get_uc(uc_handle, UC_ForwardMove, fmove);
get_uc(uc_handle, UC_SideMove, smove );

new Float:maxspeed;
pev(id, pev_maxspeed, maxspeed);
new Float:walkspeed = (maxspeed * 0.52);
fmove = floatabs( fmove );
smove = floatabs( smove );

if(fmove <= walkspeed && smove <= walkspeed && !(fmove == 0.0 && smove == 0.0))
{
//client_print( id, print_center, "WALKING" );
g_sprint[id] = true
}
else
{
//client_print( id, print_center, "RUNNING" );
g_sprint[id] = false
}

return FMRES_IGNORED
}

public FW_PreThink(id)
{
if (!is_user_alive(id))
return FMRES_IGNORED

static flag ; flag = pev(id, pev_flags)
static button ; button = pev(id, pev_button)

//Block not on ground or ducking or left, back, right movement keys
if ( !(flag & FL_ONGROUND) || (flag & FL_DUCKING) || !(button & IN_FORWARD) )
return FMRES_IGNORED

static Float: sprinting[3], Float: normal[3]
static speed ; speed = get_pcvar_num(cvar_speed)

velocity_by_aim(id, speed, sprinting) //Speed
pev(id, pev_velocity, normal)
sprinting[2] = normal[2]

if (g_sprint[id] == true) //Walking
{
set_pev(id, pev_velocity, sprinting) //Set the speed of sprinting
set_pev(id, pev_button, button & ~IN_ATTACK );
set_pev(id, pev_button, button & ~IN_ATTACK2 );

pev(id, pev_viewmodel2, g_WpnModel[id])
set_pev(id, pev_viewmodel2, "")
//engclient_cmd(id, "weapon_knife")
//set_pev(id, pev_viewmodel2, "")
}
else if (g_sprint[id] == false) //Running
{
set_pev(id, pev_velocity, normal) //Return to normal speed
set_pev(id, pev_viewmodel2, g_WpnModel[id], 32)
}

return FMRES_IGNORED
}

public FW_UpdateClientData(id, sendweapons, cd_handle )
{
if ( !is_user_alive(id) || !g_sprint[id] || !(pev(id, pev_button) & IN_FORWARD) )
return FMRES_IGNORED;

set_cd(cd_handle, CD_ID, 0);

return FMRES_HANDLED;
}

v3x
04-29-2008, 05:41
It makes the viewmodel to nothing ONLY when I press the FORWARD key. Very odd....
That's because you have a check for that. You check if the player isn't holding the button, then you make a return. That's your problem right there.

Mini_Midget
05-02-2008, 11:01
Oh yeah....
I solved that problem now but I still can't seem to make the "none" view model back to normal.
Also, I noticed that I can only block one button at a time if I do this.

set_pev(id, pev_button, button & ~IN_ATTACK)
set_pev(id, pev_button, button & ~IN_ATTACK2 );

It'll only block ATTACK2. I can't think of anyway to block both attacks.
I tried...

set_pev(id, pev_button, ( (button &~IN_ATTACK) (button &~IN_ATTACK2)))


This is what I have so far.


#include <amxmodx>
#include <fakemeta>

new bool: g_sprint[33]
new g_WpnModel[32][33]
new cvar_speed

public plugin_init()
{
register_plugin("Sprint", "0.1", "Mini_Midget");
cvar_speed = register_cvar("sprint_speed", "400");
register_forward(FM_CmdStart, "FW_CmdStart" );
register_forward(FM_PlayerPreThink, "FW_PreThink" );
register_forward(FM_UpdateClientData, "FW_UpdateClientData", 1)

}

public client_putinserver(id)
{
g_sprint[id] = false
}

public FW_CmdStart( id, uc_handle, randseed )
{
if (!is_user_alive(id))
return FMRES_IGNORED

new Float:fmove, Float:smove;
get_uc(uc_handle, UC_ForwardMove, fmove);
get_uc(uc_handle, UC_SideMove, smove );

new Float:maxspeed;
pev(id, pev_maxspeed, maxspeed);
new Float:walkspeed = (maxspeed * 0.52);
fmove = floatabs( fmove );
smove = floatabs( smove );

if(fmove <= walkspeed && smove <= walkspeed && !(fmove == 0.0 && smove == 0.0))
{
//client_print( id, print_center, "WALKING" );
g_sprint[id] = true
}
else
{
//client_print( id, print_center, "RUNNING" );
g_sprint[id] = false
}

return FMRES_IGNORED
}

public FW_PreThink(id)
{
if (!is_user_alive(id))
return FMRES_IGNORED

static flag ; flag = pev(id, pev_flags)
static button ; button = pev(id, pev_button)

//Block not on ground or ducking
if ( !(flag & FL_ONGROUND) || (flag & FL_DUCKING))
return FMRES_IGNORED

static Float: sprinting[3], Float: normal[3]
static speed ; speed = get_pcvar_num(cvar_speed)

velocity_by_aim(id, speed, sprinting) //Speed
pev(id, pev_velocity, normal)
sprinting[2] = normal[2]

if (g_sprint[id] && (button & IN_FORWARD))
{
set_pev(id, pev_velocity, sprinting) //Set the speed of sprinting
set_pev(id, pev_button, button & ~IN_ATTACK)
//set_pev(id, pev_button, button & ~IN_ATTACK2 );

pev(id, pev_viewmodel2, g_WpnModel[id], 32)
set_pev(id, pev_viewmodel2, "")
//engclient_cmd(id, "weapon_knife")
//set_pev(id, pev_viewmodel2, "")
}
else // if (!g_sprint[id]) //Running
{
set_pev(id, pev_velocity, normal) //Return to normal speed
set_pev(id, pev_viewmodel2, g_WpnModel[id], 32)
}

return FMRES_IGNORED
}

public FW_UpdateClientData(id, sendweapons, cd_handle )
{
if ( !is_user_alive(id) || !g_sprint[id] || !(pev(id, pev_button) & IN_FORWARD) )
return FMRES_IGNORED;

set_cd(cd_handle, CD_ID, 0);

return FMRES_HANDLED;
}

Alka
05-02-2008, 14:01
Hmm, this should work

set_pev(id, pev_button, ((button & ~IN_ATTACK) | (button & ~IN_ATTACK2)));

Mini_Midget
05-03-2008, 01:30
Nope, that didn't work either. But this does...

set_pev(id, pev_button, ((button & ~IN_ATTACK) & (button & ~IN_ATTACK2)));


Now... How am I gonna solve my model bug? Everything seems fine but it doesn't work how I want it to.