Tomb Raider Forums  

Go Back   Tomb Raider Forums > Tomb Raider Level Editor and Modding > Tomb Raider Level Editor > Tomb Engine

Reply
 
Thread Tools
Old 15-03-23, 18:54   #11
ShadowyXJaw724
Member
 
ShadowyXJaw724's Avatar
 
Joined: Jun 2022
Posts: 83
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.
ShadowyXJaw724 is offline   Reply With Quote
Old 15-03-23, 19:01   #12
vasatomb
Member
 
Joined: Dec 2018
Posts: 459
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
Member
 
Kubsy's Avatar
 
Joined: Nov 2019
Posts: 965
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
Kubsy is offline   Reply With Quote
Old 18-04-23, 11:35   #14
DaviDM
Member
 
DaviDM's Avatar
 
Joined: Apr 2013
Posts: 40
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
Old 09-06-23, 12:12   #15
ShadowyXJaw724
Member
 
ShadowyXJaw724's Avatar
 
Joined: Jun 2022
Posts: 83
Cool Oconic ShadowyJaw LUA Tutorial - Randomizer For SEARCH_OBJECTS

Hello! Are you have a good, great or even an amazing day? Lemme change that and make it better. I will introduce you: the first randomizer function in a TRLE!

Let's start, shall we?

Code:
function GiveItemConditions() 
if Lara:GetAnim() == 464 and Lara:GetFrame() == 180 then GiveRandomItem(1) end if Lara:GetAnim() == 465 and Lara:GetFrame() == 100 then GiveRandomItem(2) end if Lara:GetAnim() == 466 and Lara:GetFrame() == 160 then GiveRandomItem(3) end if Lara:GetAnim() == 472 and Lara:GetFrame() == 88 then GiveRandomItem(4) end
end
Alright, we start of strong! So what is going on in this function? Well, we will run it in ControlPhase, which means it will check this function every single frame.

The if statement checks if lara in is in an animation of checking a SEARCH_OBJECT, and it also checks the frame of the animation. With that, we can call the function to give our random item, yes, we give the player a random item, to play when lara is supposed to pick up the item in her animation. No, variety doesn't serve much purpose in *when* you get the item itself.

Now, when that animation is complete and the frame is at the specific point, you will see that the function GiveRandomItem() is called and a number is inserted into it. For those non-programmers, that is an argument for our function. It exists in order to allow us to control what the function really does.

Let's move on to the next part of the function.

Code:
ItemList = { 978, 979, 953, 955, 956, 958, 965, 975, 	
952, 954, 957, 964, 974
} ItemListAmount = {
1,1,20,6,6,6,20,3, 1,1,1,1,1
} ItemSearchObjectString = {
"+ 1 Big Medi in your Inventory!", "+ 1 Small Medi in your Inventory!", "+ 1 Uzi Mag in your Inventory!", "+ 6 Shotgun Shells ( Normal ) in your Inventory!", "+ 6 Shotgun Shells ( Wideshot ) in your Inventory!", "+ 6 Revolver Rounds in your Inventory!", "+ 1 HK Mag in your Inventory!", "+ 1 Harpoon Bundle in your Inventory!", "You found a pair of Uzis! Congratulations!", "You found a Shotgun! Congratulations!", "You found a Revolver! Congratulations!", "You found a HK! Congratulations!", "You found a Harpoon Gun! Congratulations!"
}
This is going to be confusing. But it's really not... avoidable. Okay, so what is ItemList - it's the list where all of our ID's for objects that we want to use as our pool for potential contestants of what you get are stored. Healing items and weapons are included in that list.

Now what you might think is... What is going on with ItemListAmount. If that's a list, then what is it for. We need the amount of an object to give to the player, and if we try to give 1 of Uzi ammo, then Lara only gets a single round. This is the best way to actually do this, as we can just replace a variable and we can modify the actual amount the player gets. 20 for Uzi and HK ammo in multiples of that is the best way to go.

ItemSearchObjectString is simple. It's what is displayed on screen to notify the player on what they found. You'll always know what you have gotten, since we cannot use the visual item circling around... Why? Because that wouldn't work. If we tried placing the item via code, you have to pick it off the ground, and it won't work if you use the SEARCH OBJECT. The reason for that is simple: when we compile the level, we HAVE to have the ammo or healing or weapon placed on the ground, otherwise it won't register in TEN that the two are connected. Hopefully that helps.

Final batch of code:

Code:
function GiveRandomItem(SEARCH_OBJECT) 
if SEARCH_OBJECT < 3 then randomItemVar = math.random(8) elseif SEARCH_OBJECT == 4 then randomItemVar = math.random(9, 13) end local ItemNotifX, ItemNotifY = PercentToScreen(25, 80) local ItemNotif = DisplayString(ItemSearchObjectString[randomItemVar], ItemNotifX, ItemNotifY, White_Color) ShowString(ItemNotif, 2) local Item = ItemList[randomItemVar] local ItemAmount = ItemListAmount[randomItemVar] GiveItem(ItemList[randomItemVar], ItemAmount)
end
Right... this is where we get serious. We first check which SEARCH_OBJECT we triggered, and that's where the argument comes in. We'd have to make that first function's if statements that way regardless because it wouldn't work properly if we tried to do it differently. Now, searching the first 3 SEARCH OBJECTS will reward you with ammo or healing items ONLY. The SEARCH_OBJECT_4 however, in this code and in this state of it, it will randomly pick a weapon out of that list we made prior. Now, you see the real deal of it. We can use most search objects to randomly sow through the items possible, and use the SEARCH_OBJECT_4 to randomly give you a weapon. Used sparingly, it adds replayability as you either are good or are met with bad luck. It's not far, but it's really interesting as a mechanic.

Now, the rest of the function is simply displaying the string and giving the item. Ignoring the string display because that's not really interesting, let's focus on the final bit of the function.

Code:
local Item = ItemList[randomItemVar]
local ItemAmount = ItemListAmount[randomItemVar]
GiveItem(ItemList[randomItemVar], ItemAmount)
Why do we make variables to use as arguments for GiveItem? Well, using ItemList[randomItemVar] would throw us an error so we do this instead. It's local in the function so it doesn't matter.

The final batch of code:

Code:
function GiveItemConditions() 

	if Lara:GetAnim() == 464 and Lara:GetFrame() == 180 then GiveRandomItem(1) end 
	if Lara:GetAnim() == 465 and Lara:GetFrame() == 100 then GiveRandomItem(2) end
	if Lara:GetAnim() == 466 and Lara:GetFrame() == 160 then GiveRandomItem(3) end 
	if Lara:GetAnim() == 472 and Lara:GetFrame() == 88 then GiveRandomItem(4) end

end

ItemList = { 978, 979, 953, 955, 956, 958, 965, 975, 	
	952, 954, 957, 964, 974
}

ItemListAmount = {
	1,1,20,6,6,6,20,3,     
	1,1,1,1,1
}

ItemSearchObjectString = {
	"+ 1 Big Medi in your Inventory!",
	"+ 1 Small Medi in your Inventory!",
	"+ 1 Uzi Mag in your Inventory!", 
	"+ 6 Shotgun Shells ( Normal ) in your Inventory!", 
	"+ 6 Shotgun Shells ( Wideshot ) in your Inventory!",
	"+ 6 Revolver Rounds in your Inventory!", 
	"+ 1 HK Mag in your Inventory!", 
	"+ 1 Harpoon Bundle in your Inventory!",
	"You found a pair of Uzis! Congratulations!",
	"You found a Shotgun! Congratulations!",
	"You found a Revolver! Congratulations!",
	"You found a HK! Congratulations!",
	"You found a Harpoon Gun! Congratulations!"
}

-- We have to use the ID numbers, and not the names themselves as if we do "Obj" for anything, it breaks and counts as a string which won't work.

function GiveRandomItem(SEARCH_OBJECT) 
	if SEARCH_OBJECT <= 3 then
		randomItemVar = math.random(8)
	elseif SEARCH_OBJECT == 4 then
		randomItemVar = math.random(9, 13)
	end
	local ItemNotifX, ItemNotifY = PercentToScreen(25, 80)
	local ItemNotif = DisplayString(ItemSearchObjectString[randomItemVar], ItemNotifX, ItemNotifY, White_Color)
	ShowString(ItemNotif, 2)
	local Item = ItemList[randomItemVar]
	local ItemAmount = ItemListAmount[randomItemVar]
	GiveItem(ItemList[randomItemVar], ItemAmount)
end

LevelFuncs.OnLoad = function() end
LevelFuncs.OnSave = function() end
LevelFuncs.OnStart = function() end
LevelFuncs.OnControlPhase = function() GiveItemConditions() end
LevelFuncs.OnEnd = function() end
I hope you enjoy this little function in TEN, and lemme know if you need any help with it! Glad to help out if you want to upgrade it for your own use.
ShadowyXJaw724 is offline   Reply With Quote
Reply

Bookmarks

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 07:38.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Tomb Raider Forums is not owned or operated by CDE Entertainment Ltd.
Lara Croft and Tomb Raider are trademarks of CDE Entertainment Ltd.