Game Development Community

Custom player event control triggers.

by Samuel Weeks · in Torque Game Engine · 03/27/2009 (4:15 am) · 10 replies

I have been searching the forums for a couple days now trying to wrap my head around how player event controls triggers work and although i have found some very good post i still haven't found the answers im looking for.

I do (for the most part) understand that several of the $mvTriggers are already scripted for us out of the box. What i'm looking for is a couple good examples of how i could go about writing my own scripts for taking advantage of the remaining non used triggers ($Mvtrigger4,$Mvtrigger5) or even replacing the current ones.

I guess for you to better help me i should explain what i currently (think)i know and what it is that puzzles me.

1) on the client side there is a keybind to call the function
----------------------------------------------
//moveMap.bind( mouse, button0, mouseFire );
-----------------------------------------------
2) the function is called
----------------------------------------------
// function mouseFire(%val)
// {
// $mvTriggerCount0++;
// }
-------------------------------------------------
3) by doing my research i was able to find that when an %Mvtrigger is incremented on the client then it is incremented on the server.

4) on every game tick the server will decrement the $Mvtrigger and in so doing it will cause an action to happen in the game world.

after doing deep digging in the engine i noticed that it already had code for handling the weapon triggers... that's all good and well but when i look at the jump and movement $Mvtriggers. i don't see any fancy engine code for them.

this is where i think the real hole in my understanding of $mvtriggers is.
- how do i get the server to do things with the triggers that are not already coded, or i should say where and how do i write the server side of the $mvtriggers.

#1
03/27/2009 (2:53 pm)
Have you figured out the purpose of the Move struct? It collects a set of inputs from the client andtransmits them to the server, as I understand it. Player (and other) objects are given Moves to process their movement - take a look at Player::updateMove. Have a look for uses of move->trigger in the function to see how your trigger inputs translate to doing things to the player.
#2
03/27/2009 (6:02 pm)
thx for the reply, yeah i took a look at Player::updateMove. and most the engine code is a little to much over my head. if you have a good understanding of it, do you think u can show me how u would use scripts to make new triggers or overwrite the old ones?
- i guess i don't really need to understand completely how it works, i just need some examples i can modify and that will be good enough for me.
#3
03/28/2009 (1:31 am)
What do you need these new triggers to do? It's probably possible to do in script - when you detect mouse input, for example, instead of invreasing the trigger count, you can perform your own function.
#4
03/28/2009 (12:26 pm)
Daniel thank you so much for working with me on this.

"instead of invreasing the trigger count, you can perform your own function. "

sorry for sounding really stupid, but thats the part i dont get. i do understand how to type the script on the client side. pretty much just call a function that does $mvtrigger0-5++. but the thing is i have no idea how to tell the server what to do when a client increments a $mvtrigger.

im not really a c++ guru, its very hard for me to look at the source code and keep up with whats going on. i only said everything i know about the engine coded $mvtriggers to show that im not being lazy and i really did put in alot of time into trying to figure it out.

after all the work i have done im really only sure of two things.
1) even though i dont completely understand how $mvtriggers work, i know enough about the built in triggers to just use them as in in my games.
2) i know that it is possible to to script the last two triggers with out touching any source code.

#2 is my problem. although i know its possible i don't understand how to do this.

for example lets say i wanted to make a function that makes the player move forward a super speed but i wanted to do so without modifying the already defined $Mvtriggers. instead i wanted it to be its own trigger $Mvtrigger5
// i know i write this part of the function ion the client side
function Move_At_SuperSpeed(%val)
{
$mvtrigger5++
}

so here is my confusion where do i define what this function does.
how do i tell the server what do do when this trigger is incremented.

can you please show me an example of how you would use and define $mvtrigger5 in script on. it doesn't really matter what u make the trigger do, i just need to see how u would write it on the client side and get the server side to understand it and allow it to happen.


i have be trying really hard to follow the code my steping in the dedugger, for exapmple i set a break point beside the moveleft function when my player moves left the game pauses, when i step the program instead of going to the server side code where the server is told to move the player left.. the player is just moved left. so basically what im saying is that
#5
03/28/2009 (12:38 pm)
Okay, I'm going to focus on your super-speed example, since it's something I vaguely know how to do. But first, a word about what you want to do.

You want to be able to say $mvTriggerCount5++, and use the result in script. As far as I know, you can't. This variable is used by the engine to gather movement data into the Move struct - but it isn't used by any scripts, only by the engine.

Keeping that in mind, if you dig into the engine code, you can make triggers do anything you want. Have another look at Player::updateMove and see where it uses move->trigger (just do a search for move->trigger in the file). There are multiple triggers, hence the number appended after 'trigger'. By using your own numbers (in your example, 5), you can add behaviour for your triggers. Here's a quick example.
I'm going to assume you know how to compile the engine and make code changes.
You should find this bit of code in the function:
// Update current orientation
   if (mDamageState == Enabled) {
This basically says that if we're not destroyed, we can run the code that allows us to turn. Now, change that code to read like this:
// Update current orientation
   if (mDamageState == Enabled && !move->trigger[5]) {
Now, whenever trigger 5 is down, you won't be able to turn. Recompile your code. Also, add a function like the one you wrote above, which increments trigger 5, and just bind it to any old key.
If I've done this right, you *should* be able to press your trigger key, and your Player will be unable to turn.

This is just a silly example, but it shows you how to use triggers in coding. Have a look at some resources - I'd do a search for 'get jetting'. These will show you how to implement things like changing your character's movement. There's also a sprint resource that actually adds a new parameter to the Move struct, which should be a good learning experience.
#6
03/28/2009 (1:45 pm)
thanks a bunch Daniel. i was really hoping to do this without having to change the engine code. but it looks like i might have to get my hands dirty after all. i think you given me a very good starting point to figuring this out.


i owe ya one i really do. welp guess its time for me to take a dive into the source code
#7
03/28/2009 (11:35 pm)
Of course, if you want to do something simpler, you can use scripts. For example, if you want a 'trigger' to cause, um... a super-high jump, you could simply write a function and bind it to the trigger key. This function would shoot off a server command, which would apply an impulse to the client's player to make them jump super high. Some things can be scripted, but more fundamental changes should be done in code.
Glad to be of service!
#8
03/29/2009 (7:19 am)
servercmds was the way i was gonna Handel a lot of player action. but i read somewhere that mvtriggers offed much better response for the client.

i guess i dont need every player action to be a trigger so i will do alot of them as server cmds.
#9
03/29/2009 (8:38 am)
Yep, I think you heard right. Things that don't need to be extremely fast, and can't be done better in code, can be handled fine via server commands - I'm planning on doing things like picking up items and opening doors via server commands. However, things like movement, where the player relies on having very fine and instantaneous control, should not be handled that way.
#10
03/29/2009 (10:06 am)
hey Daniel hit me up at dementedangst@yahoo.com when u got time. i to speak with you about something.