Modme Forums

Spawning a model via scrips

Game Modding | Call of Duty: Black Ops 3 | Scripting


ModmeBot:

Thread By: mathfag

Im making a easter egg step where you take a model and place it on a box (I have this part figured out). My question is how to i make this model spawn on the box after i place it there and play an effect?


ModmeBot:

Reply By: natesmithzombies

You need to add a script_struct where you want the model to spawn. Give it the correct targetname and model KVP and then add the following code in the right places in your script:

// add this above your function main()
#precache( "model", "model_name_here" );

#define SPAWN_FX			"_NSZ/Brutus/spawn_fx" // the second part of this is the directory of the FX
#precache( "fx", SPAWN_FX ); 


// call this function to spawn it 
function spawn_model()
{
	place_spot = struct::get( "place_spot", "targetname" ); // if you get an error on this line add this to the top of your .gsc: #using scripts\codescripts\struct;
	model = spawn( "script_model", place_spot.origin ); 
	model SetModel( place_spot.model ); 
	model PlayLoopSound( "loop_sound_here" ); // if you want it to play a loop sound use this line 
	PlayFxOnTag( SPAWN_FX, model, "tag_origin" ); 
}

// Add to your map zone
xmodel,model_name_here
fx,_NSZ/Brutus/spawn_fx


ModmeBot:

Reply By: mathfag

natesmithzombies

You need to add a script_struct where you want the model to spawn. Give it the correct targetname and model KVP and then add the following code in the right places in your script:

// add this above your function main()
#precache( "model", "model_name_here" );

#define SPAWN_FX			"_NSZ/Brutus/spawn_fx" // the second part of this is the directory of the FX
#precache( "fx", SPAWN_FX ); 


// call this function to spawn it 
function spawn_model()
{
	place_spot = struct::get( "place_spot", "targetname" ); // if you get an error on this line add this to the top of your .gsc: #using scripts\codescripts\struct;
	model = spawn( "script_model", place_spot.origin ); 
	model SetModel( place_spot.model ); 
	model PlayLoopSound( "loop_sound_here" ); // if you want it to play a loop sound use this line 
	PlayFxOnTag( SPAWN_FX, model, "tag_origin" ); 
}

// Add to your map zone
xmodel,model_name_here
fx,_NSZ/Brutus/spawn_fx

Also how would I change the angle of the model


ModmeBot:

Reply By: natesmithzombies

mathfag
natesmithzombies

You need to add a script_struct where you want the model to spawn. Give it the correct targetname and model KVP and then add the following code in the right places in your script:

This is what I added and nothing spawned but the lighting state changed so the script is called

Script struct is called "place_spot"

function gateworm_place()
 
{
 
place_spot = struct::get( "place_spot", "targetname" ); // if you get an error on this line add this to the top of your .gsc: #using scripts\codescripts\struct;
 
model = spawn( "script_model", place_spot.origin );
 
model SetModel( "p7_zm_zod_relic_boxer" );
 
// model PlayLoopSound( "loop_sound_here" ); // if you want it to play a loop sound use this line
 
// PlayFxOnTag( SPAWN_FX, model, "tag_origin" );
 
level util::set_lighting_state(3);
}



Also how would I change the angle of the model

Did you precache the model and add it to zone? You should really add the KVP:

model - p7_zm_zod_relic_boxer

to the struct as I stated. It is much cleaner and allows for dynamic updating in Radiant instead of through script. To add the angles you can simply do:

model.angles = place_spot.angles;


ModmeBot:

Reply By: mathfag

natesmithzombies
mathfag
natesmithzombies

You need to add a script_struct where you want the model to spawn. Give it the correct targetname and model KVP and then add the following code in the right places in your script:

This is what I added and nothing spawned but the lighting state changed so the script is called

Script struct is called "place_spot"

function gateworm_place()
 
{
 
place_spot = struct::get( "place_spot", "targetname" ); // if you get an error on this line add this to the top of your .gsc: #using scripts\codescripts\struct;
 
model = spawn( "script_model", place_spot.origin );
 
model SetModel( "p7_zm_zod_relic_boxer" );
 
// model PlayLoopSound( "loop_sound_here" ); // if you want it to play a loop sound use this line
 
// PlayFxOnTag( SPAWN_FX, model, "tag_origin" );
 
level util::set_lighting_state(3);
}



Also how would I change the angle of the model

Did you precache the model and add it to zone? You should really add the KVP:

model - p7_zm_zod_relic_boxer

to the struct as I stated. It is much cleaner and allows for dynamic updating in Radiant instead of through script. To add the angles you can simply do:

model.angles = place_spot.angles;

Thank you very much for your help. Everything works fine now. It turns out I just made an almoast invisible spelling mistake.

for the noobs:

function gateworm_place()
{
    place_spot = struct::get( "place_spot", "targetname" ); // if you get an error on this line add this to the top of your .gsc: #using scripts\codescripts\struct;
    model = spawn( "script_model", place_spot.origin ); 
    model.angles = place_spot.angles;
    model SetModel( "p7_zm_zod_relic_boxer" );
//    model PlayLoopSound( "loop_sound_here" ); // if you want it to play a loop sound use this line 
//    PlayFxOnTag( SPAWN_FX, model, "tag_origin" ); 
    wait(5);
    level util::set_lighting_state(3);
}