UGX-Mods

Call of Duty: Black Ops 3 => Help Desk => Scripting => Topic started by: divinefury5 on December 05, 2016, 10:33:51 am

Title: Minecart
Post by: divinefury5 on December 05, 2016, 10:33:51 am
Hey can someone help me with a script for a moveable minecart when you purchase you will be riding from A to B ? Like in the map Minecraft v1.2 with the  boat.
Thanks for helping
Title: Re: Minecart
Post by: MakeCents on December 06, 2016, 09:06:35 pm
Hey can someone help me with a script for a moveable minecart when you purchase you will be riding from A to B ? Like in the map Minecraft v1.2 with the  boat.
Thanks for helping

Setup a trigger multiple and target the cart model. Then target a struct where the cart will end up. Then target a script_brushmodel from the cart. Then cut that brushmodel and wrap your cart with it. Place the trigger multiple in the base of the cart, just above the script_brushmodel.


Code Snippet
Plaintext
#using scripts\shared\array_shared;
#using scripts\codescripts\struct;

/*
#####################
by: M.A.K.E C E N T S
#####################
Script:

Add to main in mapname.gsc
cart::init(  );

Add to top of mapname.gsc
#using scripts\zm\cart;

Add to zone file
scriptparsetree,scripts/zm/cart.gsc


//below > stands for autotargets
trigger_multiple at bottome of cart>
cartmodel at starting position>
brush_models wrapping the cart
struct, just one, where you want it to end
###############################################################################
*/

#namespace cart;

function init()
{
level.carttime = 10;//adjust time it takes to get to other station
level.cartloop = true;
carts = GetEntArray("carts","targetname");//triggers
array::thread_all(carts, &CartSetup);
}
function CartSetup()
{
cart = GetEnt(self.target,"targetname");
self EnableLinkTo();
self linkto(cart);
cart LinkPeices();
self thread CartMove(cart);
}
function CartMove(cart)
{
cart.a = cart.origin;
cart.b = struct::get(cart.target, "targetname").origin;
while(1)
{
self waittill("trigger");
self MoveToNext(cart);
wait(.05);
}
}
function MoveToNext(cart)
{
if(Distance(cart.origin,cart.a)<10)
{
cart MoveTo(cart.b,level.carttime);
}
else
{
cart MoveTo(cart.a,level.carttime);
}
wait(level.carttime);
wait(2);//waits so the cart doesn't go back right away
}
function LinkPeices()
{
peices = GetEntArray(self.target,"targetname");
foreach(p in peices)
{
p LinkTo(self);
}
}
Title: Re: Minecart
Post by: Blink-420 on December 07, 2016, 01:56:54 pm
Setup a trigger multiple and target the cart model. Then target a struct where the cart will end up. Then target a script_brushmodel from the cart. Then cut that brushmodel and wrap your cart with it. Place the trigger multiple in the base of the cart, just above the script_brushmodel.


Code Snippet
Plaintext
#using scripts\shared\array_shared;
#using scripts\codescripts\struct;

/*
#####################
by: M.A.K.E C E N T S
#####################
Script:

Add to main in mapname.gsc
cart::init(  );

Add to top of mapname.gsc
#using scripts\zm\cart;

Add to zone file
scriptparsetree,scripts/zm/cart.gsc


//below > stands for autotargets
trigger_multiple at bottome of cart>
cartmodel at starting position>
brush_models wrapping the cart
struct, just one, where you want it to end
###############################################################################
*/

#namespace cart;

function init()
{
level.carttime = 10;//adjust time it takes to get to other station
level.cartloop = true;
carts = GetEntArray("carts","targetname");//triggers
array::thread_all(carts, &CartSetup);
}
function CartSetup()
{
cart = GetEnt(self.target,"targetname");
self EnableLinkTo();
self linkto(cart);
cart LinkPeices();
self thread CartMove(cart);
}
function CartMove(cart)
{
cart.a = cart.origin;
cart.b = struct::get(cart.target, "targetname").origin;
while(1)
{
self waittill("trigger");
self MoveToNext(cart);
wait(.05);
}
}
function MoveToNext(cart)
{
if(Distance(cart.origin,cart.a)<10)
{
cart MoveTo(cart.b,level.carttime);
}
else
{
cart MoveTo(cart.a,level.carttime);
}
wait(level.carttime);
wait(2);//waits so the cart doesn't go back right away
}
function LinkPeices()
{
peices = GetEntArray(self.target,"targetname");
foreach(p in peices)
{
p LinkTo(self);
}
}

Awesome :) Question though. Is there a way to make this go say in a circle. For example, go half around a city block, stop then when used again going back to the beginning?
Title: Re: Minecart
Post by: MakeCents on December 07, 2016, 02:05:29 pm
It's a very simple script and is only setup currently to go from one point to the next, then back, in a straight line.

If your going to make turns I'd recommend learning more about vehicle nodes. I've used structs before, and it is possible. If it is the better solution for you to use structs, I would set them up as the target of each, turning them as it goes around the track. Then in script turn the cart to the next structs angle over the time it takes the cart to get there, continuing this until you have defined a kvp that says to stop. In the end you would have a loop of structs as each the target of the previous, with two of them having kvps to stop it. MoveToNext function would be edited to make this happen. I would suggest a while loop, that checks for that kvp. When defined and equal to stop, it would stop. In the while loop I would get the distance to the next struct, which would be the target of the current struct, and the angle of the next struct. Rotate to that angle and move to that struct, track the last struct, and wait the time it takes.
Title: Re: Minecart
Post by: Snprym on December 10, 2016, 01:41:04 pm
as a noob, how do i " target" a model? Do i make a new kvp target?
Title: Re: Minecart
Post by: Blink-420 on December 10, 2016, 08:17:43 pm
Setup a trigger multiple and target the cart model. Then target a struct where the cart will end up. Then target a script_brushmodel from the cart. Then cut that brushmodel and wrap your cart with it. Place the trigger multiple in the base of the cart, just above the script_brushmodel.


Code Snippet
Plaintext
#using scripts\shared\array_shared;
#using scripts\codescripts\struct;

/*
#####################
by: M.A.K.E C E N T S
#####################
Script:

Add to main in mapname.gsc
cart::init(  );

Add to top of mapname.gsc
#using scripts\zm\cart;

Add to zone file
scriptparsetree,scripts/zm/cart.gsc


//below > stands for autotargets
trigger_multiple at bottome of cart>
cartmodel at starting position>
brush_models wrapping the cart
struct, just one, where you want it to end
###############################################################################
*/

#namespace cart;

function init()
{
level.carttime = 10;//adjust time it takes to get to other station
level.cartloop = true;
carts = GetEntArray("carts","targetname");//triggers
array::thread_all(carts, &CartSetup);
}
function CartSetup()
{
cart = GetEnt(self.target,"targetname");
self EnableLinkTo();
self linkto(cart);
cart LinkPeices();
self thread CartMove(cart);
}
function CartMove(cart)
{
cart.a = cart.origin;
cart.b = struct::get(cart.target, "targetname").origin;
while(1)
{
self waittill("trigger");
self MoveToNext(cart);
wait(.05);
}
}
function MoveToNext(cart)
{
if(Distance(cart.origin,cart.a)<10)
{
cart MoveTo(cart.b,level.carttime);
}
else
{
cart MoveTo(cart.a,level.carttime);
}
wait(level.carttime);
wait(2);//waits so the cart doesn't go back right away
}
function LinkPeices()
{
peices = GetEntArray(self.target,"targetname");
foreach(p in peices)
{
p LinkTo(self);
}
}

Also, I cant get this to work. I know I've set it up just like you said. I dont know if you forgot but I gave the script_multiple a targetname of carts like it says in the script and still didnt work. Any ideas why?
Title: Re: Minecart
Post by: MakeCents on December 10, 2016, 11:16:40 pm
Also, I cant get this to work. I know I've set it up just like you said. I dont know if you forgot but I gave the script_multiple a targetname of carts like it says in the script and still didnt work. Any ideas why?

Tested, and works fine.

Here is a prefab if you are having difficulty:
http://www.mediafire.com/file/7aw0e36jaed2qt9/cart_moving.rar (http://www.mediafire.com/file/7aw0e36jaed2qt9/cart_moving.rar)