TelePort Gun (swapping X,Y,Z coords) need help

Posted By: immolat3

TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 07:17

Basically, me and a group are working on a game for our university class this term and one of the ideas is a teleport gun where if you target certain things it lets you swap places with them. i am building this off the FPS starter kit, but im having serious issues with c_trace. What is the best way to go about this?
Posted By: Michael_Schwarz

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 08:33

the best way would be to describe what problems EXACTLY you have with c_trace...
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 16:41

basically I have no idea how it works. i tried a few different things, for instance i was going to give all the objects you can switch with a certain texture, so i kept having c_trace check the texture of objects but no matter what i did it always returned back the texture BELOW my character, no matter if i had it c_tracing from x, y, or z.
Posted By: Spectre

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 19:45

If I were making such a weapon, I'd use entities and then use WED to make the objects SKILLn (where 'n' is whatever skill number you want) 9. (also arbitrary).

Then, I'd use c_trace (as I said before, use AUM 59 for reference) to trace from the weapon to 10000 quants forward. If the ray hits an object and you.skilln == 9 (i.e. a vase you placed on the floor and set its skilln to 9), store the objects position in a variable, store the players current position in a variable, then swap them.

Sure its a little more complicated than that, and if I coded it I imagine it would take me the better part of a day (so I won't ) Sorry I can't be of more help.
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 20:03

my problem seems to be that when i use c_trace it is tracing from below my character no matter what direction i tell it. at this point i have no weapon scripts actually in the game, i took out the base ones while i worked on things and i could add them back.

sorry im a total newb at this, heh, i wasnt suppose to be the programmer on the team but ours decided to not show up and not help us, so someone had to do it =\
Posted By: Spectre

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 20:15

What model are you using for the player? If you made it yourself did you ensure its origin is not under its feet or something silly like that?

Also, post a snippet that contains your c_trace so people can better understand the issue.

Posted By: Spectre

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 20:38

Here, this may help (I took the idea from AUM 59 for you)
Code:
var TraceCoords;

on_mouse_left=TeleportGun();

function TeleportGun()
{
vec_set(TraceCoords.x, vector(10000, 0, 0)); //shoots 10000 quants
vec_rotate(TraceCoords.x, player.pan); //shoots in the direction of the player
c_trace(player.x, TraceCoords.x, ignore_me | ignore_passable | activate_shoot);
if (you.skilln==9)
{
...put teleport stuff here
}
}



Now that is the general idea, and I *think* it may work but I didn't test it because I just don't have time (and obviously there is no teleport code there )

Good luck.
Posted By: TWO

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 20:42

vec_rotate(TraceCoords.x, player.pan); shouldn't that be camera.pan or ...
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 20:54

My function looks like:

function TeleportGun()
{
c_trace(my.x,target_pos.x,ignore_me);

if(you) // An entity was hit?
{
vec_set(temp.x,my.x); // Store position of the player
vec_set(my.x,you.x); // Setting player to hitten entity
vec_set(you.x,temp.x); // Setting you to the stored player position
}
}




and then on right mouse click im calling the function. basically nothing happens with that code, and with the code you put there i keep getting empty pointer errors when i put the teleport code in and try it.

i made the model, but the origin is in the middle and its facing the right way.
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 20:56

and when i use your code i get a overun error because of skilln==9

and i did set the flags to that on the object, so im not sure why
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:06

function TeleportGun()
{
vec_set(TraceCoords.x, vector(10000, 0, 0)); //shoots 10000 quants
vec_rotate(TraceCoords.x, player.pan); //shoots in the direction of the player
c_trace(player.x, TraceCoords.x, ignore_me | ignore_passable | activate_shoot);
if (you)
{
var tempX;
var tempY;
var tempZ;

tempX = my.x;
tempY = my.y;
tempZ = my.z;

my.x = TraceCoords.x;
my.y = TraceCoords.y;
my.z = TraceCoords.z;

you.x = tempX;
you.y = tempY;
you.z = tempZ;
}
}


i tried to do the teleport in more steps thinking it might make it easier to see for myself, but this still gives me empty pointers

i switched it to camera.pan, player.pan, and my.pan all with the same results.

Also tried switching to camera.pan and making all the my.x and such to player.x

function TeleportGun()
{
vec_set(TraceCoords.x, vector(10000, 0, 0)); //shoots 10000 quants
vec_rotate(TraceCoords.x, camera.pan); //shoots in the direction of the player
c_trace(player.x, TraceCoords.x, ignore_me | ignore_passable | activate_shoot);
if (you)
{
var tempX;
var tempY;
var tempZ;

tempX = player.x;
tempY = player.y;
tempZ = player.z;

player.x = TraceCoords.x;
player.y = TraceCoords.y;
player.z = TraceCoords.z;

you.x = tempX;
you.y = tempY;
you.z = tempZ;
}
}


this gives mea different empty pointer, it says

c_trace(player.x, TraceCoords.x, ignore_me | ignore_passable | activate_shoot);

contains the empty pointer
Posted By: TWO

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:16

Maybe try setting me before c_trace:
me = player;

And maybe the player is not created yet when calling TeleportGun the first time.
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:20

Tried that, same thing, empty pointer...

var TraceCoords;

function TeleportGun()
{
me = player;
vec_set(TraceCoords.x, vector(10000, 0, 0)); //shoots 10000 quants
vec_rotate(TraceCoords.x, player.pan); //shoots in the direction of the player
c_trace(player.x, TraceCoords.x, ignore_me | ignore_passable | activate_shoot);
if (you)
{
var tempX;
var tempY;
var tempZ;

tempX = player.x;
tempY = player.y;
tempZ = player.z;

player.x = TraceCoords.x;
player.y = TraceCoords.y;
player.z = TraceCoords.z;

you.x = tempX;
you.y = tempY;
you.z = tempZ;
}
}


thats what i have, then in my input script i call TeleportGun(); obviouslly. That function is inside the actual player script, built off of the PlBiped01.wdl that comes with gamestudio a7.

vec_rotate(TraceCoords.x, player.pan);

^ that is the line causing problems at the moment.


btw, thanks so much for helping me. i appreciate it.
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:21

if(Key_Pressed(plBipedInput01_red_skill2_scancode))
{
TeleportGun();
}


incase you were wondering, but this should work fine.
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:25

im thinking it might be because

TraceCoords.x

is empty when the vec_rotate is used, but i am not sure about a lot of what you are all helping me with.
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:30

btw, i'll send whoever helps me get this working some monies through paypal, haha. not even joking, i cant even take this workload anymore, i know this is prolly easy cake for you guys, but im a web designer trying to program a video game, lol.
Posted By: Spectre

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:30

Templates, eh? Don't know anything about templates. Try changing player.x and player.pan to plBiped01_entity.x and plBiped01_entity.pan

I doubt that will work but still. And to answer a previous poster on why I used PLAYER instead of CAMERA...the OP said his game was a 3rd person game (in a different thread), and thus shooting from the camera would be odd so thats why I changed it. Hell, I could still be wrong though
Posted By: TWO

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:31

First, try that: var TraceCoords[3]; I use Lite-C so I actually don't remember how C-Script handles vectors.

Then, maybe the templates don't use "player"? Try to search in the template script s for "plBipedPlayer" or sth like that.
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:35

Well, aren't I using Lite-C at the moment? I mean, in SED the icon Says Lite-C lol.

and yea, sorry it is a third person game.

=\
Posted By: TWO

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:37

Then: VECTOR TraceCoords;

And you the return type for the function declaration, so if the function returns nothing, use void: void TeleportGun() {...} But that's only a design tip
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:38

var TraceCoords[3];

function TeleportGun()
{
me = player;
vec_set(TraceCoords.x, vector(10000, 0, 0)); //shoots 10000 quants
vec_rotate(TraceCoords.x, plBiped01_entity.pan); //shoots in the direction of the player
c_trace(plBiped01_entity.x, TraceCoords.x, ignore_me | ignore_passable | activate_shoot);
if (you)
{
var tempX;
var tempY;
var tempZ;

tempX = plBiped01_entity.x;
tempY = plBiped01_entity.y;
tempZ = plBiped01_entity.z;

plBiped01_entity.x = TraceCoords.x;
plBiped01_entity.y = TraceCoords.y;
plBiped01_entity.z = TraceCoords.z;

you.x = tempX;
you.y = tempY;
you.z = tempZ;
}
}


actually kind of works..well, it doesnt give me empty pointer errors, but also it doesnt teleport me at all, heh.
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:45

tried to test it with

plBiped01_entity.x = 100;
plBiped01_entity.y = 100;
plBiped01_entity.z = 100;

instead of any swapping, and it never moves me. soooo im assuming something is either wrong with if(you) or something else =x
Posted By: TWO

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:47

It's me = plBiped01_entity;
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:49

heh, had already done that before you said =p

still does nothing
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 21:56

so i thought id test something, so i made a room with 4 different textures

c_trace(plBiped01_entity.x,target_pos.x,IGNORE_ME + SCAN_TEXTURE + USE_BOX);
if(tex_name) // An entity was hit?
{
draw_text(tex_name,200,30,vector(100,100,255));
}

no matter what it shows up as the one under me. and as i said earlier the origin is in the middle of my character so that makes no sense heh
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 22:01

im pretty sure its just firing the trace the wrong way, is there a way to visualize the "laser" it shoots?
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 22:05

Also, i can fake a teleport by just removing an entity if its hit and making a new one, i can already do both of those things the problem is just getting the x y z of any entity. sigh.
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 22:10

ok so update, i put that in a while loop so it would stay up, and now it actually switches depending on what texture im looking at, and shows .mdl's if i target them, as well.

the problem is, its not based off my pan at all, its just based off of directly in front of the character.
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 22:14

i guess what im saying is, is it possible to give all the objects i want a certain texture, then if i hit that texture it gets that things x,y,z and stores it somewhere>?
Posted By: Nems

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 22:58

Yeah its possible but why not trace for the ent name instead of textures, might help a little as then you can controll the over use of textures.
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 23:03

Im pretty stuck, how hard would it be to trace for the ent_name? Like, could you show me code for say, just tracing to the model and then if it hits the model just using draw_text to say "worked" or something. my biggest issue is getting the trace to work correctly i think, if i can just get it to actually trace to the objects i need to be able to teleport with, im sure i can figure out the teleport part myself.
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 23:46

kind of big breakthrough here

function TeleportGun()
{
var theTarget;
c_trace(my.x, theTarget.x, ignore_me + scan_texture);
draw_text(tex_name,200,30,vector(100,100,255));
if(str_cmpi(tex_name, "SQUARE.MDL") == 1)
{
my.x = 100;
my.y = 100;
my.z = 100;
}
}


when i shoot the square model i have it teleports me to 100,100,100

HOWEVER, it only works if i shoot a certain side of object, i have no idea why.
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/12/07 23:55

I know this is jsut me talking to myself, but it may end up helping someone later on. I have it now so it teleports me to the object i shoot if its the right model.

function TeleportGun()
{
var theTarget;

vec_set(theTarget.x, vector(10000, 0, 0)); //shoots 10000 quants
vec_rotate(theTarget.x, my.pan); //shoots in the direction of the player
c_trace(my.x, theTarget.x, ignore_me + scan_texture); // Does the c_trace to the object

draw_text(tex_name,200,30,vector(100,100,255));

if(str_cmpi(tex_name, "SQUARE.MDL") == 1)
{
var tempX;
var tempY;
var tempZ;

tempX = your.x;
tempY = your.y;
tempZ = your.z;

my.x = tempX;
my.y = tempY;
my.z = tempZ;
}
}


however, theres still some aiming problems. it doesnt always aim right where it should, im not sure the camera pan thing is working like i thought it should.
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/13/07 00:23

works slightly better when i use the "use_box" method.

still not getting it all the time. any ideas anyone?
Posted By: immolat3

Re: TelePort Gun (swapping X,Y,Z coords) need help - 11/13/07 01:28

i finished! woooooooooooooooooooooooooooooo!

// Welcome to the most pain in the ass function ever!
// woooooooooooooooooooooooooooooooooo
// sankey86@gmail.com
function TeleportGun()
{
var theTarget;

vec_set(theTarget.x, vector(10000, 0, 0)); //shoots 10000 quants
vec_rotate(theTarget.x, camera.pan); //shoots in the direction of the player
c_trace(my.x, theTarget.x, ignore_me + scan_texture | ignore_passable | use_aabb ); // aabb works great here

if(str_cmpi(tex_name, "SQUARE.MDL") == 1) // if the entity hit is square.mdl
{
var tempX;
var tempY;
var tempZ;

tempX = your.x;
tempY = your.y;
tempZ = your.z;

ent_create("square.mdl", my.x, null); // Create entity at player old position

my.x = tempX; //
my.y = tempY; // Move player to old entity position
my.z = tempZ; //

if (your) // if the entity hit still exists...poof
{
ent_remove(your);
}

}
}


anyone can use that if they want, works like a charm!
© 2024 lite-C Forums