UGX-Mods

Call of Duty 5: World at War => Tutorial Desk => Scripting => Topic started by: MakeCents on June 21, 2014, 02:38:20 am

Title: Communal Box
Post by: MakeCents on June 21, 2014, 02:38:20 am
This will make the box weapon take-able for all players, not just the person that hit the box.

All changes will be in your _zombiemode_weapons.gsc, treasure_chest_think() function.

I have provided two options, the few steps necessary for this, or at the bottom of the page you can select and replace the entire function.

Step-by-step
Locate the treasure_chest_think() function.
Replace the following:
Code Snippet
Plaintext
		self setvisibletoplayer( user );
with
Code Snippet
Plaintext
		self setvisibletoplayer( user );
self thread GiveMeASecond(); //gives the player who hit the box time to take weapon

Replace the following:
Code Snippet
Plaintext
			if( grabber == user || grabber == level )
with
Code Snippet
Plaintext
			if( is_player_valid(grabber) || grabber == level )
Replace the following:
Code Snippet
Plaintext
				if( grabber == user && is_player_valid( user ) && user GetCurrentWeapon() != "mine_bouncing_betty" )


with
Code Snippet
Plaintext
				user = grabber;
if( is_player_valid( user ) && user GetCurrentWeapon() != "mine_bouncing_betty" )
Then add the following function after the treasure_chest_think() function function
Code Snippet
Plaintext
GiveMeASecond(){
wait(3); //gives the buyer 3 seconds to chose to take it
self SetVisibleToAll();
}



or, if it is easier for you, just replace your whole treasure_chest_think() function with this:
Code Snippet
Plaintext
treasure_chest_think()
{
cost = 950;
if( IsDefined( level.zombie_treasure_chest_cost ) )
{
cost = level.zombie_treasure_chest_cost;
}
else
{
cost = self.zombie_cost;
}

self set_hint_string( self, "default_treasure_chest_" + cost );
self setCursorHint( "HINT_NOICON" );

//self thread decide_hide_show_chest_hint( "move_imminent" );

// waittill someuses uses this
user = undefined;
while( 1 )
{
self waittill( "trigger", user );

if( user in_revive_trigger() )
{
wait( 0.1 );
continue;
}

// make sure the user is a player, and that they can afford it
if( is_player_valid( user ) && user.score >= cost )
{
user maps\_zombiemode_score::minus_to_player_score( cost );
break;
}
else if ( user.score < cost )
{
user thread maps\_zombiemode_perks::play_no_money_perk_dialog();
continue;
}

wait 0.05;
}

// trigger_use->script_brushmodel lid->script_origin in radiant
lid = getent( self.target, "targetname" );
weapon_spawn_org = getent( lid.target, "targetname" );

//open the lid
lid thread treasure_chest_lid_open();

// SRS 9/3/2008: added to help other functions know if we timed out on grabbing the item
self.timedOut = false;

// mario kart style weapon spawning
weapon_spawn_org thread treasure_chest_weapon_spawn( self, user );

// the glowfx
weapon_spawn_org thread treasure_chest_glowfx();

// take away usability until model is done randomizing
self disable_trigger();

weapon_spawn_org waittill( "randomization_done" );

if (flag("moving_chest_now"))
{
user thread treasure_chest_move_vo();
self treasure_chest_move(lid);

}
else
{
// Let the player grab the weapon and re-enable the box //
self.grab_weapon_hint = true;
self.chest_user = user;
self sethintstring( &"ZOMBIE_TRADE_WEAPONS" );
self setCursorHint( "HINT_NOICON" );
self setvisibletoplayer( user );
self thread GiveMeASecond();


// Limit its visibility to the player who bought the box
self enable_trigger();
self thread treasure_chest_timeout();

// make sure the guy that spent the money gets the item
// SRS 9/3/2008: ...or item goes back into the box if we time out
while( 1 )
{
self waittill( "trigger", grabber );

if( is_player_valid(grabber) || grabber == level )
{

user = grabber;
if( is_player_valid( user ) && user GetCurrentWeapon() != "mine_bouncing_betty" )
{
bbPrint( "zombie_uses: playername %s playerscore %d round %d cost %d name %s x %f y %f z %f type magic_accept",
user.playername, user.score, level.round_number, cost, weapon_spawn_org.weapon_string, self.origin );
self notify( "user_grabbed_weapon" );
user thread treasure_chest_give_weapon( weapon_spawn_org.weapon_string );
break;
}
else if( grabber == level )
{
// it timed out
self.timedOut = true;
bbPrint( "zombie_uses: playername %s playerscore %d round %d cost %d name %s x %f y %f z %f type magic_reject",
user.playername, user.score, level.round_number, cost, weapon_spawn_org.weapon_string, self.origin );
break;
}
}

wait 0.05;
}

self.grab_weapon_hint = false;
self.chest_user = undefined;

weapon_spawn_org notify( "weapon_grabbed" );

//increase counter of amount of time weapon grabbed.
if(level.script != "nazi_zombie_prototype")
{
level.chest_accessed += 1;

// PI_CHANGE_BEGIN
// JMA - we only update counters when it's available
if( isDefined(level.DLC3.useChestPulls) && level.DLC3.useChestPulls )
{
level.pulls_since_last_ray_gun += 1;
}

if( isDefined(level.DLC3.useChestPulls) && level.DLC3.useChestPulls )
{
level.pulls_since_last_tesla_gun += 1;
}
// PI_CHANGE_END
}
self disable_trigger();

// spend cash here...
// give weapon here...
lid thread treasure_chest_lid_close( self.timedOut );

//Chris_P
//magic box dissapears and moves to a new spot after a predetermined number of uses

wait 3;
self enable_trigger();
self setvisibletoall();
}

flag_clear("moving_chest_now");
self thread treasure_chest_think();
}
GiveMeASecond(){
wait(3);
self SetVisibleToAll();
}
Title: Re: Communal Box
Post by: Dust on June 21, 2014, 02:53:23 am
NICE! Been waiting for this tutorial forever. One question, does this make it so the players can automatically take other  players weapons or does it wait about 5-6 seconds before giving other players the option. If its the first way then can you show me how to make it so the player who spins the box can take it before it will let other players take it. That way no one can steal other peoples box weapons.
Title: Re: Communal Box
Post by: MakeCents on June 21, 2014, 03:01:32 am
NICE! Been waiting for this tutorial forever. One question, does this make it so the players can automatically take other  players weapons or does it wait about 5-6 seconds before giving other players the option. If its the first way then can you show me how to make it so the player who spins the box can take it before it will let other players take it. That way no one can steal other peoples box weapons.

You could change:
Code Snippet
Plaintext
		//self setvisibletoplayer( user );
self SetVisibleToAll();
to
Code Snippet
Plaintext
		self setvisibletoplayer( user );
self thread GiveMeASecond();
and add this after the treasure_chest_think() function
Code Snippet
Plaintext
GiveMeASecond(){
wait(3); //gives the buyer 3 seconds to chose to take it
self SetVisibleToAll();
}

Edit: I updated the tut to include this. Good idea.
Title: Re: Communal Box
Post by: Dust on June 21, 2014, 03:44:31 am
You could change:
Code Snippet
Plaintext
		//self setvisibletoplayer( user );
self SetVisibleToAll();
to
Code Snippet
Plaintext
		self setvisibletoplayer( user );
self thread GiveMeASecond();
and add this after the treasure_chest_think() function
Code Snippet
Plaintext
GiveMeASecond(){
wait(3); //gives the buyer 3 seconds to chose to take it
self SetVisibleToAll();
}

Edit: I updated the tut to include this. Good idea.

Thanks! Will add this to my map and test it in a little bit
Title: Re: Communal Box
Post by: Alerion on June 21, 2014, 08:42:58 am
Nice, thank you!

This will defuse some trolls:D
Title: Re: Communal Box
Post by: mentality on July 03, 2014, 06:18:32 pm
Sweet, I think I'm going to add this into my map with a twist :)