UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

Script Loop Problem

broken avatar :(
Created 11 years ago
by jbird
0 Members and 1 Guest are viewing this topic.
4,022 views
broken avatar :(
×
broken avatar :(
Location: usUnited States
Date Registered: 13 May 2014
Last active: 5 days ago
Posts
167
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
×
jbird's Groups
Code Snippet
Plaintext
grief_damage()
{
players = get_players();
for(i=0;i<players.size;i++)
{
  players[i] thread grenade_damage();
  players[i] thread griefing();
}
}
Code Snippet
Plaintext
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.
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
Signature
Let's keep this thread on topic from here on in. -DBZ

+1 to off-topic reply -DBZ

lmao. Too funny.

Goliath Script Placer: http://ugx-mods.com/forum/index.php/topic,11234.msg125257/topicseen.html#new

"...Christ, people. Learn C, instead of just stringing random characters
together until it compiles (with warnings)..."

-Linus Torvalds
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
Code Snippet
Plaintext
self thread griefing();

This. Your creating a new instance of the same function everytime you damage someone. Remove it.
Last Edit: June 29, 2015, 07:19:53 am by daedra descent
broken avatar :(
×
broken avatar :(
Location: nlApeldoorn
Date Registered: 17 December 2013
Last active: 2 years ago
Posts
1,186
Respect
1,332Add +1
Forum Rank
Zombie Colossus
Primary Group
Scripter Elite
My Groups
More
My Contact & Social Links
More
Personal Quote
It aint much, if it aint Dutch
Signature
×
BluntStuffy's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
Oil Rig Beta Access
Oil Rig Beta Access
BluntStuffy's Contact & Social LinksBluntStuffyBluntstuffy@BluntZombieStuffyZombie
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
broken avatar :(
×
broken avatar :(
[UGX] Documentation Writer & Programmer
Location: usLos Angeles, CA
Date Registered: 23 August 2013
Last active: 3 years ago
Posts
1,322
Respect
Forum Rank
Zombie Colossus
Primary Group
UGX Team Member
My Groups
More
My Contact & Social Links
More
Personal Quote
(ง º ω º )ง u wont sum m8y?
Signature
Do not take life too seriously. You will never get out of it alive.
×
DidUknowiPwn's Groups
UGX Team Member
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
isFiring is also for AI only.


My bad


Code Snippet
Plaintext
test()
{
self endon("death");
self endon("disconnect");

while(true)
{
if(self IsFiring())
IPrintLnBold("I'm shooting");
else
IPrintLn("Nah");
wait 0.05;
}
}
Last Edit: June 29, 2015, 06:48:10 pm by DidUknowiPwn
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 14 September 2013
Last active: 6 years ago
Posts
1,895
Respect
Forum Rank
Zombie Destroyer
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
BE ORIGINAL
Signature
×
MakeCents's Groups
Mapper Has released one or more maps to the UGX-Mods community.
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
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...?
Code Snippet
Plaintext
grief_damage()
{
level._effect["grief_shock"] = loadfx( "fx_bullet_flesh_hit" );
players = get_players();
for(i=0;i<players.size;i++)
{
  players[i] thread grenade_damage();
  players[i] thread griefing();
}
}
griefing()
{

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
broken avatar :(
×
broken avatar :(
Location: usUnited States
Date Registered: 13 May 2014
Last active: 5 days ago
Posts
167
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
×
jbird's Groups
Code Snippet
Plaintext
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?
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
Code Snippet
Plaintext
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.

broken avatar :(
×
broken avatar :(
Location: usUnited States
Date Registered: 13 May 2014
Last active: 5 days ago
Posts
167
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
×
jbird's Groups
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 fixed it, I rewrote it so it doesn't need break functions and doesn't re-thread itself.

The if line says
Code Snippet
Plaintext
else if( self islookingat(players[i]) && self MeleeButtonPressed() && self istouching(players[i]) )
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.
broken avatar :(
×
broken avatar :(
Location: nlApeldoorn
Date Registered: 17 December 2013
Last active: 2 years ago
Posts
1,186
Respect
1,332Add +1
Forum Rank
Zombie Colossus
Primary Group
Scripter Elite
My Groups
More
My Contact & Social Links
More
Personal Quote
It aint much, if it aint Dutch
×
BluntStuffy's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
Oil Rig Beta Access
Oil Rig Beta Access
BluntStuffy's Contact & Social LinksBluntStuffyBluntstuffy@BluntZombieStuffyZombie
I fixed it, I rewrote it so it doesn't need break functions and doesn't re-thread itself.

And who was the one telling you it was doing that? that was DD, so technically he fixed it ::)
broken avatar :(
×
broken avatar :(
Location: usUnited States
Date Registered: 13 May 2014
Last active: 5 days ago
Posts
167
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
×
jbird's Groups
You could also add that waittil("weapon_fired")?
Isn't "weapon_fired" only for tanks though? At least that's what Sparky said http://gyazo.com/451b54c99532d58c1d93accd983eefa7
broken avatar :(
×
broken avatar :(
Location: se
Date Registered: 30 July 2013
Last active: 2 years ago
Posts
517
Respect
Forum Rank
Zombie Enslaver
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
×
Ege115's Groups
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Ege115's Contact & Social LinksEge115
The isFiring() function also returns true when you're meleeing.
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 14 September 2013
Last active: 6 years ago
Posts
1,895
Respect
Forum Rank
Zombie Destroyer
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
BE ORIGINAL
×
MakeCents's Groups
Mapper Has released one or more maps to the UGX-Mods community.
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
Isn't "weapon_fired" only for tanks though? At least that's what Sparky said http://gyazo.com/451b54c99532d58c1d93accd983eefa7

No.

 
Loading ...