Author Topic: Key Functions  (Read 2041 times)

I had several ideas for scripts but i'm missing a few keyboard functions.
-How do i detect if a key is being held down/is released/was just pressed?
-How do i detect what keys are currently being held down? If i know the above i could just set up a loop or something.
-How do i simulate a keypress?

And a few other things i should ask about:
-Exactly what does the operator "^" do?
-I'm also trying to make a mod that creates crosshairs over other players. Just for coolness. How would I convert a 3D position into a 2D position, and test if it would be offscreen?
-Why does player.setPosition("x y z"); crash the server, as opposed to player.position = "x y z"?
-What happens when you reach 100k X/Y on the map? 1mil?
-I found out spawning many projectiles at once makes you ghost. Whyzat? I thought that's only for bricks.
-Does using > instead of >= do anything besides change the operator type?
-What does if(!%var) do? I used it for a ServerCmd to show if it had the right number of arguments and it didn't work.
-How do i get the range and angle from/to two objects? I use a big complicated structure involving getPosition(), ifs, and a lot of subtraction.

-What's the best way to spawn a bot that Blockland treats like a player? Testing purposes.
--If possible, include a way to give it a client and make a new clientobject.
-Is there a way to tumble a player without actually tumbling the player? (Set aim)
-Is there a way to switch the controlobject of two players/vehicles/etc? I've tried and it crashes everyone.
« Last Edit: August 06, 2011, 02:20:33 PM by ThinkInvisible »

I had several ideas for scripts but i'm missing a few keyboard functions.
-How do i detect if a key is being held down/is released/was just pressed?
-How do i detect what keys are currently being held down? If i know the above i could just set up a loop or something.
-How do i simulate a keypress?

And a few other things i should ask about:
-Exactly what does the operator "^" do?
-I'm also trying to make a mod that creates crosshairs over other players. Just for coolness. How would I convert a 3D position into a 2D position, and test if it would be offscreen?
-Why does player.setPosition("x y z"); crash the server, as opposed to player.position = "x y z"?
-What happens when you reach 100k X/Y on the map? 1mil?
-I found out spawning many projectiles at once makes you ghost. Whyzat? I thought that's only for bricks.
-Does using > instead of >= do anything besides change the operator type?
-What does if(!%var) do? I used it for a ServerCmd to show if it had the right number of arguments and it didn't work.
-How do i get the range and angle from/to two objects? I use a big complicated structure involving getPosition(), ifs, and a lot of subtraction.


#1: http://forum.blockland.us/index.php?topic=162665.msg3986250#msg3986250


#2: This is a "Bitwise XOR", this is straight from the TAG: "Example: $a ^ $b, Explanation: composite of elements where bits in the same position are opposite. (i.e. 100b & 101b == 001b)"
#3: You'd still be working with 3D coordinates, therefore you wouldn't need to convert them into 2D coordinates (which is impossible because 3D has three axises and 2D has two axises).
#4: You are probably using the first function incorrectly, while the second one is editing the players position, not setting it.
#5: Nothing, the terrain just repeats. If you are on Slate then the ground will be "no-collide" and you'll fall in water but that is it.
#6: I assume your game needs to "render" those projectiles putting you into a ghosting state.
#7: Nope.
#8: If %var is equal to 0 then run what ever is in the if statement. If you didn't have the '!' in front of it, then it would be if %var is equal to 1 then run whatever is in the if statement.
#9: If your function works, use it.

#1: http://forum.blockland.us/index.php?topic=162665.msg3986250#msg3986250


#2: This is a "Bitwise XOR", this is straight from the TAG: "Example: $a ^ $b, Explanation: composite of elements where bits in the same position are opposite. (i.e. 100b & 101b == 001b)"
#3: You'd still be working with 3D coordinates, therefore you wouldn't need to convert them into 2D coordinates (which is impossible because 3D has three axises and 2D has two axises).
#4: You are probably using the first function incorrectly, while the second one is editing the players position, not setting it.
#5: Nothing, the terrain just repeats. If you are on Slate then the ground will be "no-collide" and you'll fall in water but that is it.
#6: I assume your game needs to "render" those projectiles putting you into a ghosting state.
#7: Nope.
#8: If %var is equal to 0 then run what ever is in the if statement. If you didn't have the '!' in front of it, then it would be if %var is equal to 1 then run whatever is in the if statement.
#9: If your function works, use it.


#3: But how do I display a crosshair on a 2D GUI which seems like it's above the player in the 3D game?
#8: What i meant is:
function servercmdlolblargh(%c, %a, %b) {
 if(!%b) { //asdf
  //%b was not defined, so they must have thought a was b.
  return;
 }
 dostuff(%a, %b);
}

%b always registers as %a in this case, making //asdf always trigger.

#9: It's huge. And messy. And i really think there's a better method.

EDIT: #1: Idungetit.
« Last Edit: August 06, 2011, 02:28:45 PM by ThinkInvisible »


#3: But how do I display a crosshair on a 2D GUI which seems like it's above the player in the 3D game?
#8: What i meant is:
function servercmdlolblargh(%c, %a, %b) {
 if(!%b) { //asdf
  //%b was not defined, so they must have thought a was b.
  return;
 }
 dostuff(%a, %b);
}

%b always registers as %a in this case, making //asdf always trigger.


#9: It's huge. And messy. And i really think there's a better method.
#3: If you're trying to do it client-sided, you'll need to spawn client-sided bots are the players and spawn or display images above them. It's very inefficient and does not work properly without a powerful machine.
#8: if(%b $= ""), if the variable was not defined then it should come out as null, in which case you would check to see if it's string equals null.
#9: I'll see if I can get a clean one working or find a clean one.

EDIT: To explain #1:
$remapDivision[$remapCount] = "KEYBINDCATEGORYNAME"; This will put your keybind under CATEGORYNAME in the menu.
$remapName[$remapCount] = "KEYBINDNAME"; This is the actual name of the keybind in the menu.
$remapCmd[$remapCount] = "FUNCTIONNAMEHERE"; This will be the function that is called when the key is pressed.
« Last Edit: August 06, 2011, 02:45:44 PM by Daenth »

Oh, and

#1: I need it to be for any key, not just a keybinded key

Adding onto/correcting Daenth's first post

4. Are you trying to do this clientside or serverside? If serverside, I don't know, if clientside, why are you trying to do this anyways? It won't work.
5. When you get out to distances very far from the origin (several million) the view starts glitching, eventually reaching the point of being unplayable
7. > means 'greater than' and >= means 'greater than or equal two' for example '5 > 5' is false, but '5 >= 5' is true.
8. ! means inverse. The inverse of 0 is 1, and the inverse of any non-zero value is 0.
9. Range between two objects, use VectorDist(pos1,pos2). As for angle, explain how you can have an angle with only two points defined?

Adding onto/correcting Daenth's first post

4. Are you trying to do this clientside or serverside? If serverside, I don't know, if clientside, why are you trying to do this anyways? It won't work.
5. When you get out to distances very far from the origin (several million) the view starts glitching, eventually reaching the point of being unplayable
7. > means 'greater than' and >= means 'greater than or equal two' for example '5 > 5' is false, but '5 >= 5' is true.
8. ! means inverse. The inverse of 0 is 1, and the inverse of any non-zero value is 0.
9. Range between two objects, use VectorDist(pos1,pos2). As for angle, explain how you can have an angle with only two points defined?
4: Clientside. And yeah it's possible i just need a ton of math stuff.
5. WHEEEEEEEEE
7. But does changing it do anything besides that?
8. I know that but the command isn't working right for sooooome reason.

9. Thanks, and ohhhh it's a vector i need.

4: Clientside. And yeah it's possible i just need a ton of math stuff.
No, you can not use setPosition/setTransform clientside. If you could, you'd see a lot of people doing it to go wherever they want.

No, you can not use setPosition/setTransform clientside. If you could, you'd see a lot of people doing it to go wherever they want.

what-oh.
i thought it was the crosshair one.
no, setPosition apparently breaks stuff if used on player

what-oh.
i thought it was the crosshair one.
no, setPosition apparently breaks stuff if used on player

What does this mean?

@above:
i thought Headcrab was referring to the question about crosshair.
setPosition, used on a player, crashes blockand for some reason.
player.setposition("x y z");
However, position =  does not.
player.position = "x y z";


I found out what happens at extreme axis values. Tested on Creek map.

At 1k, nothing. This is a normal, walking-reachable(in about half an hour maybe :P) value.
-Nothing. Just for comparison.

At 10k, almost nothing. Stuff starts vibrating maaaybe a little.
-No visible difference. Almost.

At 100k, water and your player twitch.
-Water twitches
-Player twitches

At 1mil, stuff breaks.
-Hard to build
-Particles are misshapen
-Ground has holes
-Water has holes and is badly misshapen
-Vehicles shake some
-Short bricks disappear almost completely
-A tall column of bricks appears to be bent and twisted
-Player looks odd

At 10mil, a lot of stuff breaks and your blockland freezes eventually.
-Holes in the ground
-Ground collision is separate from ground appearance
-Can't place bricks right
-Projectile trails zigzag crazily
-Can't move until at extreme velocity, then you shift over a long way
-Water has lots of holes
-Terrain and water shift holes and shape crazily
-You can fall through the ground in places
-Can't see bricks right
-Player twitches crazily
-Held item separates from hand
-Other stuff breaks
-Potential blockland crash
-Player resizes crazily

At 100mil, calamity.
-Player resizes to no end
-Held item resizes to no end
-Stuff breaks
-No terrain
-No water
-Falling endlessly
-Can't move
-Can barely see

At 1bil, nothing. Similar to player-deleted.
-Images leave trails
-Can't see because of above
-I think i got some console errors
-Stuff probably breaks
-Can't move
-Can barely see chat

You can't go to 10bil. It sends you back to the start.
-Sends you to 0 0 0
-Possibly gives an error saying how stupid you are

Unanswered:

-What's the best way to spawn a bot that Blockland treats like a player? Testing purposes.
--If possible, include a way to give it a client and make a new clientobject.
-Is there a way to tumble a player without actually tumbling the player? (Set aim)
-Is there a way to switch the controlobject of two players/vehicles/etc? I've tried and it crashes everyone.

-I'm also trying to make a mod that creates crosshairs over other players. Just for coolness. How would I convert a 3D position into a 2D position, and test if it would be offscreen?

-How do i detect if a key is being held down/is released/was just pressed?
-How do i detect what keys are currently being held down? If i know the above i could just set up a loop or something.
-How do i simulate a keypress?
PARTIAL: I need to know how to do this without using keybinds.

Quote
-What's the best way to spawn a bot that Blockland treats like a player? Testing purposes.
--If possible, include a way to give it a client and make a new clientobject.
What are you needing to test like this? There's likely an easier way.

Quote
-Is there a way to tumble a player without actually tumbling the player? (Set aim)
Yes, by messing with the rotation part of their transform.

Quote
-Is there a way to switch the controlobject of two players/vehicles/etc? I've tried and it crashes everyone.
Yes. Just switch their controlobjects and client/player variables and nothing should go too wrong.

Quote
-I'm also trying to make a mod that creates crosshairs over other players. Just for coolness. How would I convert a 3D position into a 2D position, and test if it would be offscreen?
This would be extremely difficult, I would recommend waiting to attempt this..

Quote
-How do i detect if a key is being held down/is released/was just pressed?
Package the keybind's function.

Quote
-How do i simulate a keypress?
You would simply need to call the function the keypress would activate.

Quote
PARTIAL: I need to know how to do this without using keybinds.
Keybinds are the only way torquescript can detect key presses.

What are you needing to test like this? There's likely an easier way.
Yes, by messing with the rotation part of their transform.
Yes. Just switch their controlobjects and client/player variables and nothing should go too wrong.
This would be extremely difficult, I would recommend waiting to attempt this..
Package the keybind's function.
You would simply need to call the function the keypress would activate.
Keybinds are the only way torquescript can detect key presses.
1: Various projectile and client-affecting mods.
2: But what's that? All i know about is setPosition/Position =.
3: You really need to explain this stuff. Client/player VARIABLE?
4: [sigh] I thought someone'd say that...
5/6/7: [longer sigh] I thought someone'd say that too.

Still unanswered:

-What's the best way to spawn a bot that Blockland treats like a player?
--If possible, a way to include a clientname+BLID would be appreciated.

-Is there a way to tumble a player without actually using the tumble function?

-How do you switch the controlObject of two clients without breaking something?