Author |
Topic: Spawn grenade? |
scillman |
|
General Member Since: Nov 23, 2006 Posts: 360 Last: Sep 1, 2012 [view latest posts] |
|
|
|
Tally |
General Member Since: Apr 21, 2005 Posts: 819 Last: Oct 26, 2012 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Friday, Jan. 20, 2012 07:54 pm |
|
scillman writes...Quote: Someone asked me if I could make something for him and I wondered if it is possible to spawn a grenade as in weapon? Or can it only be done as a script_model??
Code: grenade = spawn( "weapon_frag_grenade_mp", origin, 4 );
You always spawn the Radiant name of the weapon - not the name of the weapon file. The number "4" is a spawnflag. You can use either 3 or 4, depending on how you want the weapon to lay on the ground. |
|
|
|
scillman |
|
General Member Since: Nov 23, 2006 Posts: 360 Last: Sep 1, 2012 [view latest posts] |
|
|
|
Tally |
General Member Since: Apr 21, 2005 Posts: 819 Last: Oct 26, 2012 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Friday, Jan. 20, 2012 09:17 pm |
|
scillman writes...Quote: Actually it is spawning in the air and needs to fall down(just for the record: it does not fall straight down), as I hoped to reduce additional scripting I was hoping I could make it like the grenade as it is ingame when thrown.
change the spawnflag to 3. |
|
|
|
Samuel033 |
General Member Since: Dec 10, 2009 Posts: 484 Last: Dec 25, 2015 [view latest posts] |
|
|
|
Tally |
General Member Since: Apr 21, 2005 Posts: 819 Last: Oct 26, 2012 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Saturday, Jan. 21, 2012 12:12 pm |
|
Samuel033 writes...Quote: Does that actually spawn a real nade that can accept initial velocity? Such as throwing one or launching it from a tube. Or does it just drop and react to the ground? I would assume it also gets the timer from the weapon file. Or it can be manually detonated if needed.
If you spawn the weapon using spawnflag 3, when you get near it, it will give the pickup hint string "press ["use key"] to pick up", but it will be rigid in space - that is, it wont fall to the ground, it will remain bolt upright and at the absolute origin you give it, although it can actually be picked up and thrown (if a grenade).
However, if you use spawnflag 4 to spawn a grenade, it acts as though someone has thrown the grenade, and gives you the hint string "press [frag button] to throw back", but can actually only be picked up using the "use" key. But it will fall to the ground from your stated origin (so, for example, if you spawn it 5 units above ground, it will fall back to actual ground level), and lay on its side. It does not, however, "cook" - that is, there is no fuse set this way. However, I believe you can manually cause it to explode using the detonate() function.
Also, if you spawn a weapon other than a grenade, such as an assault rifle, it will only have minimal ammo. You have to give it full ammo:
Code: {
weapon = spawn( classname, origin, 4 );
weapname = weapon maps\mp\gametypes\_weapons::getItemWeaponName();
weapon setPickupStartAmmo( weapname );
}
setPickupStartAmmo( weapname )
{
curweapname = weapname;
altindex = 0;
while( altindex == 0 || (curweapname != weapname && curweapname != "none") )
{
allammo = weaponStartAmmo( curweapname );
clipammo = weaponClipSize( curweapname );
reserveammo = 0;
if( clipammo >= allammo )
{
clipammo = allammo;
}
else
{
reserveammo = allammo - clipammo;
}
self itemWeaponSetAmmo( clipammo, reserveammo, altindex );
curweapname = weaponAltWeaponName( curweapname );
altindex++;
}
}
|
|
|
|
scillman |
|
General Member Since: Nov 23, 2006 Posts: 360 Last: Sep 1, 2012 [view latest posts] |
|
|
|
IzNoGoD |
General Member Since: Nov 29, 2008 Posts: 694 Last: Nov 10, 2012 [view latest posts] |
|
|
|
scillman |
|
General Member Since: Nov 23, 2006 Posts: 360 Last: Sep 1, 2012 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Saturday, Jan. 21, 2012 03:14 pm |
|
Nope that is SP only ( ModsRepository)
Kind of getting the idea I have no other choice then scripting it
P.s.
1- I set the angles that did not help.
2. I can not get the current origin, so how could I let it detonate?!
edited on Jan. 21, 2012 08:20 am by scillman
This is basicly what I have now:
Code: playGrenade( org, ang )
{
model = spawn( "weapon_frag_grenade_mp", org, 4 );
model.angles = ang;
pos = (0,0,-100000);
while (model.origin != pos)
{
pos = model.origin;
wait .05;
}
iPrintLnBold("Hit ground!");
model thread maps\mp\gametypes\_shellshock::grenade_earthQuake();
}
edited on Jan. 21, 2012 08:35 am by scillman |
|
|
|
Tally |
General Member Since: Apr 21, 2005 Posts: 819 Last: Oct 26, 2012 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Saturday, Jan. 21, 2012 04:16 pm |
|
What is it you are trying to do? Because, looking at that code, I can't for the life of me see what you are attempting to do.
Just an update -
After some experimentation, I found that you cannot use detonate() on a grenade spawned in this way. The detonate() function uses the "grenade" classname, and that type of entity is only created once a live player presses one of their grenade buttons (either primary or secondaryoffhand), or one of the actionslots. So, in other words, it has to actually be thrown by a player in order for the entity to be recognised as a "grenade".
However, knowing this doesn't mean you can't spoof it - all you need to do is script the explosion and subsequent damage to any players in the vicinity of the entity. I had to do this for my Martyrdom perk in my COD2 mod. Just get the origin of the spawned grenade, and then set a timer to count down to detonation time, and then delete the entity and play an FX on that location. Then use a scripted radius damage at that origin to damage any players in that area.
Not ideal, I know, but what you going to do? Rewrite the COD4 MP executable to make it possible? Believe me - I've thought about it! |
|
|
|