Ammo instead damage Created 9 years ago2015-07-05 18:38:38 UTC by abbadon abbadon

Created 9 years ago2015-07-05 18:38:38 UTC by abbadon abbadon

Posted 9 years ago2015-07-05 18:38:38 UTC Post #326180
Hi, I have a question about something I´m working on. I´ve modified the code of a monster so it´ll give ammo instead og giving damage to the player. I did this:

on the #include part...

#include "player.h"

on the declarations:

CBasePlayer *pPlayer;

on the attack function...

pPlayer->GiveAmmo(600,9mm,600);

well, I have compiled Ok, run the MOD, all fine, but when the monster attacks me the MOD crashes. I donñ t know if something´swrong with the code because the debug doesen´t give no clues...

The one who can solve this will be on credits as "monster_trolley code fix (c) insert-your-name-here" :)
Posted 9 years ago2015-07-05 18:40:24 UTC Post #326181
https://www.youtube.com/watch?v=vYCfr_AWC2k

Here´s what the mod look like with the HOG added!! (just to motivate you ;) ).
Posted 9 years ago2015-07-05 18:57:52 UTC Post #326182
For God´s sake...how can I edit my wn posts?. Here´s what I´ve obtained on the debugger

The program 'C:\DevZWC20\HL\hl.exe' has exited with code -1073741819 (0xC0000005).
Posted 9 years ago2015-07-05 20:24:28 UTC Post #326189
sounds unsafe. The best idea would be to have the monster spawn an ammo entity (like how human grunts drop a weapon_9mmAR) instead of calling the giveammo function directly.
Posted 9 years ago2015-07-05 21:54:46 UTC Post #326191
You mean spawning an ammobox each time it attacks?
Posted 9 years ago2015-07-05 23:02:31 UTC Post #326193
how can I edit my wn posts?
When your post is the most recent one, the edit button is next to your name on the far right, above one's avatar.
Jessie JessieTrans Rights <3
Posted 9 years ago2015-07-06 12:19:58 UTC Post #326204
Got it!! I have a 1900x1080 screen and the font I choose is toooo small, got to look better next time, sorry.
Posted 9 years ago2015-07-06 17:17:58 UTC Post #326205
Right. How did that fix your problem?
When your post is the most resent one, the edit button is next to your name on the far right, above one's avatar.
When it's not the most recent one?
Dr. Orange Dr. OrangeSource good.
Posted 9 years ago2015-07-06 19:17:53 UTC Post #326208
Right. How did that fix your problem?
Sorry, I was talking about the edit button ;)

I am still working on it, but I have some doubts:

Could I make it so the ammoboxes exit from the monster´s arms?
If so, could it be possible to make them be throwed instead of being droped from the arms?

And, the most important. How I call the function?, the monster, as the Hgrunt, hast´t a CMymonster :: Killed function... :/
Posted 9 years ago2015-07-06 23:23:19 UTC Post #326216
Could I make it so the ammoboxes exit from the monster´s arms?
If so, could it be possible to make them be throwed instead of being droped from the arms?
The model of the monster should have an attachment. If you check hgrunt.mdl it has an attachment around where the gun should be.

It is possible to make a spawned ammo_9mmAR or other item to fly in a certain velocity. I have seen it in another mod.
DropItem( "weapon_shotgun", vecGunPos, vecGunAngles );
is how hgrunt calls the function to drop a shotgun. Just replace weapon shotgun with your ammo_9mmAR or what you are using.
Posted 9 years ago2015-07-07 13:32:13 UTC Post #326233
I´m on it. I´ve had to get rid of the GibMonster(); part because each time the monster attacks me it blows into pieces!!, gorish.... XD

Aniway, your method doesen´t work for me, suerely my fault.

Here´s the code I used:

[quote][blue]void CTrolley :: GiveAmmo ( void )
{
Vector	vecGunPos;
Vector	vecGunAngles;
CBaseEntity *pGun;
	GetAttachment( 0, vecGunPos, vecGunAngles );


	{
		pGun = DropItem( "ammo", vecGunPos, vecGunAngles );
	}
	if ( pGun )
	{
		pGun->pev->velocity = Vector (RANDOM_FLOAT(-100,100), RANDOM_FLOAT(-100,100), RANDOM_FLOAT(200,300));
		pGun->pev->avelocity = Vector ( 0, RANDOM_FLOAT( 200, 400 ), 0 );
	}
}[/blue][/quote]

And I put the GiveAmmo() function inside the Attac part

[quote][blue]//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
void CTrolley :: HandleAnimEvent( MonsterEvent_t *pEvent )
{
switch( pEvent->event )
{
	case TROLL_AE_ATTACK_RIGHT:
	{

//ALERT( at_console, "Drone slashes with right claw!!\n" );
		CBaseEntity *pHurt = CheckTraceHullAttack( 0, gSkillData.zombieDmgOneSlash, DMG_SLASH );
		if ( pHurt )
		{

			EMIT_SOUND_DYN ( ENT(pev), CHAN_WEAPON, pAttackHitSounds[ RANDOM_LONG(0,ARRAYSIZE(pAttackHitSounds)-1) ], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5,5) );
		}
		else // Play a random attack miss sound
			EMIT_SOUND_DYN ( ENT(pev), CHAN_WEAPON, pAttackMissSounds[ RANDOM_LONG(0,ARRAYSIZE(pAttackMissSounds)-1) ], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5,5) );
		if (RANDOM_LONG(0,1))
			AttackSounds();

		pev->nextthink = gpGlobals->time + 10;//¿chuta? Esto es para que tras atacar no vuelva a recargar en diez segunos ¡¡¡¡¡¡¡SIIIIII!!!!! ¡¡¡¡¡¡Chutaaaarrrrrrl el 7-7-2015 San-fer-mín!!!!!
		GiveAmmo();// A ver si chuta....
	}
	break;
	default:
		CBaseMonster::HandleAnimEvent( pEvent );
		break;
}
}[/blue][/quote]

Of course I´ve declared all functions adn put the right attachment to the Trolley monster. But... no luck.

Did I something wrong? :/
Posted 9 years ago2015-07-07 13:42:11 UTC Post #326234
{
pGun = DropItem( "ammo", vecGunPos, vecGunAngles );
}
1) that looks wrong to me
2)what ammo do you want him to give? I can't see any value being passed to that function
Tetsu0 Tetsu0Positive Chaos
Posted 9 years ago2015-07-07 14:11:39 UTC Post #326237
Mmmmm, the original function calls for the model "w_357ammo", so I put the "ammo" model of my mod. Everything on this line of code is identical to the original except for the model name :(
Posted 9 years ago2015-07-07 16:14:24 UTC Post #326241
can you place the "ammo" model in game with a cycler entity?
perhaps the model is crashing the engine?

Else, what if you take the existing dropitem code and use that instead?
Get your monster drop the W_357 then swap out your ammo once that works. I would think that if the copy-pasted code doesn't work, then your're missing a step somewhere.

I'm not a HL coder, but I read and write code for a living and I think smaller baby steps might work better than large jumps
Also, does the "dropItem" function require the owner to posses said item? Or does it just spawn a new instance
Tetsu0 Tetsu0Positive Chaos
Posted 9 years ago2015-07-07 21:15:36 UTC Post #326243
can you place the "ammo" model in game with a cycler entity?
In a first approach I thought that, but the game NEEDS the ammobox be spawned the way I want.
perhaps the model is crashing the engine?
No, the model in game perform all actions perfectly, and the game doesen´t crash like in the first attempt when I used pPlayer->GiveAmmo
Else, what if you take the existing dropitem code and use that instead?
If you take a look it´s identical. The only part that I deleted is that of the code checking if the monster has a gun. Oh, and the Gibs part that makes the monster explode once it attacks the player.
Get your monster drop the W_357 then swap out your ammo once that works.
Mmmm, I didn´t try that. So you think that the problem is that the code doesen´t regognize my model, right?
I would think that if the copy-pasted code doesn't work, then your're missing a step somewhere.
I also think that, but...what step? :( That´s the question. ;)
Also, does the "dropItem" function require the owner to posses said item? Or does it just spawn a new instance.
I don´t know for sure. I must take a look to the code. Give a try and I´ll tell you.

User posted image

http://www.moddb.com/mods/zion-warcry
Posted 9 years ago2015-07-08 11:07:11 UTC Post #326255
I still think that this:
{
pGun = DropItem( "ammo", vecGunPos, vecGunAngles );
}

looks really wrong to me.
There's no conditional statement or function declaration before the bracket.
Tetsu0 Tetsu0Positive Chaos
Posted 9 years ago2015-07-08 13:10:58 UTC Post #326257
Ok, but, how it should be instead? :(
Posted 9 years ago2015-07-08 13:17:28 UTC Post #326258
perhaps remove the "{" and "}" surrounding it?
Tetsu0 Tetsu0Positive Chaos
Posted 9 years ago2015-07-08 13:24:59 UTC Post #326259
That wouldn't change anything, in C/C++/etc. you can create scopes like that and it'll just run the same as if it was an "if (true)" condition. It's a feature that's rarely useful, but it won't change the way the code works (in this case).
Penguinboy PenguinboyHaha, I died again!
Posted 9 years ago2015-07-08 13:38:16 UTC Post #326261
well there goes my idea - sorry abbadon
Thanks for the tip PB
Tetsu0 Tetsu0Positive Chaos
Posted 9 years ago2015-07-18 08:54:03 UTC Post #326263
Don´t worry. I find the solution!!!
int CTrolley :: GiveAmmo( int iCount, char *szName, int iMax );
I declare the function...
GiveAmmo(600, "9mm",600);// A ver si chuta..
Put in into the ATTACK function...
int CTrolley :: GiveAmmo( int iCount, char *szName, int iMax )
{
CBaseEntity *pPlayer;

pPlayer = UTIL_FindEntityByClassname( NULL, "player" );

pPlayer->GiveAmmo(600,"9mm",600);

return TRUE;
}
And this is the function that makes the monster give you AMMO instead damage. I think you can make it also heals you, but I don´t know how (yet) ;)
Also, make a condition on the Classify function in which if you have less of 100 ammo (or whatever value you want) the relationship is R_NM, else is R_ALLY ;) else the guy´ll keep on reloading forever and ever (because he hates you!!!).

Here´s the trolley guy working!!
User posted image
You must be logged in to post a response.