Writen .lua to normal .lua [closed] - lua

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
This is in FiveM and I dont know how to write this to 'normal' lua.
This is the code:
if LumiaM.Mfunc.Button('Give Yourself A Car (Specific)', 5, trigy) then
local player_id = LumiaM.Mfunc.KeyboardInput('Players ID to Recive the Car', '', 100)
local vehicles = LumiaM.Mfunc.KeyboardInput('Vehicle Modle', '', 100)
if LumiaN.natives.IsModelValid(vehicles) and LumiaN.natives.IsModelAVehicle(vehicles) then
local plate = LumiaM.Mfunc.KeyboardInput('Vehicle Plate', '', 8)
LumiaF.func.TriggerCustomEvent(true, "vRP:MySQL_query", "vRP/add_custom_vehicle", {user_id = player_id, vehicle = vehicles, vehicle_plate = plate, veh_type = "car"}, 2)
else
print('Bad Model')
end
end
trigy = trigy + 20
end

This is in FiveM and I dont know how to write this to 'normal' lua
This code uses the FiveM API.
You cannot do this in Lua alone. There is no replacement for LumiaM.Mfunc.KeyboardInput for example.
You could replace a few things with Lua but that wouldn't actually make sense. What should be the outcome of replacing code for a game without the game?

Related

Generator with condition in F# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
if you know, how I can write generator with condition in F# - tell me please!) something like that:
let res = [for i in 1..5 if i % 2 = 0 then i]
printfn "%A" res
You were almost on the right track.
let res =
[
for i in 1..5 do
if i % 2 = 0 then
yield i
]
The feature you're looking for is list comprehensions.
This is similar to yield return in C#. The same comprehensions are available for seq and Array.

I don't understand this example in Lua [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
function maximum (a)
local mi = 1 -- maximum index
local m = a[mi] -- maximum value
for i,val in ipairs(a) do
if val > m then
mi = i
m = val
end
end
return m, mi
end
print(maximum({8,10,23,12,5}))--> 23 3
I can't understand this, would someone explain this example? It's so confusing, Programming in Lua First edition always make some hard examples.
The function takes one argument, which is a table that is stored in the variable a.
The function iterates (loops) over each value in the table a, using the ipairs function to return the index and value from the table (temporarily stored in i and val).
Inside the loop the value from the table is compared against m, and if val is larger than m then m is assigned the value of val and mi is assigned the value of i.
Then the function returns the two values m and mi.
In short what the function does, is to find the maximum values and its index in the table passed as the argument.

Generate a random string with n digits number (except 0 at begin) in Ruby [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Someone can teach me how to generate a random string with n digits number.
Ex: n=3, myString = "001" or "002" or ... "999" (except number 0 at begin)
p/s: I am using Ruby 1.8.7
n.times.map { (0..9).to_a.sample }.join
If it's for a password or something:
require 'securerandom'
random_number = SecureRandom.random_number(10**n)
formatted_number = "0#{random_number}"
Edit: If it doesn't need to be secure:
random_number = rand(10**n)
formatted_number = "0#{random_number}"

Error <name> expected near "if" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Hi this is my first lua code but I get a error pls fix it thx in advanced if you do get this working. I have a feeling its a small thing I'm missing.
class 'Autochat'
TalkTimer = Timer()
local TalkDelay = 1 -- in minutes
local active = 1
function
if active = 0 then
return
end
if active ~= "0" then
if(TalkTimer:GetSeconds() > (60 * timeDelay)) then
Chat:Broadcast("Hi the admin is offline.", Colors(0, 255, 0))
TalkTimer:Restart()
end
end
end
Autochat = Autochat()
The function is missing a name. Lua reads to the next line looking for the function's name and gets confused when it finds an if statement.
Also, the first if statement should be if active == 0 then because == is the comparison operator.

math.random function with step option? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
A custom function that will return a random number with a step option available like in the for loop.
Example:
for i=1,10,**2** do
print(i)
end
Do you mean this:
function randomWithStep(first, last, stepSize)
local maxSteps = math.floor((last-first)/step)
return first + stepSize * math.random(0, maxSteps)
end
This gives the same behavior as math.random(first, last) except that the values will be "stepSize" apart. Note that the highest random # may not be "last", depends if (last-first) is a multiple of stepSize.

Resources