You can read and reply to posts and download all mods without registering.
We're an independent and non-profit fan-site. Find out more about us here.
function OnBeginScript() { SetOneShotTimer("flashlight", 0.5);}function OnTimer() { if (message().name == "flashlight") { // some constants local maxDist = 60; local minRadius = 3; local maxRadius = 17; local maxLight = 250; local deg2rad = PI / 180; local lightObj = GetData("flob"); local lastObjLit = GetData("lastObjLit"); // ensure flashlight object exists and ID saved if (!lightObj) { if (!Object.Named("flob")) { lightObj = Object.Create("Marker"); Object.SetName(lightObj, "flob") } else { lightObj = Object.Named("flob"); } SetData("flob", lightObj); SetData("lastObjLit", 0); lastObjLit = 0; } // get camera position/facing local pos = Camera.GetPosition(); local face = Camera.GetFacing(); local faceY = face.y * deg2rad; local faceZ = face.z * deg2rad; // find out if there's a surface within range local testPos = vector(); testPos.x = pos.x + maxDist * cos(faceY) * cos(faceZ); testPos.y = pos.y + maxDist * cos(faceY) * sin(faceZ); testPos.z = pos.z + maxDist * sin(faceY - PI); local hitPos = vector(); local hitObj = object(); local hitObjID = 0; // return values: 0 nothing, 1 terrain, 2 object, 3 mesh local rayHit = Engine.ObjRaycast(pos, testPos, hitPos, hitObj, 0, 0, lightObj, 0); if (rayHit) { // calc distance to impact local v = (hitPos - pos); local d = sqrt(v.Dot(v)); local lightRad = (maxRadius - minRadius) * (d / maxDist) + minRadius; local lightBright = maxLight * (1 - (d / maxDist)); // step back from impact by radius of the light local d2 = d - lightRad / 2; // never position light behind player if (d2 < 0) { d2 = 0; } // calc actual light position // (there's probably a better way to do this) local lightPos = vector(); lightPos.x = pos.x + d2 * cos(faceY) * cos(faceZ); lightPos.y = pos.y + d2 * cos(faceY) * sin(faceZ); lightPos.z = pos.z + d2 * sin(faceY - PI); // apply updated light params Property.SetSimple(lightObj, "SelfLit", lightBright); Property.SetSimple(lightObj, "SelfLitRad", lightRad); Object.Teleport(lightObj, lightPos, face); // facing doesn't matter // handle object lighting // (objects often need some help due to vertex lighting plus low poly counts) if (rayHit == 2) { hitObjID = hitObj.tointeger(); // check for object focus change if (hitObjID != abs(lastObjLit)) { killObjLight(lastObjLit); // don't mess with objects that already have Extra Light if (Property.Possessed(hitObjID, "ExtraLight")) { lastObjLit = -hitObjID; } else { lastObjLit = hitObjID; Property.Set(hitObjID, "ExtraLight", "Additive?", TRUE); } SetData("lastObjLit", lastObjLit); } if (lastObjLit > 0) { // fade to target brightness local curLum = Property.Get(hitObjID, "ExtraLight", "Amount (-1..1)"); // (lightBright / maxLight) / 2) is the target extra light Property.Set(hitObjID, "ExtraLight", "Amount (-1..1)", curLum + (((lightBright / maxLight) / 2) - curLum) / 3); } } else { killObjLight(lastObjLit); } } else { // light didn't reach anything Property.SetSimple(lightObj, "SelfLit", 0); killObjLight(lastObjLit); } // again! SetOneShotTimer("flashlight", 0.0333); }}// remove extra light from last lit objectfunction killObjLight(lastObjLit) { if (lastObjLit != 0) { SetData("lastObjLit", 0); if (lastObjLit > 0) { Property.Remove(lastObjLit, "ExtraLight"); } }}
It's probably a minor implementation detail but it seems to me that the light isn't very strong up close and doesn't disperse enough over a distance.
and the more important question - can AIs be made to go investigate should they spot the light?
Adding a few dark areas to the base game would be atmospheric (dark enough so you do need a torch, I mean), but if you do decide to make such a mod then please don't put make the dark areas too long, as it does get tedious.
Could you make it so your in-game character requires a hand to hold the torch, meaning that you can hold the torch even if your other hand is holding a pistol or wrench (or if the hand is empty, of course), but not if he's holding something that requires two hands? And instead of having to grab the torch from your inventory, could you activate and deactivate it by pressing a user defined key (as otherwise you might have to alter the UI to specifically allow you to place a one-handed object into either hand)?
So no running around with a torch in hand, but only stationary examination of dark spots and places.