Jump to content

Triggers


gordonramp
 Share

Recommended Posts

I am looking at the idea of 'triggers'( initiating an event) but have no idea where to start. I assume some sort of collision code would be necessary followed by a pointing at the event. Like, the recording of 'Health'. I can't seem to find anything much about this on the Lua Forum. Any ideas? :P

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

A trigger can be any kind of measurable thing. You could make a "trigger" so that when an entity (for example the player) is close enough to some other entity, then the entity would slowly turn towards the first entity.

 

This would be really simple to code, somehow like (in pseudocode):

If(EntityDistance(this,namedentity)<5)
PointEntity(this,namedentity,3,0.01)
End

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

You are thinking of area triggers. Is it doable in lua but in my mind currently has limitations. The body must be defined in the model you bring in, in order to for you to be able to get a collision method called. There currently is no way to get a collision method called in lua for bodies that you make in lua code. Which sucks.

Link to comment
Share on other sites

Ok, I thought I would have a go at using 'EntityDistance'. Using Lumooja's pseudocode as a base.. I placed a metal door on a terrain in the editor. Then using the basic fps Lua code, put this in the main loop..

 

If(EntityDistance(fw.main.camera,metal01_1)<5) then
PointEntity(fw.main.camera,metal01_1,3,0.01)
end

 

I gives me this error.. 'unexpected symbol near 'then''

I guess it's a simple Lua code error, any ideas why that might be?

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

Your right, it runs without an error now (C++ coder), however the object does not turn to face the camera as requested.

 

Maybe someone has a simple working example of 'trigger code' to share. :P

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

are you using this in a gamescript or an entity script? I am asking because 'metal01_1' looks like the name of the entity and not actually an entity...

 

i would put that code in an entity script for the metal01 gmf inside the object:Render() function... of course changing it from metal01_1 to object.model

 

Also it should be:

PointEntity(object.model,fw.main.camera,1, 0.01)

 

the other way is trying to point the camera at the other entity :P

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Ok, I'll explore this...

 

Update:

Success..

 

require("scripts/class")
local class=CreateClass(...)
function class:CreateObject(model) 
local object=self.super:CreateObject(model) 
function object:Update() 
if EntityDistance(fw.main.camera, self.model) < 10 then
PointEntity(self.model, fw.main.camera, 3, 0.01)
end
end
end

 

Thanks :P

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...