UGX-Mods

Call of Duty 5: World at War => Help Desk => Scripting => Topic started by: MZslayer11 on November 24, 2015, 05:00:45 pm

Title: MOTD Grenade Pit
Post by: MZslayer11 on November 24, 2015, 05:00:45 pm
So a while ago this topic was posted about MOTD Grenade Disposal and i'm having a little trouble getting it to work with the code posted.

Here is what I have (Credit to Lilrifa):

In mapname.gsc:
Under "maps\_zombiemode::main();"
Code Snippet
Plaintext
//Grenade Disposal===================
p = get_players();
for(i=0;i<p.size;i++)
{
p[i] thread watch_for_grenade();
        p[i] IPrintLnBold("Player Connected");
}
// Grenade Disposal=================

Bottom of file:
Code Snippet
Plaintext
// Grenade Disposal
watch_for_grenade()
{
self endon( "death" );
self endon( "disconnect" );

for (;;)
{
self waittill("grenade_fire",grenade,weapname);
self IPrintLnBold(weapname);
if(weapname == "fraggrenade" || weapname == "Stielhandgranate")
{
self IPrintLnBold("Grenade Thrown");
grenade thread disposal(self, "grenade_check_trig");
}
}
}

disposal(player, grenade_disposal)
{
player IPrintLnBold("Checking for trig");
trig = getEnt( "targetname" , "grenade_disposal");
checking = 1;
while(checking)
{
wait(0.05);

if(self isTouching(trig))
{
player maps\_zombiemode_score::add_to_player_score(20);
self delete();
player IPrintLnBold("Deleting Grenade");
}

checking = 0;
}
}

Original Post: http://ugx-mods.com/forum/index.php/topic,7052.0.html (http://ugx-mods.com/forum/index.php/topic,7052.0.html)

Whats happening to me is that all my grenades are deleted instead of just the ones that are thrown into the trigger. Any help is appriecated.
Title: Re: MOTD Grenade Pit
Post by: alaurenc9 on November 24, 2015, 05:07:44 pm
this is because your trigger is undefined.

your trigger is undefined because you are using GetEnt very incorrectly.

i assume you wanted this??

Code Snippet
Plaintext
trig = GetEnt( grenade_disposal, "targetname" );

also take out

Code Snippet
Plaintext
self endon( "death" );


in watch_for_grenade(), because that would mean once u spectate, this script stops running for the rest of the game.

also your while loop ends after only one check??
i would recommend replacing that whole functions with this:

Code Snippet
Plaintext
disposal( player, grenade_disposal ) 
{
self endon( "death" ); // if the grenade explodes, end this function
trig = GetEnt( grenade_disposal, "targetname" );
while( true )
{
wait 0.05;
if( IsDefined( self ) && self IsTouching( trig ) ) // check if the nade is still defined first ( it hasnt blown up yet )
{
player maps\_zombiemode_score::add_to_player_score( 20 );
self Delete(); // delete after adding points, because this function ends on the grenade's delete
return;
}
}
}
Title: Re: MOTD Grenade Pit
Post by: MZslayer11 on November 24, 2015, 05:18:10 pm
Thanks ill give that a go

Double Post Merge: November 24, 2015, 05:28:18 pm
Hmm its still doing the same thing with your changes.
Title: Re: MOTD Grenade Pit
Post by: MakeCents on November 24, 2015, 05:39:32 pm
Thanks ill give that a go

Double Post Merge: November 24, 2015, 05:28:18 pm
Hmm its still doing the same thing with your changes.

Maybe add another check then?
Code Snippet
Plaintext
    if(IsDefined( trig ) && self IsTouching( trig ) )

it seems that it is deleting due to that line, and maybe you have a typo in your kvp in radiant, or more than one of those triggers, or something, and trig isn't defined since you had it backwards (the original post had it backwards too) and in quotes... What is your kvp for that trigger in radiant? If that check addition stops it from deleting at all, I would guess that trig is not defined then.

Edit: Your kvp should be "grenade_check_trig" since that is the string you are passing.

Code Snippet
Plaintext
disposal(player, grenade_disposal) 
{
player IPrintLnBold("Checking for trig");
trig = getEntArray( grenade_disposal, "targetname" )[0];//in case you have more than one, will error, need to edit script to thread on each of them if you want more than one
while(isdefined(self))
{
wait(0.05);

if(isdefined(trig) && self isTouching(trig))
{
player maps\_zombiemode_score::add_to_player_score(20);
self delete();
player IPrintLnBold("Deleting Grenade");
}
}
}

For multiple triggers try something like:
Code Snippet
Plaintext
disposal(player, grenade_disposal) 
{
player IPrintLnBold("Checking for trig");
trigs = getEntArray( grenade_disposal, "targetname" );
array_thread(trigs,::WatchMe,self,player);
}
WatchMe(grenade, player){
while(isdefined(grenade))
{
wait(0.05);

if(isdefined(self) && grenade isTouching(self))
{
player maps\_zombiemode_score::add_to_player_score(20);
grenade delete();
player IPrintLnBold("Deleting Grenade");
}
}
}
Title: Re: MOTD Grenade Pit
Post by: MZslayer11 on November 25, 2015, 03:58:30 am
Alright its is almost working properly with the stuff that MakeCents posted (the multiple triggers one). For some reason, it gives me 40 points when I throw it into the pit, and when I do not throw it in the pit, it doesn't get deleted (yay), but it gives me 40 points when it explodes.  :o

this is the exact code i'm using now:

Under maps\_zombiemode::main();
Code Snippet
Plaintext
//Grenade Disposal===================
p = get_players();
for(i=0;i<p.size;i++)
{
p[i] thread watch_for_grenade();
        p[i] IPrintLnBold("Player Connected");
}
// Grenade Disposal=================

Bottom of file:
Code Snippet
Plaintext
// Grenade Disposal
watch_for_grenade()
{
self endon( "disconnect" );

for (;;)
{
self waittill("grenade_fire",grenade,weapname);
self IPrintLnBold(weapname);
if(weapname == "fraggrenade" || weapname == "Stielhandgranate")
{
self IPrintLnBold("Grenade Thrown");
grenade thread disposal(self, "grenade_check_trig");
}
}
}

disposal(player, grenade_disposal)
{
player IPrintLnBold("Checking for trig");
trigs = getEntArray( grenade_disposal, "targetname" );
array_thread(trigs,::WatchMe,self,player);
}

WatchMe(grenade, player){
while(isdefined(grenade))
{
wait(0.05);

if(isdefined(self) && grenade isTouching(self))
{
player maps\_zombiemode_score::add_to_player_score(20);
grenade delete();
player IPrintLnBold("Deleting Grenade");
}
}
}

I have two trigger multiples in  radiant with the KVP:
Code Snippet
Plaintext
targetname - grenade_check_trig

WTF is wrong now lol?
Title: Re: MOTD Grenade Pit
Post by: MakeCents on November 25, 2015, 04:38:41 am
You should only have one trig unless you have multiple places you can do this at. When you say you have two, are they at the same place or touching? If they are touching, then that is why prob, delete one.
If the triggers are in different places then it could also need another check, try:

Code Snippet
Plaintext
WatchMe(grenade, player){
while(isdefined(grenade))
{
wait(0.05);

if(isdefined(self) && isdefined(grenade) && grenade isTouching(self))
{
player maps\_zombiemode_score::add_to_player_score(20);
grenade delete();
player IPrintLnBold("Deleting Grenade");
}
}
}
Title: Re: MOTD Grenade Pit
Post by: MZslayer11 on November 25, 2015, 04:40:54 am
You should only have one trig unless you have multiple places you can do this at. When you say you have two, are they at the same place or touching?
It could also need another check, try:

Code Snippet
Plaintext
WatchMe(grenade, player){
while(isdefined(grenade))
{
wait(0.05);

if(isdefined(self) && isdefined(grenade) && grenade isTouching(self))
{
player maps\_zombiemode_score::add_to_player_score(20);
grenade delete();
player IPrintLnBold("Deleting Grenade");
}
}
}

yeah they are at two seperate places. Ill give that a try.

Double Post Merge: November 25, 2015, 04:53:04 am
Thank you so much, that got it working +1!