Scripts / Help With Scrips

Years of Service
User Offline
Joined: 17th Dec 2013
Location: Australia
Posted: 19th Jan 2014 12:42
Hi there I know 0 about scrips but I am looking

to give it a shot with what we have in the alpha

I have a light in my map and I have set the main script

to "light.lua" and the contents of said file is below

-- LUA Script - precede every function and global member with lowercase name of script + '_main'

-- Light Changes when aprochaed

function light_main(e)

lightrange = lr

PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;

PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;

PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;

PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));

if PlayerDist < 80 then

lr = 0

if PlayerDist > 80 then

lr = 8000



from what I understand with the code that I have added it should enable or disable the light based on the distance that I am from it but its not working

any one able to help?

Bring It On

GameGuru TGC Backer
Years of Service
User Offline
Joined: 20th Jan 2011
Location: Worldwide Web
Posted: 20th Jan 2014 11:19 Edited at: 20th Jan 2014 11:30

I am not sure about LUA, Not had a chance to play with it yet but it looks like you have a condition within a condition to me. This might be causing your trouble.

In your code you are saying that if PlayerDist is smaller than 80 then do something (first condtion) and then within that condition you are saying that if PlayerDist > 80 then do something (second condtion).

It could never get to the second condition unless the first condition is smaller than 80 but then it could not run the second condition because the first one is saying that PlayerDist is smaller than 80

Your Code:

This is what I think you want:

You will probably need to get rid of the First and Second condition quotes within the code if you copy and paste.

Hope this helps

I've got something to say


It's better to burn out than fade away.

Login to post a reply

Server time is: 2024-04-14 22:00:08
Your offset time is: 2024-04-14 22:00:08