Wednesday, 19 October 2011

Evolution of the code #5

Doors, lockers, generators
First of all, sorry for not updating during the weekend and hope i dont lose the few followers i have but as previously stated this is a hobby project which took a year so far, so bear with me.

This week I attempted to add a bit of new code / lua into the game by creating status objects (objects that need to be somehow enabled - similar to locked doors, lockers or broken generators) and keys / keycards (or general objects that are needed).

Since I'm always going for generalization, all of these are derived from one new base class named StatusObject (which stores a new boolean used to decide if the object is enabled, and a string of the object key type which is unlocked by). I have also added two new functions to c# and exposed them to lua where the mapper has access to any property of that object.This makes mapping and luascripting loads easier so I will pat myself on the back for now since I'm the only one using it :D

Lets take for example the situation below. I have a console (or generator), but it is deactivated and nothing will happen when the user clicks on it.

In another chest is a red keycard. When the player equips it and clicks on again the generator/console is enabled and can be used to toggle a light with a bit of lua code.
function OnInit(instance)

function use(prejudicial)
    if IsDisabled() == false then
        local light = GetEntityByName("Light_1");
        local isOn = GetProperty(light,"AllowDynamicLighting");
        if isOn then isOn = false else isOn = true end
        SetProperty( light, "AllowDynamicLighting", isOn );

The same will be applied for all of these objects, but currently the repair or lockpick skills remain to be added.

No comments:

Post a Comment