Post: Vending Machine?
02-26-2011, 05:18 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); Well, I found another thing. This time I found codes for a vending machine. Found in _dynamic_world.gsc
    
// Vending Machine
CONST_vending_machine_health = 400;
CONST_soda_pop_time = 0.1; // seconds
CONST_soda_count = 12; // number of soda per machine
CONST_soda_launch_force = 1000; // soda shoot out force
CONST_soda_random_factor = 0.15; // in percentage 0.2 = 20%
CONST_soda_splash_dmg_scaler = 3; // splash damage multiplier


EDIT! More vending machine coding:
    vending_machine()
{
level endon( "game_ended" );
self endon( "death" );

// self is use trigger
self SetCursorHint( "HINT_ACTIVATE" );

self.vm_normal = getent( self.target, "targetname" );
assertex( isdefined( self.vm_normal ), "Vending machine use trigger is missing target to the normal vending machine script_model" );
vm_soda_start = getent( self.vm_normal.target, "targetname" );
assertex( isdefined( vm_soda_start ), "Vending machine normal script_model is missing target to the start-soda can script_model" );
vm_soda_stop = getent( vm_soda_start.target, "targetname" );
assertex( isdefined( vm_soda_start ), "Start-soda can script_model is missing target to the end-soda can script_model" );
self.vm_launch_from = getent( vm_soda_stop.target, "targetname" );
assertex( isdefined( self.vm_launch_from ), "End-soda can script_model is missing target to the physics launch-from script_origin" );
self.vm_launch_to = getent( self.vm_launch_from.target, "targetname" );
assertex( isdefined( self.vm_launch_to ), "launch-from can script_origin is missing target to the physics launch-to script_origin" );

if ( isdefined( self.vm_launch_to.target ) )
self.vm_fx_loc = getent( self.vm_launch_to.target, "targetname" );

//assertex( isdefined( self.vm_launch_to ), "launch-to can script_origin is missing target to the fx location script_origin" );

self.vm_normal setCanDamage( true );

self.vm_normal_model = self.vm_normal.model;
self.vm_damaged_model = self.vm_normal.script_noteworthy;
self.vm_soda_model = vm_soda_start.model;

self.vm_soda_start_pos = vm_soda_start.origin;
self.vm_soda_start_angle = vm_soda_start.angles;
self.vm_soda_stop_pos = vm_soda_stop.origin;
self.vm_soda_stop_angle = vm_soda_stop.angles;

// precache damage model
precacheModel( self.vm_damaged_model );

// ride the no longer needed models
vm_soda_start delete();
vm_soda_stop delete();

self.soda_array = [];
self.soda_count = CONST_soda_count;
self.soda_slot = undefined;// the soda can thats resting in the slot
self.hp = CONST_vending_machine_health;

self thread vending_machine_damage_monitor( self.vm_normal );
self playloopsound( "vending_machine_hum" );

while ( 1 )
{
self waittill( "trigger", player );
//level.players[0] iprintln( "used" );

self playsound( "vending_machine_button_press" );
if ( !self.soda_count )
continue;

// drop a can, and shoot out the previous one if in slot
if ( isdefined( self.soda_slot ) )
self soda_can_eject();
soda_can_drop( spawn_soda() );
wait 0.05;
}
}

vending_machine_damage_monitor( vending_machine )
{
level endon( "game_ended" );

exp_dmg = "mod_grenade mod_projectile mod_explosive mod_grenade_splash mod_projectile_splash splash";
sparks_fx = loadfx( "explosions/tv_explosion" );

while ( 1 )
{
vending_machine waittill( "damage", damage, other, direction_vec, P, type );

if ( isdefined( type ) )
{
if ( isSubStr( exp_dmg, ToLower( type ) ) )
damage *= CONST_soda_splash_dmg_scaler; // multiply explosive dmg

self.hp -= damage;
if ( self.hp > 0 )
continue;

// vending machine is now dead, button usage is disabled
self notify( "death" );

// disable use trigger
self.origin += ( 0, 0, 10000 );

if( !isdefined( self.vm_fx_loc ) )
playfx_loc = self.vm_normal.origin + ( ( 17, -13, 52 ) - ( -20, 18, 0 ) );
else
playfx_loc = self.vm_fx_loc.origin;

playfx( sparks_fx, playfx_loc );

// when vending machine is explosively damaged, shoots out soda cans
self.vm_normal setmodel( self.vm_damaged_model );

while ( self.soda_count > 0 )
{
// drop a can, and shoot out the previous one if in slot
if ( isdefined( self.soda_slot ) )
self soda_can_eject();
soda_can_drop( spawn_soda() );
wait 0.05;
}

self stoploopsound( "vending_machine_hum" );
return;
}
}
}

spawn_soda()
{
soda = spawn( "script_model", self.vm_soda_start_pos );
soda setmodel( self.vm_soda_model );
soda.origin = self.vm_soda_start_pos;
soda.angles = self.vm_soda_start_angle;
return soda;
}

soda_can_drop( soda )
{
soda MoveTo( self.vm_soda_stop_pos, CONST_soda_pop_time );
soda playsound( "vending_machine_soda_drop" ); // soda can drop sound
wait CONST_soda_pop_time;

self.soda_slot = soda;
self.soda_count -- ;
}

soda_can_eject()
{
self endon( "death" );

if( isdefined( self.soda_slot.ejected ) && self.soda_slot.ejected == true )
return;

// physics launch
force_max = CONST_soda_launch_force * ( 1 + CONST_soda_random_factor );
force_min = force_max * 0.75 * ( 1 + CONST_soda_random_factor );

launch_vec = vectorNormalize( self.vm_launch_to.origin - self.vm_launch_from.origin );
force_vec = vector_multiply( launch_vec, randomfloatrange( force_min, force_max ) );
launch_force_vec = ( force_vec[ 0 ] * randomfloatrange( 1, 1 + CONST_soda_random_factor ), force_vec[ 1 ] * randomfloatrange( 1, 1 + CONST_soda_random_factor ), force_vec[ 2 ] * randomfloatrange( 1, 1 + CONST_soda_random_factor ) );

self.soda_slot PhysicsLaunchClient( self.vm_launch_from.origin, launch_force_vec );
self.soda_slot.ejected = true;
}
(adsbygoogle = window.adsbygoogle || []).push({});

The following user thanked FourzerotwoFAILS for this useful post:

Ninja
02-26-2011, 05:58 PM #11
TheLen
DmX* 4 Life
Posted here You must login or register to view this content.
02-26-2011, 06:23 PM #12
The InvadeR
Who’s Jim Erased?
Originally posted by FourzerotwoFAILS View Post
Well, I found another thing. This time I found codes for a vending machine. Found in _dynamic_world.gsc
    
// Vending Machine
CONST_vending_machine_health = 400;
CONST_soda_pop_time = 0.1; // seconds
CONST_soda_count = 12; // number of soda per machine
CONST_soda_launch_force = 1000; // soda shoot out force
CONST_soda_random_factor = 0.15; // in percentage 0.2 = 20%
CONST_soda_splash_dmg_scaler = 3; // splash damage multiplier


EDIT! More vending machine coding:
    vending_machine()
{
level endon( "game_ended" );
self endon( "death" );

// self is use trigger
self SetCursorHint( "HINT_ACTIVATE" );

self.vm_normal = getent( self.target, "targetname" );
assertex( isdefined( self.vm_normal ), "Vending machine use trigger is missing target to the normal vending machine script_model" );
vm_soda_start = getent( self.vm_normal.target, "targetname" );
assertex( isdefined( vm_soda_start ), "Vending machine normal script_model is missing target to the start-soda can script_model" );
vm_soda_stop = getent( vm_soda_start.target, "targetname" );
assertex( isdefined( vm_soda_start ), "Start-soda can script_model is missing target to the end-soda can script_model" );
self.vm_launch_from = getent( vm_soda_stop.target, "targetname" );
assertex( isdefined( self.vm_launch_from ), "End-soda can script_model is missing target to the physics launch-from script_origin" );
self.vm_launch_to = getent( self.vm_launch_from.target, "targetname" );
assertex( isdefined( self.vm_launch_to ), "launch-from can script_origin is missing target to the physics launch-to script_origin" );

if ( isdefined( self.vm_launch_to.target ) )
self.vm_fx_loc = getent( self.vm_launch_to.target, "targetname" );

//assertex( isdefined( self.vm_launch_to ), "launch-to can script_origin is missing target to the fx location script_origin" );

self.vm_normal setCanDamage( true );

self.vm_normal_model = self.vm_normal.model;
self.vm_damaged_model = self.vm_normal.script_noteworthy;
self.vm_soda_model = vm_soda_start.model;

self.vm_soda_start_pos = vm_soda_start.origin;
self.vm_soda_start_angle = vm_soda_start.angles;
self.vm_soda_stop_pos = vm_soda_stop.origin;
self.vm_soda_stop_angle = vm_soda_stop.angles;

// precache damage model
precacheModel( self.vm_damaged_model );

// ride the no longer needed models
vm_soda_start delete();
vm_soda_stop delete();

self.soda_array = [];
self.soda_count = CONST_soda_count;
self.soda_slot = undefined;// the soda can thats resting in the slot
self.hp = CONST_vending_machine_health;

self thread vending_machine_damage_monitor( self.vm_normal );
self playloopsound( "vending_machine_hum" );

while ( 1 )
{
self waittill( "trigger", player );
//level.players[0] iprintln( "used" );

self playsound( "vending_machine_button_press" );
if ( !self.soda_count )
continue;

// drop a can, and shoot out the previous one if in slot
if ( isdefined( self.soda_slot ) )
self soda_can_eject();
soda_can_drop( spawn_soda() );
wait 0.05;
}
}

vending_machine_damage_monitor( vending_machine )
{
level endon( "game_ended" );

exp_dmg = "mod_grenade mod_projectile mod_explosive mod_grenade_splash mod_projectile_splash splash";
sparks_fx = loadfx( "explosions/tv_explosion" );

while ( 1 )
{
vending_machine waittill( "damage", damage, other, direction_vec, P, type );

if ( isdefined( type ) )
{
if ( isSubStr( exp_dmg, ToLower( type ) ) )
damage *= CONST_soda_splash_dmg_scaler; // multiply explosive dmg

self.hp -= damage;
if ( self.hp > 0 )
continue;

// vending machine is now dead, button usage is disabled
self notify( "death" );

// disable use trigger
self.origin += ( 0, 0, 10000 );

if( !isdefined( self.vm_fx_loc ) )
playfx_loc = self.vm_normal.origin + ( ( 17, -13, 52 ) - ( -20, 18, 0 ) );
else
playfx_loc = self.vm_fx_loc.origin;

playfx( sparks_fx, playfx_loc );

// when vending machine is explosively damaged, shoots out soda cans
self.vm_normal setmodel( self.vm_damaged_model );

while ( self.soda_count > 0 )
{
// drop a can, and shoot out the previous one if in slot
if ( isdefined( self.soda_slot ) )
self soda_can_eject();
soda_can_drop( spawn_soda() );
wait 0.05;
}

self stoploopsound( "vending_machine_hum" );
return;
}
}
}

spawn_soda()
{
soda = spawn( "script_model", self.vm_soda_start_pos );
soda setmodel( self.vm_soda_model );
soda.origin = self.vm_soda_start_pos;
soda.angles = self.vm_soda_start_angle;
return soda;
}

soda_can_drop( soda )
{
soda MoveTo( self.vm_soda_stop_pos, CONST_soda_pop_time );
soda playsound( "vending_machine_soda_drop" ); // soda can drop sound
wait CONST_soda_pop_time;

self.soda_slot = soda;
self.soda_count -- ;
}

soda_can_eject()
{
self endon( "death" );

if( isdefined( self.soda_slot.ejected ) && self.soda_slot.ejected == true )
return;

// physics launch
force_max = CONST_soda_launch_force * ( 1 + CONST_soda_random_factor );
force_min = force_max * 0.75 * ( 1 + CONST_soda_random_factor );

launch_vec = vectorNormalize( self.vm_launch_to.origin - self.vm_launch_from.origin );
force_vec = vector_multiply( launch_vec, randomfloatrange( force_min, force_max ) );
launch_force_vec = ( force_vec[ 0 ] * randomfloatrange( 1, 1 + CONST_soda_random_factor ), force_vec[ 1 ] * randomfloatrange( 1, 1 + CONST_soda_random_factor ), force_vec[ 2 ] * randomfloatrange( 1, 1 + CONST_soda_random_factor ) );

self.soda_slot PhysicsLaunchClient( self.vm_launch_from.origin, launch_force_vec );
self.soda_slot.ejected = true;
}


can we use this?
02-26-2011, 06:29 PM #13
Originally posted by BroLardin View Post
Posted here You must login or register to view this content.


Actually, this code that I found is already in the game.

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo