Modme Forums
Menu:

[Tutorial] How To Move The Player / With Entities

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


ModmeBot:

Thread By: CT8918

[Tutorial] How To Move The Player / With Entities

By: CT8918



Here is a script that moves a player gradually from point A to point B. Not a teleporting script.

I created this because when an entity is moving below a player, the player just slides off.

This script allows the player to move with the entity. Could also be used for other things as well.



Special thanks to DTZxPorter and EnCore Modding for helping me figure out what move functions to use.



/*
Script: move_player
Author: CT8918 
Date Created: 3/9/2017
Move Function Help: DTZxPorter and EnCore Modding
Used initially in the map "Mortuus-Arena." Coming Soon...

Put in mapname.gsc (Located in Call of Duty Black Ops III\usermaps\mapname\scripts\zm)

My implementation was for moving the player on top of a moving zamboni.

HOW TO USE
1. 	Create Trigger with these two kvps:
		[Change Value] 		property: targetname 			value: name_your_function_trig (I used: ride_zamboni_trig) 
		[Add KVP]			property: target				value: point1
	
2. 	Create a script_origin where you want the player to start from with two kvps needed and one optional kvp:
		[Change Value] 		property: targetname 			value: point1
		[Add KVP Needed]	property: target				value: point2
		[Add KVP Optional]	property: model					value: c_t6_default_character_fb (This allows you to see where player will be.)
	
3. 	Create a script_origin where you want the player to end up with one kvp needed and one optional kvp:
		[Change Value] 		property: targetname 			value: point2
		[Add KVP Optional]	property: model					value: c_t6_default_character_fb (This allows you to see where player will be.)
	
4. 	Edit script below making sure the functions match each other. I have default names. 
		Use Ctrl+H to find and replace names. Find "name_your_function" and replace with whatever you want.
	
	Make sure to change:
		name_your_function_array = GetEntArray("name_your_function_trig", "targetname");
*/

//TO INITIALIZE - Place wherever you want the function's Trigger to be initialized at.
	thread name_your_function_init();

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
//FUNCTIONS TO MOVE PLAYER
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
FUNCTION: name_your_function_init 
Initializes the process of moving the player.
Can add a cost to how much the trigger will cost.
Gets the path of the player and stores in an array.
Precondition: Need to have a trigger, a point1 script_origin, and a point2 script_origin.	
*/
function name_your_function_init()
{
    level.name_your_function_cost = 500; //Cost to start moving (not needed).
 
    name_your_function_array = GetEntArray("name_your_function_trig", "targetname"); //Gets Point1 and Point2
 
    for(i=0;i<name_your_function_array.size;i++) {="" name_your_function_array[i]="" thread="" name_your_function_think();="" }="" }="" *="" function:="" name_your_function_think="" waits="" for="" the="" trigger="" to="" be="" used="" and="" then="" calls="" the="" function(s)="" to="" run.="" precondition:="" run="" "thread="" name_your_function_init();"="" in="" main="" or="" where="" you="" need="" it.="" */="" function="" name_your_function_think()="" {="" self="the" trigger="" self="" sethintstring("press="" ^3[{+activate}]="" ^7to="" ride="" the="" zamboni.="" [cost:="" "="" +="" level.name_your_function_cost="" +="" "]");="" self="" setcursorhint("hint_noicon");="" point1="GetEnt(self.target," "targetname");="" point2="GetEnt(point1.target," "targetname");="" while="" loop="" to="" allow="" a="" reuse="" of="" the="" trigger.="" if="" one="" and="" done,="" remove="" this="" one="" and="" delete="" trigger="" at="" the="" end.="" while(1)="" {="" while="" loop="" to="" wait="" for="" player="" input.="" while(1)="" {="" self="" waittill("trigger",="" player);="" if(player.score="">= level.name_your_function_cost)
            {
                player.score -=(level.name_your_function_cost); //Deducts the points from player. If free, do not include.
				//player thread driveZamboni(); //This is what I used to move the Zamboni's brushmodels and models. Included example at bottom.
                player thread name_your_function_move_player(point1, point2); //This is what actually moves the player.
				//self Delete(); //Deletes the trigger. Remove comments if one and done.
                break;
            }
        }
    }
}

/*
FUNCTION: name_your_function_move_player 
Moves the player from point1 to point2.
Precondition: Run "thread name_your_function_init();" in main or where you need it.
*/
function name_your_function_move_player(point1, point2)
{
    self EnableInvulnerability(); //Just a precaution. Unfair if player dies frozen. 

    WAIT_SERVER_FRAME;

    self thread look_at(point2); //Fixes player gaze and prevents any body glitches.

    origin = spawn("script_model", point1.origin);
    origin setModel("tag_origin");
    self SetOrigin( origin.origin );
    self PlayerLinkTo(origin, "tag_origin");

    origin MoveTo( point2.origin, 30, 3, 0 ); //MoveTo((<point[a vector]="">,<time>,[acceleration time],[deceleration time])
    origin waittill("movedone");

    self notify("arrived_at_point2"); //Player can now by "unlocked."
    self FreezeControls(false);
    self DisableInvulnerability(); //Removes the precaution. Player may now die if zombies there. May need to add delay.
    origin Delete(); 
}

/*
FUNCTION: look_at 
Does not allow player to move and locks the players gaze at point2.
Precondition: Run "thread name_your_function_init();" in main or where you need it.
*/
function look_at(point)
{
    self endon("arrived_at_point2");
    while(1)
    {
		//"Locks" the player in place.
		self SetPlayerAngles(point.angles); 
		self FreezeControls(true);
		WAIT_SERVER_FRAME;
    }
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//END FUNCTIONS TO MOVE PLAYER
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
//BONUS FUNCTION!!!
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

/*
FUNCTION: drive_zamboni
THIS IS THE FUNCTION I USED TO MOVE ZAMBONI(THE THING BELOW MY PLAYER).
Use only as a reference.
***DO NOT COPY INTO YOUR CODE BECAUSE "level.zamboni" HAS NOT BEEN DECLARED*** 
*/
function drive_zamboni()
{
	/*	
	I have the zamboni array as a level variable since I used it before.
	To get everything the zamboni was made out of, I gave every 
	script_brushmodel's and script_model's the targetname of "zamboni_components."	
	I then used this code segment to select them all:
		level.zamboni = getEntArray( "zamboni_components", "targetname" );
	This allows me to move them all together using a for loop.
	You can use this with anything in a map to move in a straight line. Rotate throws stuff out of place.
	*/

	level.zamboni[0] playsound("start_engine"); //Engine sound I have. Had to specify a specific brush/model so I used [0].
	wait(3);
	level.zamboni[0] playsound("zamboni13s"); //Driving sound for 30 seconds.
		
	//This is what I used to move the zamboni to where I wanted it to go. Used a for loop for every component to move.
	for(i = 0; i < level.zamboni.size; i++)
	{
		//Match the units with the player.
		level.zamboni[i] movey(-1888, 30, 3, 0); //I have point2 located -1888 y units away from point1.
	}
	wait(30); //This is how long I used for the Zamboni to move.
	
	//Deletes or resets the components. Could have used: movey(1888, 30, 3, 0) to go back to initial smoothly.
	for(i = 0; i < level.zamboni.size; i++)
	{
		//level.zamboni[i] movey(1888, 0.0000001, 0, 0); //Yanked back for reuse.
		level.zamboni[i] delete(); //The zamboni has been taken away!  
	}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//END BONUS FUNCTION
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
</time></point[a></name_your_function_array.size;i++)>