15-03-23, 18:54 | #11 | ||
Member
Joined: Jun 2022
Posts: 83
|
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:
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:
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. |
||
15-03-23, 19:01 | #12 |
Member
Joined: Dec 2018
Posts: 459
|
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. |
15-03-23, 21:28 | #13 | |
Member
Joined: Nov 2019
Posts: 965
|
Quote:
Ask questions on the general forum threads |
|
18-04-23, 11:35 | #14 |
Member
Joined: Apr 2013
Posts: 40
|
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) It is possible to customize the counter:
Examples of customization (click to open image) Last edited by DaviDM; 18-04-23 at 11:46. |
09-06-23, 12:12 | #15 |
Member
Joined: Jun 2022
Posts: 83
|
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) endend 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!"} 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 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) 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 |
Bookmarks |
Thread Tools | |
|
|