flashlight from aum 18...

Posted By: Blink

flashlight from aum 18... - 12/26/06 18:28

my problem, is... when i put the action in my models, they dont do what they are supposed to do, and i cant use the flashlight at all. there are no errors at all with the code, but for some reason its not working. can anyone help?


code:

var max_dist = 10000; // use it for distances smaller than 10,000 quants
var energy = 100; // the energy for the batteries that come with the flashlight
var battery = 200; // the energy for the batteries that can be picked up

action battery_pickup
{
my.passable = on;
while (player == null) {wait (1);}
while (vec_dist (player.x, my.x) > 100) {wait (1);}
energy += battery;
ent_remove (me);
}

action flashlight_pickup
{
while (player == null) {wait (1);}
my.passable = on;
while (vec_dist (player.x, my.x) > 100) {wait (1);}
my.invisible = on;
my.lightred = 250;
my.lightgreen = 250;
my.lightblue = 170;
while (1)
{
while (energy > 0 && key_f == 1) // press the "F" key to use the flashlight
{
my.lightrange = 200;
temp.x = max_dist * cos(player.pan) * cos(camera.tilt) + player.x;
temp.y = max_dist * sin(player.pan) * cos(camera.tilt) + player.y;
temp.z = max_dist * sin(camera.tilt) + player.z;
trace_mode = ignore_models + use_box;
my.skill1 = trace (player.x, temp);
if (my.skill1 != 0)
{
temp.x = (my.skill1 - 30) * cos(player.pan) * cos(camera.tilt) + player.x;
temp.y = (my.skill1 - 30) * sin(player.pan) * cos(camera.tilt) + player.y;
temp.z = (my.skill1 - 30) * sin(camera.tilt) + player.z;
vec_set (my.pos, temp);
}
energy -= 0.5 * time;
wait (1);
}
my.lightrange = 0;
wait (1);
}
}
Posted By: George

Re: flashlight from aum 18... - 12/27/06 19:59

Make sure that your player is named "player". Place this line of code at the beginning of your player action:

action my_player
{
player = my;
// the rest of your playercode would go here
............
}
Posted By: Blink

Re: flashlight from aum 18... - 12/31/06 17:45

can i use this code with the templates? thats what i am doing now. my player has playerbiped01 action.
Posted By: George

Re: flashlight from aum 18... - 01/02/07 10:33

Sure, just place that line at the beginning of player's action.
Posted By: aztec

Re: flashlight from aum 18... - 01/02/07 12:28

Is there an update for the flashlight because it doesnt work quite well on my
a6 extra is there another way to solve that problem?
Regards
Aztec
Posted By: George

Re: flashlight from aum 18... - 01/03/07 20:09

What doesn't work well?
Posted By: aztec

Re: flashlight from aum 18... - 01/04/07 08:08

Well I tried that code and at first there where no problems but there was no light when I pressed the f buton then I tried to rescript it
that I dont need all this pick-up stuff.

I just wanted that if I press F the light appears and if I press again it dissapears

but I didnt got it
Regards
Aztec
Posted By: molotov

Re: flashlight from aum 18... - 01/04/07 08:35

Hey aztec, I also didn't want to use the pick up stuf, and also that press a button it appears and press it again it disappears. And sofar it's working for me, this is the code after I changed it:

/////////////////////////////////////////////////////////////////////////////////////////
define flash_light skill96;
var max_dist = 700; // use it for distances smaller than 10,000 quants

function flash()
{
var temp2;
while (player == null) {wait (1);}
my.passable = on;
my.invisible = on;
my.lightred = 250;
my.lightgreen = 250;
my.lightblue = 170;
while(player.flash_light == on)
{
my.lightrange = 100;
temp.x = max_dist * cos(player.pan) * cos(player.tilt) + player.x;
temp.y = max_dist * sin(player.pan) * cos(player.tilt) + player.y;
temp.z = max_dist * sin(player.tilt) + player.z;
trace_mode = ignore_models + use_box;
vec_for_vertex(temp2,player,711);
my.skill1 = trace (temp2, temp);
if (my.skill1 != 0)
{
temp.x = (my.skill1 - 30) * cos(player.pan) * cos(player.tilt) + player.x;
temp.y = (my.skill1 - 30) * sin(player.pan) * cos(player.tilt) + player.y;
temp.z = (my.skill1 - 30) * sin(player.tilt) + player.z;
vec_set (my.pos, temp);
}
wait(1);
}
my.lightrange = 0;
ent_remove(me);
}

function flashlight()
{
IF (player.flash_light == on)
{
player.flash_light = off;
return;
}
ELSE
{
player.flash_light = on;
ent_create("flash.mdl",player.x,flash);
return;
}
}

on_l = flashlight;

Hope this works for you.
Posted By: aztec

Re: flashlight from aum 18... - 01/04/07 14:33

doesnt work so good
nothing happen if I press the L button
Aztec
Posted By: molotov

Re: flashlight from aum 18... - 01/04/07 15:37

That's really strange because I got working nicely.
Posted By: George

Re: flashlight from aum 18... - 01/04/07 15:40

Maybe you didn't add the "player = my;" line of code to your player script. As an alternative, you can comment the "while (player == null) {wait (1);}" line of code from Molotov's script.
Posted By: aztec

Re: flashlight from aum 18... - 01/05/07 08:02

okay I thought of that too now IŽll try
Regards
Aztec
Posted By: Blink

Re: flashlight from aum 18... - 01/13/07 01:36

question Molotov...i used your script and i get an error when i am on the level. when i press l, it says: Empty pointer in flashlight: (player.flash_light==on). am i missing something?
Posted By: molotov

Re: flashlight from aum 18... - 01/13/07 08:50

You did put the following lines in your script;
"define flash_light skill96;"
and have this "player = me;" in your player code.
and do still have this line in the beginning of the flashlight code,
"while (player == null) {wait (1);}"
Posted By: Blink

Re: flashlight from aum 18... - 01/13/07 15:51

the code i am using is the plbiped01 code. i added the "player = my;" in the line of code. but i still get errors when i press L to turn on the light. i used the code exactly as you wrote it, with the "while (player == null);. should it say "player = me;?
Posted By: molotov

Re: flashlight from aum 18... - 01/14/07 11:47

Hey Blink, changing player == my in to player == me, doesn't really change anything. When I'll have some time I will try to see if I can get plbiped01 to work with my flashlight code. In the mean time maybe placing a proc_late inside the flash function would work.
Posted By: Blink

Re: flashlight from aum 18... - 01/14/07 14:38

thanks, i discovered no change when i changed me and my,lol. where do i put proc_late?
Posted By: Blink

Re: flashlight from aum 18... - 01/14/07 14:54

here is the flash function:


function flash()
{
var temp2;
while (player == null) {wait (1);}
my.passable = on;
my.invisible = on;
my.lightred = 250;
my.lightgreen = 250;
my.lightblue = 170;
while(player.flash_light == on)
{
my.lightrange = 100;
temp.x = max_dist * cos(player.pan) * cos(player.tilt) + player.x;
temp.y = max_dist * sin(player.pan) * cos(player.tilt) + player.y;
temp.z = max_dist * sin(player.tilt) + player.z;
trace_mode = ignore_models + use_box;
vec_for_vertex(temp2,player,711);
my.skill1 = trace (temp2, temp);
if (my.skill1 != 0)
{
temp.x = (my.skill1 - 30) * cos(player.pan) * cos(player.tilt) + player.x;
temp.y = (my.skill1 - 30) * sin(player.pan) * cos(player.tilt) + player.y;
temp.z = (my.skill1 - 30) * sin(player.tilt) + player.z;
vec_set (my.pos, temp);
}
wait(1);
}
my.lightrange = 0;
ent_remove(me);
}
{
proc_late(); // not sure if this is right lol
...
}
Posted By: molotov

Re: flashlight from aum 18... - 01/14/07 17:47

No, proc_late should be about here;
function flash()
{
var temp2;
proc_late;
while (player == null) {wait (1);}
........

But don't know if it works.
Anyway do you also have placed "define flash_light skill96;" at the top of the script?
Posted By: Blink

Re: flashlight from aum 18... - 01/14/07 21:59

it didnt work, still the same error. i am not sure whats causing the issue. have any other ideas?
Posted By: tindust

Re: flashlight from aum 18... - 01/14/07 23:05

Well, I see several things that may prevent the light from showing up. First, if you use proc_late it should go to the beginning of the function just like molotov says. Don't think you would need it though. Another thing, I don't see were you tell the my pointer what it is. You may have to specify that either by adding me = player in the beginning of the function, or by adding it in the function call:




EDIT: paragraph deleted, did not apply to question





Also, if you are using the code from your first post, the flashlight will run out of power real fast, perhaps even before you see it. Temporarily turn off the power decrease line:

// power -= time*0.5;

Finally, increase the range to at least 1000. Depending on how big your level is, the light might not reach anything to illuminate. These are just some thoughts, hope they help,

cheers,
tindust
Posted By: Blink

Re: flashlight from aum 18... - 01/14/07 23:27

Thanks tindust, but i think i am really confused now. i am using plbiped01, how do i modify that? not too sure how to add to the functions in that script. i did change the range in the flashlight script though.
Posted By: tindust

Re: flashlight from aum 18... - 01/15/07 03:54

I'm sorry. Didn't want to confuse it more. Took a look at the flash light code. Forget about what I said regarding the my pointer. It applies to a different type of flash light script. Also, don't worry about "player = me" here since the player entity is called "plBiped01_entity". In fact I don't think you should have to change the plBiped script.

I think in order to get it to work you need to:

1/ change player to plBiped01_entity everywhere in the flash light script
(alternatively add the line "player = plBiped01_entity" as first line)

2/ change "energy -= 0.5 * time;" to "//energy -= 0.5 * time;"
(keeps flashlight charged at max, just for testing purpose)

3/ make sure you have a flashlight model somewhere in your level, as described
in aum 18. It could be just a ball model or something.

4/ make sure the action flashlight_pickup is attached to that model
(through entity properties in the World Editor)

5/ not sure how you have added the flashlight script to your project, but it
needs to be included somewhere, in a separate wdl file I suppose

hope this works now,
Posted By: Blink

Re: flashlight from aum 18... - 01/15/07 12:49

can i make the same changes for the other script? i dont want to use the flashlight pickup and battery pickup. i just want to hit a button for the light to toggle on and off.
Posted By: Blink

Re: flashlight from aum 18... - 01/15/07 12:50

see the code again:

/////////////////////////////////////////////////////////////////////////////////////////
define flash_light skill96;
var max_dist = 700; // use it for distances smaller than 10,000 quants

function flash()
{
var temp2;
while (player == null) {wait (1);}
my.passable = on;
my.invisible = on;
my.lightred = 250;
my.lightgreen = 250;
my.lightblue = 170;
while(player.flash_light == on)
{
my.lightrange = 100;
temp.x = max_dist * cos(player.pan) * cos(player.tilt) + player.x;
temp.y = max_dist * sin(player.pan) * cos(player.tilt) + player.y;
temp.z = max_dist * sin(player.tilt) + player.z;
trace_mode = ignore_models + use_box;
vec_for_vertex(temp2,player,711);
my.skill1 = trace (temp2, temp);
if (my.skill1 != 0)
{
temp.x = (my.skill1 - 30) * cos(player.pan) * cos(player.tilt) + player.x;
temp.y = (my.skill1 - 30) * sin(player.pan) * cos(player.tilt) + player.y;
temp.z = (my.skill1 - 30) * sin(player.tilt) + player.z;
vec_set (my.pos, temp);
}
wait(1);
}
my.lightrange = 0;
ent_remove(me);
}

function flashlight()
{
IF (player.flash_light == on)
{
player.flash_light = off;
return;
}
ELSE
{
player.flash_light = on;
ent_create("flash.mdl",player.x,flash);
return;
}
}

on_l = flashlight;
Posted By: tindust

Re: flashlight from aum 18... - 01/15/07 14:18

I think the code looks OK, except that "function flash()" should be "action flash".

Still any errors?
Posted By: Blink

Re: flashlight from aum 18... - 01/15/07 15:50

ok... same error. let me ask, this is going to sound stupid. but could the problem be that since the flashlight script says player, should the player script say player as well everywhere in the script, and not plbiped01?
Posted By: Blink

Re: flashlight from aum 18... - 01/15/07 16:47

nevermind..tried it, didnt work at all, too many errors.
Posted By: tindust

Re: flashlight from aum 18... - 01/15/07 16:55

Well, technically yes, but the template files are heavily interconnected. It's probably better to not change their code much if possible. It's better to adapt added scripts to the definitions used in the templates. One reason I'm not using templates much.

Have you tried to debug by using a breakpoint? I see one place where the flash action probably gets stuck:

function flash()
{
var temp2;
while (player == null) {wait (1);}
my.passable = on;

Try using:

function flash()
{
var temp2;
while (player == null) {player = plBiped_entity; wait (1);}
my.passable = on;
Posted By: molotov

Re: flashlight from aum 18... - 01/15/07 18:26

Hey Blink, here is a small demo from me, which include my inventory system(press i) and the flashlight(press L). Try to see if the flashlight works in this demo on your computer, it did work on mine. This way you can see if it is a script related problem or a computer related program. Let me know if it works or not.
http://rapidshare.com/files/11848793/inventar_and_flashlight.rar.html
Posted By: Blink

Re: flashlight from aum 18... - 01/17/07 02:14

it's script related, the flashlight and inventory worked perfectly. great job on the inventory by the way. so what do i do now? how can i get your script to work. i tried including it in my main, but i came up with errors. i guess i did something wrong again since i know your script works.
Posted By: molotov

Re: flashlight from aum 18... - 01/17/07 08:26

The problem can be about two things, or the template your using is giving problems, or you'r placing the functions and includes in the wrong way. Solving the template isn't easy, I recomment creating your own script. Anyway where do you have placed the include<flashlight.wdl>;, is it in the first lines of the first script? You could also place the include below the action with "player = me" in it. If this doesn't work, the problem is in the templates.
Posted By: Blink

Re: flashlight from aum 18... - 01/17/07 14:11

i placed it in my level script. its with the other includes. should i include it in my plbiped01 script?
Posted By: Blink

Re: flashlight from aum 18... - 01/17/07 14:35

i will be totally honest, i have no clue what to do next. i really need this flashlight script.thank you for all of your help. by the way, how did you get it to work without using a model?
Posted By: molotov

Re: flashlight from aum 18... - 01/17/07 15:17

I do use a model, look a this piece of code;

function flashlight()
{
IF (player.flash_light == on)
{
player.flash_light = off;
return;
}
ELSE
{
player.flash_light = on;
ent_create("flash.mdl",player.x,flash); //here I use a model, called flash.mdl
return;
}
}

on_l = flashlight; //this calls the flashlight function.

The flashlight function creates the flash.mdl and adds the flash function to it;

Maybe you could make a small demo of your project and send it to me, so I could see your code, maybe I can find out what the problem is.
Posted By: tindust

Re: flashlight from aum 18... - 01/17/07 16:39

You have not considered using a dynamic light as flashlight?
Posted By: molotov

Re: flashlight from aum 18... - 01/17/07 18:27

Hey Tindust what you mean by dynamic light, I thought that every light you scripted was a dynamic light.
Posted By: Blink

Re: flashlight from aum 18... - 01/17/07 19:58

let me ask? since the code works for your flash.mdl, how can i use it with my plbiped? can i add the script as an include with the model i am using? i am not sure how to compress files to send the demo to you, molotov. is there an alternative?
Posted By: Blink

Re: flashlight from aum 18... - 01/17/07 20:00

wait..that was a dumb question, you cant include that kind of script like that, in plbiped duh. sorry for the noob thought.
Posted By: tindust

Re: flashlight from aum 18... - 01/17/07 22:39

Yes, of course molotov, I was a bit unclear. What I meant was using a spotlight type dynamic light that is carried by the player. When turned on it sends a narrow cone of light from the player to wherever you aim it. It would work just like a real flashlight shining on everything within its range.

You could pick it up like before and aim it as before. Just thought I'd mention this alternative to the light wev'e been talking about here.

cheers
Posted By: Blink

Re: flashlight from aum 18... - 01/18/07 01:31

tindust, do you have a biped model using your code? my model is a basic plbiped model, using a template script. can you show me an example of your script you use for your model that uses the flashlight script?
Posted By: tindust

Re: flashlight from aum 18... - 01/18/07 12:38

Sure, here's a code for a flashlight action. Just move closer to the flashlight
entity with your player ent to get the flashlight "attached". When it is, it
becomes invisible and the flashlight comes on whenever you press the f key. The
light will turn with the player.
Code:

/****************************************************************************************
2007-01-17

Dynamic Flashlight and Torch: type dynamic spotlight
becomes "attached" to player as the player gets closer than 100 from the model that has
the flashlight action attached to it, in example below it is plBiped01_entity.

Make it work by placing a flashlight model (any model) in your level, attach
the action "flashlight" to it and change the player (plBiped01_entity) to
whatever your player entity name is, and yes include this wdl in your include
list at the end.

This kind of lighting on block geometry looks "blocky". It's a property of
dynamic lighting, looks great on models though.

cheers
tindust
****************************************************************************************/

var energy = 100;

action flashlight
{
// d3d settings optional;
d3d_lightres = off; // quality of dynamic light setting. set to "on" can give better result sometimes
//d3d_spotlightcone[0] = 30; // optional settings, look up in manual. Applies to all spotlights in level
//d3d_spotlightcone[1] = 15;
//d3d_spotlightcone[2] = 1;
//
while (plBiped01_entity == null) {wait (1);}
my.passable = on;
while (vec_dist (plBiped01_entity.x, my.x) > 100) {wait (1);}
my.invisible = on;
my.lightrange = 0;
my.spotlight = on; // off for using as Torch
my.lightred = 250;
my.lightgreen = 250;
my.lightblue = 170;
while(1)
{
vec_set(my.x,plBiped01_entity.x);
vec_set(my.pan,plBiped01_entity.pan);
while (energy > 0 && key_f == 1) // press the "F" key to use the flashlight
{
my.lightrange = 1000;
vec_set(my.x,plBiped01_entity.x);
vec_set(my.pan,plBiped01_entity.pan);
my.tilt += 5; // degree upward tilt of flashlight, value depends on using third or first person view
//energy -= 0.5 * time;
wait (1);
}
my.lightrange = 0;
wait (1);
}
}


Posted By: molotov

Re: flashlight from aum 18... - 01/18/07 13:24

Hey Tindust, isn't using a spotlight in such way, causing a lower framerate.

Hey Blink, you can use winzip or winrar for compressing a small demo, and then use;
http://rapidshare.com/
for releasing it for download.
Posted By: tindust

Re: flashlight from aum 18... - 01/18/07 14:30

In general that's true, but it's only important when using many dynamic lights
to lighten a large and complex level with lots of surfaces. In small fps levels
in dark environment it's not a problem in reality. The flashlights here have
too short range to significantlt slow down the fps.

I tried the action above in a large room level with a bunch of models spread
out. The level was a quick template build with the WED Project Manager used to
add plBiped01 and camera3rd01, and whatever additional wdls the Project Manager
added. The action was put into its own wdl.

The fps was set to 64 and didn't change whether the spotlight, pointlight or no
light was on.

By the way if setting "my.spotlight..." to "//my.spotlight..." above, the
action can be used as a Torch action by the player, lighting up the surroundings
up to the range set to the light model.
Posted By: molotov

Re: flashlight from aum 18... - 01/18/07 15:25

Hey Tindust, I tryed it out, but it's not working right, because it doesn't light up blocks, only models.
Posted By: Blink

Re: flashlight from aum 18... - 01/18/07 17:14

so, i cant use it? the levels i want to use it on have prefabs. do i have to replace them all with map entities?
Posted By: tindust

Re: flashlight from aum 18... - 01/18/07 17:32

Hmm. That's odd. I have no problems like that. The lighting works fine on blocks and prefabs here. They need to be textured though, but you probably have that alredy. What are your graphic cards? Perhaps that will shed some light (heh) on our problem. I'm using a nVidia Quadro FX.
Posted By: Det

Re: flashlight from aum 18... - 01/18/07 19:30

Where`s your problem with this code ? The works good and has no Errors.

When you picked up the Flshlight you must pusch tef "F" Button then the

Flashlight in burning That`s all.
Posted By: Blink

Re: flashlight from aum 18... - 01/19/07 14:34

i will try this code when i get home. so let me understand...instead of:
while (plBiped01_entity == null) {wait (1);}
it should say:
while (player == null) {wait (1);},
although my model is using plbiped01 template script?

yes, my model is named "player" by the way. or should it say:
while (player.mdl == null) {wait (1);}
Posted By: tindust

Re: flashlight from aum 18... - 01/19/07 15:40

If you open the template wdl plBiped01 you will see that it uses the name plBiped01_entity, that's what is assigned to the model to which you attach the action irrespective of what name the model file has. Use the code as shown.

cheers
Posted By: Blink

Re: flashlight from aum 18... - 01/20/07 01:24

WOW Tindust!!!! what a great code, it works perfectly!!!! exactly what i need! i really appreciate it, if i can do anything in return, i will!!!!
Posted By: tindust

Re: flashlight from aum 18... - 01/20/07 04:45

glad to help

btw
the code
//energy -= 0.5 * time;
should be
//energy -= 0.5 * time_step;
to be up to date with most recent 3dgs
... hard to break old habits
Posted By: Blink

Re: flashlight from aum 18... - 01/21/07 06:40

do i have to change it? the script works perfectly with my project.
Posted By: tindust

Re: flashlight from aum 18... - 01/21/07 09:43

Not at this point in time, but eventually the "time" func will no longer be supported in futute 3dgs versions. In general, it's alway good to keep code up to date. "time_step" is essentially the same.
Posted By: Blink

Re: flashlight from aum 18... - 01/22/07 18:05

Thanks, I will make the change when i get home.
© 2023 lite-C Forums