Wednesday 15 January 2014

Biggest LUA Script Yet

Work

Not much time to blog (or eat it seems), but I managed to finish more of the LUA script engine so it's clean underneath, no longer crashes on repeat runs, can handle health, ammo, weapons, zones and now sounds, keys and doors. Of course plenty more scripts required, but we're making fast progress. Here is the largest of the scripts right now, which controls the whole logic of a chainlink fence gate which can be locked, unlocked, opened and closed, complete with user prompts and even it's own global variable.

-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Door Prompts 'Closed' can be opened with entity collected specified by 'USE KEY' 

-- state to ensure user must release E key before can open/close again
door_pressed = 0
 
function door_main(e)
 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 < 100 then
  if g_Entity[e]['activated'] == 0 then
   if g_Entity[e]['haskey'] == 1 then 
    Prompt("The door is locked. Press E key to unlock door");
    if g_KeyPressE == 1 then 
 g_Entity[e]['activated'] = 1;
    end
   else
    Prompt("The door is locked. Find a key to unlock door");
   end
  else
   if g_Entity[e]['activated'] == 1 then
    -- door is unlocked and closed
  Prompt("Press E to open door");
    if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and door_pressed == 0 then 
SetAnimation(0);
PlayAnimation(e);
g_Entity[e]['animating'] = 1;
g_Entity[e]['activated'] = 2;
     PlaySound0(e);
CollisionOff(e);
door_pressed = 1;
end
   else
    if g_Entity[e]['activated'] == 2 then
-- door is open
  if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and door_pressed == 0 then
   SetAnimation(1);
 PlayAnimation(e);
   g_Entity[e]['animating'] = 1;
   g_Entity[e]['activated'] = 1;
      PlaySound1(e);
      CollisionOn(e);
 door_pressed = 1;
end
end
   end
  end
 end
 if g_KeyPressE == 0 then 
  door_pressed = 0;
 end
end

I am knocking up a quick internal version now and then calling it a night. Have a meeting tomorrow to show the latest development progress and decide what the tweak work should be on Friday before a release for later that night. I have added quite a bit of stuff to this one, so I would have liked to do more testing, but I am sure you want to get your hands on this one as soon as.  

There should be enough meat on the script system for you to start playing with it when you get the alpha cascade, but I will making quick additions after the 17th in response to any key areas I have missed (there will be plenty).

Play

Went for a nice walk this afternoon. Rained half way through but I was totally covered in waterproof gear so I was in 'smug mode' as the wind and rain howled around me.  Nothing else to report, it's been all work. Going to eat now and see if an early night is possible..

3 comments:

  1. Great work again Lee,i no that snug walking in the rain feeling.

    ReplyDelete
  2. Great stuff,

    just a question - is the hide/scale limbs feature working aswell?
    and well another one, would it be possible to exploit this with lets say entitys.
    Was thinking about something on the lines of attaching a entity to a limb and detaching it.

    I was thinking todo some tests in this area, that should be a way to start a character customization system with this.

    Would appreciate some heads up on this for Lua
    -hiding limbs
    -scaling limbs
    -atatching entitys
    -dettaching entitys
    in LUA

    ReplyDelete
  3. ooh and Lee, i guess you missed this, i posted it some blogs earlier

    A System like this could be used for damage visualization
    http://www.valvesoftware.com/publications/2010/gdc2010_vlachos_l4d2wounds.pdf

    and in action
    http://www.youtube.com/watch?v=5_G79LJ_l2Y

    This is a Shader driven Solution, its implementation is no way easy but it might give some idea to the shader guy.

    Anyways great to see Reloaded grow :)

    ReplyDelete