PDA

View Full Version : [L4D2]Need Grenade Launcher's Grenade to move faster.


Bakuryu
01-02-2012, 15:59
I'm turning the Grenade Launcher into a rocket launcher(kinda) I want it to behave similar to how the rocket launcher from TF2's soldier works. I got it to shoot straight the problem is now the cross hair doesn't match the destination. Also I can't for the life of my figure out how to make it move faster without the "rocket" flipping out or going in a weird direction. I tried it with every property that mentions velocity in datamaps, I tried it with setting the entitys property and using the teleportentity function. Everytime it shoots fast, but in a weird direction.

public OnEntityCreated(entity, const String:classname[])
{
if(StrEqual(classname, "grenade_launcher_projectile", false))
{
//SDKHook(entity, SDKHook_SpawnPost, BoostGrenade);
CreateTimer(0.1, BoostGrenade,entity);


}
}


public Action:BoostGrenade(Handle:timers, any:entity)
{

new client=GetEntPropEnt(entity,Prop_Send, "m_hOwnerEntity");
if (issoldier[client])
{
SetEntProp(entity, Prop_Send, "movetype", 4);
decl Float:vVelocity[3]
GetEntPropVector(entity, Prop_Data, "m_vecVelocity", vVelocity);
ScaleVector(vVelocity, 50.00);
SetEntPropVector(entity, Prop_Data, "m_vecVelocity", vVelocity);
//TeleportEntity(entity, NULL_VECTOR, NULL_VECTOR, vVelocity);
}
}

McFlurry
01-02-2012, 16:33
There's a bunch of cvars to control the grenade launcher already built into the game.


"grenadelauncher_damage" = "400"
game cheat
"grenadelauncher_ff_scale" = "0.12"
game cheat
- ff scale for grenade launcher damage to other players
"grenadelauncher_ff_scale_self" = "0.12"
game cheat
- ff scale for grenade launcher damage to other players
"grenadelauncher_force_kill" = "2000.0"
game cheat
"grenadelauncher_radius_kill" = "180"
game cheat
"grenadelauncher_radius_stumble" = "250"
game cheat
"grenadelauncher_show_radius" = "0"
game cheat
"grenadelauncher_startpos_forward" = "16.0"
game
"grenadelauncher_startpos_right" = "4.0"
game
"grenadelauncher_startpos_up" = "0.0"
game
"grenadelauncher_vel_up" = "100.0f"
game
"grenadelauncher_vel_variance" = "10.0"
game
"grenadelauncher_velocity" = "1200"
game cheat

Your code wouldn't work, as you try to boost the grenade launcher itself.

Bakuryu
01-02-2012, 16:49
The entity is specified as the grenade launcher projectile so it wont effect the gun, unless its the gun I need to change? Also I need this to be on a player basis so using cvars will make it global.

MasterMind420
01-02-2012, 16:54
Check out Silvers "Flaregun" plugin, does all kinds of cool stuff with the grenade launcher.

McFlurry
01-02-2012, 16:58
The entity is specified as the grenade launcher projectile so it wont effect the gun, unless its the gun I need to change? Also I need this to be on a player basis so using cvars will make it global.
I misread the entity name, sorry about that. Also try hooking SpawnPost with SDK Hooks when the projectile is created, and boost it there.

Bakuryu
01-02-2012, 17:02
I misread the entity name, sorry about that. Also try hooking SpawnPost with SDK Hooks when the projectile is created, and boost it there.
I did it still works, but It still is wonky when I mess with the teleport function.

current code does nothing
public OnEntityCreated(entity, const String:classname[])
{
if(StrEqual(classname, "grenade_launcher_projectile", false))
{
SDKHook(entity, SDKHook_SpawnPost, BoostGrenade);
//CreateTimer(0.1, BoostGrenade,entity);


}
}


public Action:BoostGrenade(entity)
{

new client=GetEntPropEnt(entity,Prop_Send, "m_hOwnerEntity");
if (issoldier[client])
{
//SetEntProp(entity, Prop_Send, "movetype", 4);
decl Float:vVelocity[3]
//decl Float:vOrigin[3]
//decl Float:vAngle[3]
GetEntPropVector(entity, Prop_Data, "m_vecVelocity", vVelocity);
//GetEntPropVector(entity,Prop_Data, "m_vecOrigin", vOrigin);
//GetEntPropVector(entity,Prop_Data, "m_angRotation", vAngle);
ScaleVector(vVelocity, 500.0);
//ScaleVector(vOrigin, 50.0);
//ScaleVector(vAngle, 900.0);
SetEntPropVector(entity, Prop_Data, "m_vecVelocity", vVelocity);
//TeleportEntity(entity, NULL_VECTOR, NULL_VECTOR, vVelocity);
}
}

McFlurry
01-02-2012, 17:06
Silvers uses "m_vInitialVelocity" instead of "m_vecVelocity". Try using that(Prop_Send).

Bakuryu
01-02-2012, 17:11
Is that still a vector? if not that might be why its not working because im still using scale vector, otherwise it didn't work with either Prop_Data or Prop_Send

McFlurry
01-02-2012, 17:21
It's a vector, most props come with letters that tell what type, such as v, b, fl, i.

Bakuryu
01-02-2012, 17:23
Yea it doesnt work sadly I tried both with Teleport and just setting the vectors. I commented it out but setpropent movetype to 4 makes it go straight like I wan't but I still can't make it go faster. I though maybe the movement type was messing it up, but it doesn't seem to be the case. Actually now that I think about it I don't think anything besides that is working maybe the timer is still the only way?

Edit: Yep the hooks aren't working the timer works though. Did I do the hook wrong?

McFlurry
01-02-2012, 17:34
SpawnPost doesn't have Action: in front of it, but I don't know if that would actually break the hook.

Bakuryu
01-02-2012, 17:39
The prototype doesn't need Action only the function does. At least that's what I saw when I made it.

Bakuryu
01-02-2012, 19:15
This kinda works, something I noticed is the scale has to be very high for there to be any noticeable difference which leads me to believe this worked before and I didn't realize it. The only problem right now is it still seems to be crooked at the beginning which I am guessing is because of the timer and its not hitting where the cross hair is. Any suggestion on how to fix that? I guess id find the initial origin and then reposition it, but to where and how setentpropvector?



public OnEntityCreated(entity, const String:classname[])
{
if(StrEqual(classname, "grenade_launcher_projectile", false))
{
//SDKHook(entity, SDKHook_SpawnPost, BoostGrenade);
CreateTimer(0.1, BoostGrenade,entity);


}
}


public Action:BoostGrenade(Handle:timer, any:entity)
{

new client=GetEntPropEnt(entity,Prop_Send, "m_hOwnerEntity");
if (issoldier[client])
{
SetEntProp(entity, Prop_Send, "movetype", 4);
decl Float:vVelocity[3]
//decl Float:vOrigin[3]
//decl Float:vAngle[3]
GetEntPropVector(entity, Prop_Send, "m_vInitialVelocity", vVelocity);
//GetEntPropVector(entity,Prop_Data, "m_vecOrigin", vOrigin);
//GetEntPropVector(entity,Prop_Data, "m_angRotation", vAngle);
NormalizeVector(vVelocity,vVelocity);
ScaleVector(vVelocity, 3500.0);
//ScaleVector(vOrigin, 50.0);
//ScaleVector(vAngle, 500.0);
//SetEntPropVector(entity, Prop_Send, "m_vInitialVelocity", vVelocity);
TeleportEntity(entity, NULL_VECTOR, NULL_VECTOR, vVelocity);
}
}

Silvers
01-03-2012, 06:35
View the way I did the scaling, the maths might eventually boost it to that number I never viewed the results. You do need to create a delay, what I did was set the default speed to 1 so that the projectile would not explode when shot at a wall, this also allows the 0.1 timer to finally trigger and then you can apply the velocity. I was testing with SDKHooks_OnSpawnPost but it seemed the velocity (which tells the direction the grenade is heading) was always 0.0,0.0,0.0. Also check out the up velocity cvar from Valve, that will control if it's inside the crosshair or above/down.

Bakuryu
01-03-2012, 11:49
View the way I did the scaling, the maths might eventually boost it to that number I never viewed the results. You do need to create a delay, what I did was set the default speed to 1 so that the projectile would not explode when shot at a wall, this also allows the 0.1 timer to finally trigger and then you can apply the velocity. I was testing with SDKHooks_OnSpawnPost but it seemed the velocity (which tells the direction the grenade is heading) was always 0.0,0.0,0.0. Also check out the up velocity cvar from Valve, that will control if it's inside the crosshair or above/down.
Are you refering to you Flare Gun? I haven't check it out yet, but I need it to explode. Where do I find the cvar for up velocity? Keep in mind this has work on a player basis.

Bakuryu
01-04-2012, 01:12
I think I got it to work, its not perfect, but it will do for now, it lags a little at the beginning before the code takes effect.

public OnEntityCreated(entity, const String:classname[])
{
if(StrEqual(classname, "grenade_launcher_projectile", false))
{
//SDKHook(entity, SDKHook_SpawnPost, BoostGrenade);
CreateTimer(0.1, BoostGrenade,entity);
}

if(StrEqual(classname, "grenade_launcher", false))
{
SetEntProp(entity,Prop_Send, "m_iExtraPrimaryAmmo", 3);
}

}

public Action:BoostGrenade(Handle:timer, any:entity)
{

new client=GetEntPropEnt(entity,Prop_Send, "m_hOwnerEntity");
if (issoldier[client])
{
SetEntProp(entity, Prop_Send, "movetype", 4);
decl Float:vVel[3]
decl Float:vAng[3]
decl Float:vPos[3]
decl Float:vVel2[3]
GetClientEyePosition(client,vPos);
GetClientEyeAngles(client,vAng);
GetAngleVectors(vAng,vVel,NULL_VECTOR,NULL_VE CTOR);
ScaleVector(vVel, 3500.0);
//GetEntPropVector(entity, Prop_Data, "m_vecVelocity", vVel2);
//AddVectors(vVel,vVel2,vVel);
//NormalizeVector(vVel,vVel);
//GetEntPropVector(entity,Prop_Data, "m_angRotation", vAngle);
//ScaleVector(vVel, 3500.0);
//ScaleVector(vAngle, 500.0);
//SetEntPropVector(entity, Prop_Send, "m_vInitialVelocity", vVelocity);
TeleportEntity(entity, vPos, vAng, vVel);
}
}

Next I'd like to make it so he has 3 grenades(rockets) to shoot. I found a plugin that does this so I am in the process of trying to figure out how to make it work for mine. Something I didn't realize till I looked at their code is that the ammo has to be kept track of when its not used because I assume the game resets it to 1 normally. Here is the plugin im talking about: http://forums.alliedmods.net/showthread.php?p=1495171

I'm also looking into a way to give the player another primary weapon that they can switch back and forth to using the slot1 key.