www.tombraiderforums.com  

Go Back   www.tombraiderforums.com > Tomb Raider Level Editor and Modding > Tomb Raider Level Editor > Tomb Engine

Reply
 
Thread Tools
Old 15-03-23, 18:54   #11
ShadowyXJaw724
Hobbyist
 
ShadowyXJaw724's Avatar
 
Join Date: Jun 2022
Location: Behind You
Posts: 66
Lightbulb Replicating the Wait() function from Roblox

Hello! I am here to show you how to replicate the wait() function from Roblox. It's a commonly used function in roblox as it allows for easier coding of certain things in that game engine.

What is the wait() function? Very simple.

It takes the time you put as the argument inside, and it "pauses" the code from running further. So, you can have something happen, use wait(5) { progressing five seconds }, and then something else.

Let's get started with a quick example of how you can do something similar



Quote:
LevelFuncs.OnLoad = function() end
LevelFuncs.OnSave = function() end
LevelFuncs.OnStart = function() SetFOV(105) end
LevelFuncs.OnEnd = function() end


LevelFuncs.OnControlPhase = function()



end

This is the starting base for our code. The level layout doesn't matter, neither goes the other .lua files for this tutorial.

I set the FOV to 105 for personal preference.

Here is the code you could use for this replication:

Quote:
local StartWaitReplication = false
local Wait_Variable = 0

LevelFuncs.OnLoad = function() end
LevelFuncs.OnSave = function() end
LevelFuncs.OnStart = function() SetFOV(105) end
LevelFuncs.OnEnd = function() end


LevelFuncs.OnControlPhase = function()

if StartWaitReplication then
Wait_Variable = Wait_Variable + 1
end

if StartWaitReplication then
if Wait_Variable == 150 then
Lara:SetHP(10)
end
if Wait_Variable == 300 then
Lara:Explode()
end
end

end

LevelFuncs.TriggerExample = function()

StartWaitReplication = true

end
Okay, let's explain what happens here.

The TriggerExample function makes a boolean variable become true, and thus our if statements in the control phase function can run.

When that gets triggered, it start incrementing another variable by 1 according to the 30 fps framerate. - 5 seconds would be 150 frames, so that's what we do for the first one, where we set Lara's health to 10 as an example. After another 5 seconds Lara explodes as the variable is 300.
__________________
< You must break the cycle, or the loop will repeat tommorow. >
ShadowyXJaw724 is offline   Reply With Quote
Old 15-03-23, 19:01   #12
vasatomb
Historian
 
Join Date: Dec 2018
Location: Russia
Posts: 434
Default

this is all great, but how to do without scripting, and for example with the help of the node editor to do for example: opening doors after a certain time, and then so that the fire is lit after some more time, etc. etc....

Lua may be a good language, but I don't really want to study it thoroughly. (I barely understood how to assign names to objects at the level (well, keys, etc..))

Last edited by vasatomb; 15-03-23 at 19:04.
vasatomb is offline   Reply With Quote
Old 15-03-23, 21:28   #13
Kubsy
Explorer
 
Kubsy's Avatar
 
Join Date: Nov 2019
Location: Polska
Posts: 776
Default

Quote:
Originally Posted by vasatomb View Post
this is all great, but how to do without scripting, and for example with the help of the node editor to do for example: opening doors after a certain time, and then so that the fire is lit after some more time, etc. etc....

Lua may be a good language, but I don't really want to study it thoroughly. (I barely understood how to assign names to objects at the level (well, keys, etc..))
Please don't write here as this thread is mainly for Lua tutorial stuff.

Ask questions on the general forum threads
__________________
Chronicles Lara: "Whatever"
Kubsy is offline   Reply With Quote
Old 18-04-23, 11:35   #14
DaviDM
Hobbyist
 
DaviDM's Avatar
 
Join Date: Apr 2013
Posts: 36
Default Ammo Counter 2.0

This is an update of the ammo counter

This counter displays the ammo available for the weapon being wielded. If the ammunition is infinite it displays "infinite".

This part of code can be inserted at the end, under the functions .ON
The AddCallback function will cause the values of the munitions to update automatically


Code:
--customization--
local color = Color(0, 255, 128)
local x = 1.8
local y = 6.2
local text = 'Ammo:'
----
local halfwayX, halfwayY = PercentToScreen(x, y)
local ammoMessage = DisplayString('', halfwayX, halfwayY, color, false)
LevelFuncs.__ShowAmmoCounter = function()
    if Lara:GetHandStatus() == 4 then
        if not (Lara:GetAmmoCount() == -1) then
            ammoMessage:SetKey(text .. ' ' .. Lara:GetAmmoCount())
        else
            ammoMessage:SetKey(text .. ' Infinite')
        end
        ShowString(ammoMessage)
    else
        HideString(ammoMessage)
    end
end
AddCallback(TEN.Logic.CallbackPoint.POSTCONTROLPHASE, LevelFuncs.__ShowAmmoCounter)
Customize Counter
It is possible to customize the counter:
  1. Color

    it is possible to change the 3 numbers inside the brackets that represent the color of the counter (R,G,B).
    One can use RGB color picker to select the color and copy the values (R,G,B)


  2. Position

    it is possible to change the (x,y) position of the counter.
    • Position (0,0) is the upper left corner
    • position (100,100) is the lower right corner



  3. Text

    it is possible to change the text inside the superscripts

Examples of customization (click to open image)


Last edited by DaviDM; 18-04-23 at 11:46.
DaviDM is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 09:21.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.