Everything in one line [duplicate] - lua

This question already has answers here:
Lua indentation code in Lua [closed]
(6 answers)
Closed 7 years ago.
My example is the below, i found i code in internet, but its a little difuculty to understand it because are everything in one line, there a program or website to uncode it? i mean, add the spaces and lines to make it more readiable?
require("libs.Utils")require("libs.Res") require("libs.SideMessage") local adae = false local ddasf = true local ddasfcfa = false local ggsa = {} local fasca = {} local vvsa = {} local ggaw = {} local fefsg = nil local hhasf = true local gggqas = 4000 local bwe = false local bwefqa = {} print(math.floor(client.screenRatio*100)) --[[Config. --If u have some problem with positioning u can add screen ration(64 line) and create config for yourself.]] if math.floor(client.screenRatio*100) == 177 then testX = 1600 testY = 900 tpanelHeroSize = 55 tpanelHeroDown = 25.714 tpanelHeroSS = 20 txxB = 2.535 txxG = 3.485 elseif math.floor(client.screenRatio*100) == 166 then testX = 1280 testY = 768 tpanelHeroSize = 47.1 tpanelHeroDown = 25.714 tpanelHeroSS = 18 txxB = 2.59 txxG = 3.66 elseif math.floor(client.screenRatio*100) == 160 then testX = 1280 testY = 800 tpanelHeroSize = 48.5 tpanelHeroDown = 25.714 tpanelHeroSS = 20 txxB = 2.579 txxG = 3.74 elseif math.floor(client.screenRatio*100) == 133 then testX = 1024 testY = 768 tpanelHeroSize = 47 tpanelHeroDown = 25.714 tpanelHeroSS = 18 txxB = 2.78 txxG = 4.63 elseif math.floor(client.screenRatio*100) == 125 then testX = 1280 testY = 1024 tpanelHeroSize = 58 tpanelHeroDown = 25.714 tpanelHeroSS = 23 txxB = 2.747 txxG = 4.54 else testX = 1600 testY = 900 tpanelHeroSize = 55 tpanelHeroDown = 25.714

I don't know if such a program exists, but you can put it into a text editor that supports Lua syntax highlighting. Then, it's mostly a case of hitting 'enter' where the Lua triggers are (things like local and require, for instance). Lua is nice in that it allows you to put everything on one line, but I can understand how hard that can be to read so you can understand what's being done.

Related

How i can make the parts of a Model be together with primarypart and follow it

I want to make a vfx model primary part go to the Player Character Primary Part, but the parts of the vfx model isn't moving with the model primary part. I tried to weld them but didnt work. What can i do? Code below:
local replicated = game.ReplicatedStorage
local powers = replicated.Powers
local ss = game.ServerStorage
local FireWind = ss.FireWind:Clone()
powers.GiantFire.OnServerEvent:Connect(function(Player, Hit)
local char = Player.Character or Player.CharacterAdded:Wait()
local hrpp = char.PrimaryPart
local SuperFireSphere = Instance.new("Part")
SuperFireSphere.Shape = Enum.PartType.Ball
SuperFireSphere.Material = Enum.Material.Neon
SuperFireSphere.BrickColor = BrickColor.new("New Yeller")
SuperFireSphere.Anchored = true
SuperFireSphere.CanCollide = false
task.wait(.2)
hrpp.Position += Vector3.new(0, 50 , 0)
hrpp.Anchored = true
SuperFireSphere.Parent = workspace
FireWind.PrimaryPart.Position = hrpp.Position
FireWind.Parent = workspace
SuperFireSphere.Position = char.PrimaryPart.Position + Vector3.new(0,15,0)
for i = 1, 10 do
task.wait(.1)
SuperFireSphere.Size += Vector3.new(2,2,2)
end
task.wait(10)
SuperFireSphere:Destroy()
hrpp.Anchored = false
end)
You should try set the PrimaryPartCFrame using model:SetPrimaryPartCFrame(cframe)
In this case, you want it to follow the HumanoidRootPart CFrame.
local model = workspace.Model
local char = game.Players.LocalPlayer:WaitForChild('Character')
local hrp = char.HumanoidRootPart
local part = workspace.Part
model:SetPrimaryPartCFrame(hrp.CFrame) -- sets the model's primary part's CFrame to the hrp.
Local potato = 10
Local TestAmount = 11
If potato == 10 then
Script.parent.cancollide = false
End
If TestAmount == 11 then
Script.parent.transparency = false
end

How to add more than one variable

function CountCops()
local xPlayers = ESX.GetPlayers()
CopsConnected = 0
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
if xPlayer.job.name == 'police' then
CopsConnected = CopsConnected + 1
end
end
SetTimeout(120 * 1000, CountCops)
end
Does anyone know how would I have both if xPlayer.job.name == 'police' or xPlayer.job.name == 'sheriff' read for = 1 cop for each person.
So if one police was on then it = 1
and if one sheriff was on it would = 2.
local countingJobs = {
['police'] = true,
['sheriff'] = true
};
function CountCops()
local xPlayers = ESX.GetPlayers()
CopsConnected = 0
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
if countingJobs[xPlayer.job.name] then
CopsConnected = CopsConnected + 1
end
end
SetTimeout(120 * 1000, CountCops)
end

Create Object With Array Table

I try to make several panel objects on my form in Cheat Engine using CE Lua script. How do this in the correct way?.
local bricks = {}
local brickWidth = 70
local brickHeight = 25
local brickRows = 6
local brickColumns = 6
local rleft = 5
local rtop = 5
local cleft = 5
local ctop = 10
for row = 0, brickRows do
for column = 0, brickColumns do
bricks[row] = createPanel(gameMain)
bricks[row].Width = brickWidth
bricks[row].Height = brickHeight
bricks[row].Top = rtop
bricks[row].Left = rleft
bricks[row].Color = math.random(10,65255)
rleft = rleft + brickWidth + 5
bricks[column] = createPanel(gameMain)
bricks[column].Width = brickWidth
bricks[column].Height = brickHeight
bricks[column].Left = cleft
bricks[column].Top = brickHeight + 5
bricks[column].Color = math.random(10,65255)
ctop = ctop + brickHeight + 5
end
end
But it fails. What I want is for each row and column will contain 6 panels.
How to write the correct script?. Thank you
Create a table that will contain all bricks.
Create 1 table per row
Create and add 1 brick per column into each row
Simply use the loop counters to calculate the offsets.
Maybe you should solve such problems with pen and paper first.
local rows, cols = 6, 6
local width, height = 70, 25
local gap = 5
local bricks = {}
for row = 1, rows do
bricks[row] = {}
for col = 1, cols do
local x = (col - 1) * (width + gap) -- x offset
local y = (row - 1) * (height + gap) -- y offset
local newBrick = createPanel(gameMain)
-- assign brick's properties
-- ...
bricks[row][col] = newBrick
end
end

Why is this lua dijkstra's algorithm not working in some cases?

Im using Dijkstra algorythm code from this site: https://rosettacode.org/wiki/Dijkstra%27s_algorithm#Lua
Unfortunately It doesnt work for current edges table.
I have determined that the problem disappears when I delete the connection from 35 -> 36, but It doesnt solve the problem.
-- Graph definition
local edges = {
[34] = {[35] = 1,[37] = 1,},
[35] = {[34] = 1,[36] = 1,[46] = 1,},
[36] = {[35] = 1,[37] = 1,},
[37] = {[34] = 1,[36] = 1,},
[38] = {[46] = 1,},
[46] = {[35] = 1,[38] = 1,},
}
-- Fill in paths in the opposite direction to the stated edges
function complete (graph)
for node, edges in pairs(graph) do
for edge, distance in pairs(edges) do
if not graph[edge] then graph[edge] = {} end
graph[edge][node] = distance
end
end
end
-- Create path string from table of previous nodes
function follow (trail, destination)
local path, nextStep = destination, trail[destination]
while nextStep do
path = nextStep .. " " .. path
nextStep = trail[nextStep]
end
return path
end
-- Find the shortest path between the current and destination nodes
function dijkstra (graph, current, destination, directed)
if not directed then complete(graph) end
local unvisited, distanceTo, trail = {}, {}, {}
local nearest, nextNode, tentative
for node, edgeDists in pairs(graph) do
if node == current then
distanceTo[node] = 0
trail[current] = false
else
distanceTo[node] = math.huge
unvisited[node] = true
end
end
repeat
nearest = math.huge
for neighbour, pathDist in pairs(graph[current]) do
if unvisited[neighbour] then
tentative = distanceTo[current] + pathDist
if tentative < distanceTo[neighbour] then
distanceTo[neighbour] = tentative
trail[neighbour] = current
end
if tentative < nearest then
nearest = tentative
nextNode = neighbour
end
end
end
unvisited[current] = false
current = nextNode
until unvisited[destination] == false or nearest == math.huge
return distanceTo[destination], follow(trail, destination)
end
-- Main procedure
print("Directed:", dijkstra(edges, 34, 38, true))
print("Undirected:", dijkstra(edges, 34, 38, false))
I recieve the output of inf, 38 with current egdes table content but when I delete the connection between 35 -> 36 it gives an good output - 3, 34 35 46 38
For easier understand im uploading the graphic representation of edges table: https://i.imgur.com/FFF22C1.png
As you can see the route is corrent when we start from 34 -> 35 -> 46 -> 38 but as I sad It works only when connection from 35 to 36 is not existing.
Why it is not working in the case showed in my code?
This is an example of Dijkstra algorithm implementation
-- Graph definition
local edges = {
[34] = {[35] = 1,[37] = 1,},
[35] = {[34] = 1,[36] = 1,[46] = 1,},
[36] = {[35] = 1,[37] = 1,},
[37] = {[34] = 1,[36] = 1,},
[38] = {[46] = 1,},
[46] = {[35] = 1,[38] = 1,},
}
local starting_vertex, destination_vertex = 34, 38
local function create_dijkstra(starting_vertex)
local shortest_paths = {[starting_vertex] = {full_distance = 0}}
local vertex, distance, heap_size, heap = starting_vertex, 0, 0, {}
return
function (adjacent_vertex, edge_length)
if adjacent_vertex then
-- receiving the information about adjacent vertex
local new_distance = distance + edge_length
local adjacent_vertex_info = shortest_paths[adjacent_vertex]
local pos
if adjacent_vertex_info then
if new_distance < adjacent_vertex_info.full_distance then
adjacent_vertex_info.full_distance = new_distance
adjacent_vertex_info.previous_vertex = vertex
pos = adjacent_vertex_info.index
else
return
end
else
adjacent_vertex_info = {full_distance = new_distance, previous_vertex = vertex, index = 0}
shortest_paths[adjacent_vertex] = adjacent_vertex_info
heap_size = heap_size + 1
pos = heap_size
end
while pos > 1 do
local parent_pos = (pos - pos % 2) / 2
local parent = heap[parent_pos]
local parent_info = shortest_paths[parent]
if new_distance < parent_info.full_distance then
heap[pos] = parent
parent_info.index = pos
pos = parent_pos
else
break
end
end
heap[pos] = adjacent_vertex
adjacent_vertex_info.index = pos
elseif heap_size > 0 then
-- which vertex neighborhood to ask for?
vertex = heap[1]
local parent = heap[heap_size]
heap[heap_size] = nil
heap_size = heap_size - 1
if heap_size > 0 then
local pos = 1
local last_node_pos = heap_size / 2
local parent_info = shortest_paths[parent]
local parent_distance = parent_info.full_distance
while pos <= last_node_pos do
local child_pos = pos + pos
local child = heap[child_pos]
local child_info = shortest_paths[child]
local child_distance = child_info.full_distance
if child_pos < heap_size then
local child_pos2 = child_pos + 1
local child2 = heap[child_pos2]
local child2_info = shortest_paths[child2]
local child2_distance = child2_info.full_distance
if child2_distance < child_distance then
child_pos = child_pos2
child = child2
child_info = child2_info
child_distance = child2_distance
end
end
if child_distance < parent_distance then
heap[pos] = child
child_info.index = pos
pos = child_pos
else
break
end
end
heap[pos] = parent
parent_info.index = pos
end
local vertex_info = shortest_paths[vertex]
vertex_info.index = nil
distance = vertex_info.full_distance
return vertex
end
end,
shortest_paths
end
local vertex, dijkstra, shortest_paths = starting_vertex, create_dijkstra(starting_vertex)
while vertex and vertex ~= destination_vertex do
-- send information about all adjacent vertexes of "vertex"
for adjacent_vertex, edge_length in pairs(edges[vertex]) do
dijkstra(adjacent_vertex, edge_length)
end
vertex = dijkstra() -- now dijkstra is asking you about the neighborhood of another vertex
end
if vertex then
local full_distance = shortest_paths[vertex].full_distance
local path = vertex
while vertex do
vertex = shortest_paths[vertex].previous_vertex
if vertex then
path = vertex.." "..path
end
end
print(full_distance, path)
else
print"Path not found"
end

ROBLOX - Why is this fly script working only in the Studio?

I really need help..
I have this code for fly, as a backpack item:
Name = "Fly"
pi = 3.141592653589793238462643383279502884197163993751
a = 0
s = 0
ndist = 13
rs = 0.025
siz = Vector3.new(1, 1, 1)
form = 0
flow = {}
function CFC(P1,P2)
local Place0 = CFrame.new(P1.CFrame.x,P1.CFrame.y,P1.CFrame.z)
local Place1 = P2.Position
P1.Size = Vector3.new(P1.Size.x,P1.Size.y,(Place0.p - Place1).magnitude)
P1.CFrame = CFrame.new((Place0.p + Place1)/2,Place0.p)
end
function checktable(table, parentneeded)
local i
local t = {}
for i = 1, #table do
if table[i] ~= nil then
if string.lower(type(table[i])) == "userdata" then
if parentneeded == true then
if table[i].Parent ~= nil then
t[#t + 1] = table[i]
end
else
t[#t + 1] = table[i]
end
end
end
end
return t
end
if script.Parent.Name ~= Name then
User = game:service("Players").Nineza
HB = Instance.new("HopperBin")
HB.Name = Name
HB.Parent = User.StarterGear
script.Parent = HB
User.Character:BreakJoints()
end
speed = 50
script.Parent.Selected:connect(function(mar)
s = 1
torso = script.Parent.Parent.Parent.Character.Torso
LeftShoulder = torso["Left Shoulder"]
RightShoulder = torso["Right Shoulder"]
LeftHip = torso["Left Hip"]
RightHip = torso["Right Hip"]
human = script.Parent.Parent.Parent.Character.Humanoid
bv = Instance.new("BodyVelocity")
bv.maxForce = Vector3.new(0,math.huge,0)
bv.velocity = Vector3.new(0,0,0)
bv.Parent = torso
bg = Instance.new("BodyGyro")
bg.maxTorque = Vector3.new(0,0,0)
bg.Parent = torso
connection = mar.Button1Down:connect(function()
a = 1
bv.maxForce = Vector3.new(math.huge,math.huge,math.huge)
bg.maxTorque = Vector3.new(900000,900000,900000)
bg.cframe = CFrame.new(torso.Position,mar.hit.p) * CFrame.fromEulerAnglesXYZ(math.rad(-90),0,0)
bv.velocity = CFrame.new(torso.Position,mar.hit.p).lookVector * speed
moveconnect = mar.Move:connect(function()
bg.maxTorque = Vector3.new(900000,900000,900000)
bg.cframe = CFrame.new(torso.Position,mar.hit.p) * CFrame.fromEulerAnglesXYZ(math.rad(-90),0,0)
bv.velocity = CFrame.new(torso.Position,mar.hit.p).lookVector * speed
end)
upconnect = mar.Button1Up:connect(function()
a = 0
moveconnect:disconnect()
upconnect:disconnect()
bv.velocity = Vector3.new(0,0,0)
bv.maxForce = Vector3.new(0,math.huge,0)
torso.Velocity = Vector3.new(0,0,0)
bg.cframe = CFrame.new(torso.Position,torso.Position + Vector3.new(torso.CFrame.lookVector.x,0,torso.CFrame.lookVector.z))
wait(1)
end)
end)
while s == 1 do
wait(0.02)
flow = checktable(flow, true)
local i
for i = 1,#flow do
flow[i].Transparency = flow[i].Transparency + rs
if flow[i].Transparency >= 1 then flow[i]:remove() end
end
if a == 1 then
flow[#flow + 1] = Instance.new("Part")
local p = flow[#flow]
p.formFactor = form
p.Size = siz
p.Anchored = true
p.CanCollide = false
p.TopSurface = 0
p.BottomSurface = 0
if #flow - 1 > 0 then
local pr = flow[#flow - 1]
p.Position = torso.Position - torso.Velocity/ndist
CFC(p, pr)
else
p.CFrame = CFrame.new(torso.Position - torso.Velocity/ndist, torso.CFrame.lookVector)
end
p.BrickColor = BrickColor.new("Cyan")
p.Transparency = 1
p.Parent = torso
local marm = Instance.new("BlockMesh")
marm.Scale = Vector3.new(1.9, 0.9, 1.725)
marm.Parent = p
local amplitude
local frequency
amplitude = pi
desiredAngle = amplitude
RightShoulder.MaxVelocity = 0.4
LeftShoulder.MaxVelocity = 0.4
RightHip.MaxVelocity = pi/10
LeftHip.MaxVelocity = pi/10
RightShoulder.DesiredAngle = desiredAngle
LeftShoulder.DesiredAngle = -desiredAngle
RightHip.DesiredAngle = 0
LeftHip.DesiredAngle = 0
end
end
end)
script.Parent.Deselected:connect(function()
a = 0
s = 0
bv:remove()
bg:remove()
if connection ~= nil then
connection:disconnect()
end
if moveconnect ~= nil then
moveconnect:disconnect()
end
if upconnect ~= nil then
upconnect:disconnect()
end
while s == 0 do
wait()
if #flow > 0 then
flow = checktable(flow, true)
local i
for i = 1,#flow do
flow[i].Transparency = flow[i].Transparency + rs
if flow[i].Transparency >= 1 then flow[i]:remove() end
end
end
end
end)
while true do
wait()
if s == 1 then
return
end
end
script:remove()
The script is in a HopperBin Object in the game's StarterPack Folder.
Now if you try it on your own, you'll see that it will work, BUT if you publish the game, play it via ROBLOX(not the studio) and try to use the item, you won't fly.
Any ideas why?
It's been a long time since I haven't played ROBLOX, so my answer might be inaccurate.
First, you need to understand the difference between a Script and a Localscript. In a nutshell, a script runs server-side whereas a Localscript runs client-side. Your fly script is expected to run on a player's client, thus you have to use a Localscript.
Your regular script works in build-mode because scripts are run on your client, and thus are considered as Localscripts. When you publish your game and play it, your computer doesn't work as a server anymore, but as a client.
In addition to this, as you use a localscript, you may have to change the following line :
-- gets the client (local player) on which the script is running
User = Game:GetService("Players").LocalPlayer
Also, avoid relative paths such as script.Parent.Parent.Parent..... You want to get the client's torso, so just use your User variable as per : User.Character.Torso. Do the same for the character's Humanoid object.
I think it's because the time to load not existing try this at line1:
repeat wait() until game.Players.LocalPlayer.Character

Resources