griefing() { level._effect["grief_shock"] = loadfx( "fx_bullet_flesh_hit" ); while(1) { players = get_players(); for (i = 0; i < players.size; i++) { if( self islookingat(players[i]) && self isFiring() ) { self thread griefing(); self maps\_zombiemode_score::add_to_player_score( 10 ); PlayFX( level._effect["grief_shock"], players[i].origin ); players[i] setMoveSpeedScale( .3 ); wait( 1.5 ); players[i] setMoveSpeedScale( 1 ); break; } else if( self islookingat(players[i]) && self isMeleeing() && self istouching(players[i]) ) { self thread griefing(); iprintln(vectorToAngles(self.origin - players[i].origin)); self maps\_zombiemode_score::add_to_player_score( 10 ); if( isDefined( self.has_altmelee ) && self.has_altmelee ) { players[i] setVelocity( vectorToAngles( self.origin - players[i].origin ) ); // Not tested, you'll have to play around with this. Most likely won't push the player in the correct direction. } players[i] setVelocity( vectorToAngles( self.origin - players[i].origin ) ); // Not tested, you'll have to play around with this. Most likely won't push the player in the correct direction. PlayFX( level._effect["grief_shock"], players[i].origin ); players[i] setMoveSpeedScale( .3 ); wait( 1.5 ); players[i] setMoveSpeedScale( 1 ); break; } } wait(0.05); } }
For some reason, the code seems to loop quite a few times (you're suppose to gain 10 points when you shoot someone, but you earn like 30 +10's) even though I have a break and after shooting someone about 3 times the game crashes.
You're making all players thread the function, and then you get all players again. The players that threads it is in the function twice, might need a check like
Code Snippet
Plaintext
if( players[i] == self )
EDIT: And even more what DD said, missed that..
Quote
... but you earn like 30 +10's) even though I have a break and after shooting ...
You are only breaking out of the for() loop, not the while() loop..
Last Edit: June 29, 2015, 07:32:53 am by BluntStuffy
I see what your going for, and if you take the while loop out or you remove the recursive call, your still gonna run into issues. Maybe not the crash. You probably want to thread some other functions that end on a notification, which would be notified right before threading. Otherwise the speed is going to be set back awkwardly.
I don't think your level._effect["grief_shock"] = loadfx( "fx_bullet_flesh_hit" ); needs to be set every time either. I haven't testing any of this, but I think it would flow better...?
while(1) { // self waittill("weapon_fired");//you could add this too, but not sure what need changed for melee players = get_players(); for (i = 0; i < players.size; i++) { if( self islookingat(players[i]) && self isFiring() ) { self notify("shooting_player"); self thread ShootingPlayer(players[i]); break; } else if( self islookingat(players[i]) && self isMeleeing() && self istouching(players[i]) ) { self notify("stabbing_player"); self thread ShootingPlayer(players[i]); break; } } wait(0.05);//get rid of this if the waittill("weapon_fired") works } } ShootingPlayer(player){ self endon("disconnect"); self endon("shooting_player"); self maps\_zombiemode_score::add_to_player_score( 10 ); PlayFX( level._effect["grief_shock"], player.origin ); player setMoveSpeedScale( .3 ); wait( 1.5 ); player setMoveSpeedScale( 1 ); } StabbingPlayer(player){ self endon("disconnect"); self endon("stabbing_player"); iprintln(vectorToAngles(self.origin - player.origin)); self maps\_zombiemode_score::add_to_player_score( 10 ); if( isDefined( self.has_altmelee ) && self.has_altmelee ) { player setVelocity( vectorToAngles( self.origin - player.origin ) ); // Not tested, you'll have to play around with this. Most likely won't push the player in the correct direction. } player setVelocity( vectorToAngles( self.origin - player.origin ) ); // Not tested, you'll have to play around with this. Most likely won't push the player in the correct direction. PlayFX( level._effect["grief_shock"], player.origin ); player setMoveSpeedScale( .3 ); wait( 1.5 ); player setMoveSpeedScale( 1 ); break; }
You could also add that waittil("weapon_fired")?
Last Edit: June 29, 2015, 06:42:26 pm by MakeCents
griefing() { while(1) { players = get_players(); for (i = 0; i < players.size; i++) { if( self islookingat(players[i]) && self AttackButtonPressed() && self GetCurrentWeaponClipAmmo() > 0 ) { weapon = self getcurrentweapon(); if(players[i].maxhealth > players[i].health) { self maps\_zombiemode_score::add_to_player_score( 10 ); } players[i] thread slowdown(weapon); wait WeaponFireTime( self GetCurrentWeapon() ); } else if( self islookingat(players[i]) && self MeleeButtonPressed() && self istouching(players[i]) ) { iprintln(vectorToAngles(self.origin - players[i].origin)); if(players[i].maxhealth > players[i].health) { self maps\_zombiemode_score::add_to_player_score( 10 ); } if( isDefined( self.has_altmelee ) && self.has_altmelee ) { players[i] setVelocity( vectorToAngles( self.origin - players[i].origin ) ); // Not tested, you'll have to play around with this. Most likely won't push the player in the correct direction. } players[i] setVelocity( vectorToAngles( self.origin - players[i].origin ) ); // Not tested, you'll have to play around with this. Most likely won't push the player in the correct direction. players[i] thread slowdown(); wait 1; } } /*zombs = getaispeciesarray("axis"); for(i=0;i<zombs.size;i++) { if( self islookingat(zombs[i]) && self AttackButtonPressed() ) { weapon = self getcurrentweapon(); self maps\_zombiemode_score::add_to_player_score( 10 ); self thread slowdown(weapon); zombs[i] thread slowdown(); wait WeaponFireTime( self GetCurrentWeapon() ); } }*/ wait(0.05); } }
This is what I have now, I fixed the crashing. The melee part doesn't seem to do anything but the shooting part works. Another problem is that islookingat() only seems to notice if you are looking at something up to a certain distance (300ish units), is there a way to extend this range?
griefing() { while(1) { players = get_players(); for (i = 0; i < players.size; i++) { if( self islookingat(players[i]) && self AttackButtonPressed() && self GetCurrentWeaponClipAmmo() > 0 ) { weapon = self getcurrentweapon(); if(players[i].maxhealth > players[i].health) { self maps\_zombiemode_score::add_to_player_score( 10 ); } players[i] thread slowdown(weapon); wait WeaponFireTime( self GetCurrentWeapon() ); } else if( self islookingat(players[i]) && self MeleeButtonPressed() && self istouching(players[i]) ) { iprintln(vectorToAngles(self.origin - players[i].origin)); if(players[i].maxhealth > players[i].health) { self maps\_zombiemode_score::add_to_player_score( 10 ); } if( isDefined( self.has_altmelee ) && self.has_altmelee ) { players[i] setVelocity( vectorToAngles( self.origin - players[i].origin ) ); // Not tested, you'll have to play around with this. Most likely won't push the player in the correct direction. } players[i] setVelocity( vectorToAngles( self.origin - players[i].origin ) ); // Not tested, you'll have to play around with this. Most likely won't push the player in the correct direction. players[i] thread slowdown(); wait 1; } } /*zombs = getaispeciesarray("axis"); for(i=0;i<zombs.size;i++) { if( self islookingat(zombs[i]) && self AttackButtonPressed() ) { weapon = self getcurrentweapon(); self maps\_zombiemode_score::add_to_player_score( 10 ); self thread slowdown(weapon); zombs[i] thread slowdown(); wait WeaponFireTime( self GetCurrentWeapon() ); } }*/ wait(0.05); } }
This is what I have now, I fixed the crashing. The melee part doesn't seem to do anything but the shooting part works. Another problem is that islookingat() only seems to notice if you are looking at something up to a certain distance (300ish units), is there a way to extend this range?
You fixed it or one of our suggestions worked?
Anyway this might be why melee doesn't work:
Code Snippet
Plaintext
self istouching(players[i])
I doubt knifing someone counts as "touching" them in CoD.
As for isLookingAt(), don't think you can change it. Honestly i think you should just do a <player> waittill("damage", attacker) for this. Less code and it would fix the isLookingAt bug.
I doubt knifing someone counts as "touching" them in CoD.
As for isLookingAt(), don't think you can change it. Honestly i think you should just do a <player> waittill("damage", attacker) for this. Less code and it would fix the isLookingAt bug.
I fixed it, I rewrote it so it doesn't need break functions and doesn't re-thread itself.
So you have to be touching someone AND meleeing for it take effect because if I didn't have the istouching() then it would happen when you melee someone while looking at them from any range instead of only melee range.
I tried a waittill "damage" but it doesn't work because players don't actually damage other players.