Hello
I decided to work on this to help @DidUknowiPwn with his zombie mod. With this script you can spawn boxes that when you are close to them, you press F and they give you something. I have already made 2 special boxes for you as an example, one that gives you ammo and one that gives you stalker perk (from mw3).
For using them, first you need to add in Init() the following:
For example (with these you configure the ammo and stalker boxes, the stalker one would need better shaders, I havent looked for a proper one):
And then to spawn a box, just this:
In the example above ( 259, -566, 30 ) is the position, ( 0, 0, 0 ) the angles of the box, "com_plasticcase_beige_big" is the model I used on the box and "ammo" the kind of box I spawn.
Screenshot:
Thanks to @DidUknowiPwn for the screenshot and for testing it.
I decided to work on this to help @DidUknowiPwn with his zombie mod. With this script you can spawn boxes that when you are close to them, you press F and they give you something. I have already made 2 special boxes for you as an example, one that gives you ammo and one that gives you stalker perk (from mw3).
Code:
AddBoxType( type, shader, function, string, minimap )
{
if( ! isDefined( level.boxes ) )
level.boxes = [];
level.boxes[ type ][ 0 ] = shader;
level.boxes[ type ][ 1 ] = function;
level.boxes[ type ][ 2 ] = string;
level.boxes[ type ][ 3 ] = minimap;
}
SpawnBox( position, angle, model, type )
{
block = spawn( "script_model", position );
block setModel( model );
block.angles = angle;
block Solid();
block CloneBrushmodelToScriptmodel( level.airDropCrateCollision );
curObjID = maps\mp\gametypes\_gameobjects::getNextObjID();
objective_add( curObjID, "invisible", ( 0, 0, 0 ) );
objective_position( curObjID, position );
objective_state( curObjID, "active" );
objective_team( curObjID, "allies" );
objective_icon( curObjID, level.boxes[ type ][ 3 ] );
block thread BoxShader( level.boxes[ type ][ 0 ] );
block thread BoxAction( type );
}
BoxAction( type )
{
self endon( "death" );
self endon( "disconnect" );
boxtrigger = Spawn( "trigger_radius", self.origin, 0, 50, 72 );
wait ( 0.05 );
while( 1 )
{
boxtrigger waittill( "trigger", player );
if( !isplayer( player ) )
continue;
while( player IsTouching( boxtrigger ) )
{
if( VectorDot( anglesToForward( player.angles ), VectorNormalize( boxtrigger.origin - player.origin ) ) > 0.766 )
{
player setLowerMessage( "activate", level.boxes[ type ][ 2 ] );
if( player UseButtonPressed() )
{
player thread [[ level.boxes[ type ][ 1 ] ]]();
wait ( 0.5 );
}
}
else
player ClearLowerMessage( "activate", 1 );
wait ( 0.05 );
}
player ClearLowerMessage( "activate", 1 );
}
}
BoxShader( shader )
{
self endon( "death" );
self endon( "disconnect" );
trigger = Spawn( "trigger_radius", self.origin, 0, 150, 72 );
trigger.icon = NewHudElem( );
trigger.icon SetShader( shader, 50, 50 );
trigger.icon.alpha = 0;
trigger.icon.color = ( 1, 1, 1 );
trigger thread UpdateShaderPos();
trigger.icon SetWayPoint( true, true );
wait ( 0.05 );
while( 1 )
{
trigger waittill( "trigger", player );
if( !isplayer( player ) )
continue;
while( player IsTouching( trigger ) )
{
if( VectorDot( anglesToForward( player.angles ), VectorNormalize( trigger.origin - player.origin ) ) > 0.766 )
FadeIcon( trigger.icon, "in" );
else
FadeIcon( trigger.icon, "out" );
wait ( 0.05 );
}
FadeIcon( trigger.icon, "out" );
}
}
FadeIcon( icon, what )
{
if( what == "in" )
{
icon FadeOverTime( 0.2 );
icon.alpha = 1;
wait ( 0.2 );
}
else if( what == "out" )
{
icon FadeOverTime( 0.2 );
icon.alpha = 0;
wait ( 0.2 );
}
else
{
if( icon.alpha == 0 )
{
icon FadeOverTime( 0.2 );
icon.alpha = 1;
wait ( 0.2 );
}
else
{
icon FadeOverTime( 0.2 );
icon.alpha = 0;
wait ( 0.2 );
}
}
}
UpdateShaderPos()
{
while( isDefined( self ) )
{
self.icon.x = self.origin[ 0 ];
self.icon.y = self.origin[ 1 ];
self.icon.z = self.origin[ 2 ] + 55;
wait ( 0.05 );
}
}
AmmoRefill()
{
self maps\mp\killstreaks\_airdrop::refillAmmo();
self playLocalSound( "ammo_crate_use" );
}
SetStalker()
{
self endon( "death" );
self endon( "disconnect" );
while( 1 )
{
if( self ADSButtonPressed() )
self SetMoveSpeedScale( 1.3 );
else
{
self SetMoveSpeedScale( 1 );
self maps\mp\gametypes\_weapons::updateMoveSpeedScale( "primary" );
}
wait ( 0.05 );
}
}
For using them, first you need to add in Init() the following:
Code:
AddBoxType( "name", "shader that displays over it", ::FunctionThatGivesYouItsEffect, "Text that appears when you are close and looking to it", "shader that will appear on minimap" );
For example (with these you configure the ammo and stalker boxes, the stalker one would need better shaders, I havent looked for a proper one):
Code:
AddBoxType( "ammo", "waypoint_ammo_friendly", ::AmmoRefill, "Hold ^3[{+activate}]^7 for an Ammo Refill", "waypoint_ammo_friendly" );
AddBoxType( "stalker", "specialty_pistoldeath_upgrade", ::SetStalker, "Hold ^3[{+activate}]^7 to get Stalker perk", "specialty_pistoldeath_upgrade" );
And then to spawn a box, just this:
Code:
SpawnBox( ( 259, -566, 30 ), ( 0, 0, 0 ), "com_plasticcase_beige_big", "ammo" );
In the example above ( 259, -566, 30 ) is the position, ( 0, 0, 0 ) the angles of the box, "com_plasticcase_beige_big" is the model I used on the box and "ammo" the kind of box I spawn.
Screenshot:
Thanks to @DidUknowiPwn for the screenshot and for testing it.