Formating lua code - any tool? - lua

Hi so i recently decoded some game scripts written in lua. But it looks like this
My code looks like this
PlayerTable = { JOGO = 0, BALANCE = 0, BALANCE_P = 0, PROFIT = 0, XXX = 0, XXX_Count = 0, XXX_Player = 0, AH, AL, NUM, LOSETOP = { Times = 0, Money = 0, Name }, WINTOP = { Times = 0, Money = 0, Name } } end if PlayerTable.JOGO == Games.NULL then if 0 < PlayerTable.BALANCE then if table.contains(words.H, Message) then PlayerTable.JOGO = Games.HIGH if HL_ENABLED then Last_Payout = os.time() MinOption = BetOption[PlayerTable.JOGO].Min MaxOption = BetOption[PlayerTable.JOGO].Max PayoutOption = BetOption[PlayerTable.JOGO].Payout else if not table.contains(LimitSay.DISABLED, name) then Self.Say(Disabled_G[PlayerTable.JOGO]) table.insert(LimitSay.DISABLED, name) end PlayerTable.JOGO = Games.NULL end elseif table.contains(words.L, Message) then PlayerTable.JOGO = Games.LOW if HL_ENABLED then
I know there are HTML, JS etc. beautifiers so Is there any tool i can use to beautify this code ?
Or do i need to do it manually ? Its almost 2000 lines of code so i would rather not to do this manually.

You could use ZeroBrane. Basically select the code and then Edit-> Source -> Correct Indentation

Related

ImageLabel doesn't display in BillboardGUI

So, this is my problem.
This script works with one image id, but not any others.
I literally have no idea why this is happening.
This is the script >>
function newEntity(imgId, eName)
EntityBase = Instance.new("Part", workspace)
EntityBase.Transparency = 1
EntityBase.Size = Vector3.new(0.9, 0.1, 0.7)
EntityBase.Name = eName
EntityBillboardGui = Instance.new("BillboardGui", EntityBase)
EntityBillboardGui.StudsOffset = Vector3.new(0, 5, 0)
EntityBillboardGui.Size = UDim2.new(0,250,0,250)
EntityBillboardGui.MaxDistance = math.huge
EntityBillboardGui.Adornee = EntityBase
EntityImage = Instance.new("ImageLabel",EntityBillboardGui)
EntityImage.Size = EntityBillboardGui.Size
EntityImage.BackgroundTransparency = 1
EntityImage.Image = imgId
return EntityBase
end
troller = newEntity("rbxthumb://11954446780","imposter")
troller.Position = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
trololol = Instance.new("Sound", troller)
trololol.SoundId = "http://www.roblox.com/asset/?id=5677788502"
trololol:Play()
wait(2)
troller:Destroy()
game.Players.LocalPlayer.Character.Humanoid.Health = 0
Can anybody help fix it?
For starters I would recommend seperating the parent, like this:
EntityBase = Instance.new("Part") EntityBase.Parent = workspace
SECOND: I would recommend not using a seperate part, just put the billboardGui into the player's head
third you used rbxthumb wrong
rbxthumb://type=[ThumbnailType]&id=[TargetId]&w=[Width]&h=[Height]”
These are the supported sizes and types
example: rbxthumb://type=Avatar&id=123456789&w=720&h=720

lua setteam issue with another job

In the current example we have two different jobs, one is an ST, and the other is a Jedi, in this case Anakin Skywalker. The difference between the two professions, is in the code according to my opinion possibly none, I'm not sure in this regard, however, unlike the ST job in the game itself I can enter /setteam name ST to become the job, this does not happen with the job for the Jedi.
TEAM_ST = DarkRP.createJob("ST", {
color = Color(0, 0, 0),
model = "models/hazel/cg_models/1_et/cg_et.mdl",
description = [[
Ein ausgebildeter Klonsoldat
]],
weapons = {
"comlink_swep",
"cross_arms_swep",
"cross_arms_infront_swep",
"hololink_swep",
"point_in_direction_swep",
"salute_swep",
"surrender_animation_swep"
},
command = "ST",
max = 99,
salary = 10,
admin = 0,
vote = false,
hasLicense = false,
category = "Klon",
canDemote = false,
PlayerSpawn = function(ply)
ply:SetHealth(100)
ply:SetMaxHealth(100)
ply:SetArmor(100)
ply:SetMaxArmor(100)
end,
})
TEAM_AS = DarkRP.createJob("Anakin Skywalker", {
color = Color(0, 0, 0),
model = "models/kaiido/anakin/anakin.mdl",
description = [[
Ein mächtiger Jedi-Schüler
]],
weapons = {
"comlink_swep",
"cross_arms_swep",
"cross_arms_infront_swep",
"hololink_swep",
"point_in_direction_swep",
"salute_swep",
"surrender_animation_swep"
},
command = "AS",
max = 1,
salary = 15,
admin = 0,
vote = false,
hasLicense = false,
category = "Jedi",
canDemote = false,
PlayerSpawn = function(ply)
ply:SetHealth(5000)
ply:SetMaxHealth(5000)
ply:SetArmor(100)
ply:SetMaxArmor(100)
end,
})
Any idea about my problem?
I basically tried to recreate the job several times, looking for erroneous characters or blanks etc, I didn't find anything.

How to use values ​from one module script in another module script?

Faced such problem: it is necessary to use values ​​from other module script in one module script. Both module scripts contain tables with float, boolean and string values. How in theory can this be done and is it possible at all? And if not, what are the alternative solutions? I read on the forum that this can be done, but how exactly was not explained anywhere.
For example.
One module script:
local characters = {
["CharacterOne"] = {
["Health"] = 100,
["InGroup"] = false,
["Eating"] = {"Fruit", "Meat"}
};
["CharacterTwo"] = {
["Health"] = 260,
["InGroup"] = true,
["Eating"] = {"Meat"}
}
}
return characters
Two module script:
local food = {
["Fruit"] = {
["Saturation"] = 20,
["Price"] = 2
},
["Meat"] = {
["Saturation"] = 50,
["Price"] = 7
}
}
return food
The documentation for ModuleScripts tells you how to use them in other source containers: the require function.
So assuming that you've named your ModuleScripts Characters and Food respectively, and assuming that they are siblings in a folder, you could utilize the require function like this :
local Food = require(script.Parent.Food)
local characters = {
["CharacterOne"] = {
["Health"] = 100,
["InGroup"] = false,
["Eating"] = { Food.Fruit, Food.Meat }
};
["CharacterTwo"] = {
["Health"] = 260,
["InGroup"] = true,
["Eating"] = { Food.Meat }
}
}
return characters

Lua "if...then" statement unresponsive

I'm a newbie using LUA to make missions in
Operation Flashpoint: Dragon Rising's mission editor. I've been trying to get the script down for about a week, I've googled, edited, and scoured the help index of the editor till it feels like my eyes are bleeding and it's all led to this.
I'm having an issue with this "if...then" statement not doing anything. First, here's the whole thing:
function onMissionStart()
OFP:showLetterBoxOsd(false);
OFP:allowPlayerMovement(true);
OFP:allowPlayerFire(true);
OFP:setObjectiveState("Wave1","IN_PROGRESS");
OFP:setObjectiveState("Wave2","IN_PROGRESS");
OFP:activateEntitySet("enemy1");
end --This all seems to work fine, nothing to see here.
--OFP:isAlive(name of unit or entity set)
function isAlive() --After naming this function, a pesky "'<name>' expected near 'if'" error dissapeared so thats nice.
if OFP:isAlive("enemy1") == (false) --This "if..Then" statement should spawn "enemy2" when "enemy1" dies.
then
OFP:activateEntitySet("enemy2");
end
if OFP:isAlive("enemy2") == (false)
then
OFP:setObjectiveState("Wave2","COMPLETED")
OFP:missionCompleted()
end
end
Now here's what's giving me trouble:
function isAlive()
if OFP:isAlive("enemy1") == (false)
then
OFP:activateEntitySet("enemy2");
end
This is supposed to spawn enemy2 when enemy1 dies, but in game it might as well not exist, it doesn't work.
This names my function, the next line was throwing '<name>' expected near if until I did.
function isAlive()
This should track whether enemy1 is still alive, and if it returns a false it should spawn enemy2.
if OFP:isAlive("enemy1") == (false)
then
OFP:activateEntitySet("enemy2");
end
function onMissionStart ist most likely a function the game calls when the mission starts. I could not find any official reference manual but the game seems to have some event based scripting system.
The remaining code you provided probably only executed when the file is loaded and therefor without any effect during the game.
Edit due to comment:
function onMissionStart()
OFP:showLetterBoxOsd(false);
OFP:allowPlayerMovement(true);
OFP:allowPlayerFire(true);
OFP:setObjectiveState("Wave1","IN_PROGRESS");
OFP:setObjectiveState("Wave2","IN_PROGRESS");
OFP:activateEntitySet("enemy1");
end --This all seems to work fine, nothing to see here.
The above code defines the function onMissionStart(). It most likely implements a function that is called by the game, when the mission starts.
You added the following code if I'm not mistaken:
--OFP:isAlive(name of unit or entity set)
function isAlive() --After naming this function, a pesky "'<name>' expected near 'if'" error dissapeared so thats nice.
if OFP:isAlive("enemy1") == (false) --This "if..Then" statement should spawn "enemy2" when "enemy1" dies.
then
OFP:activateEntitySet("enemy2");
end
if OFP:isAlive("enemy2") == (false)
then
OFP:setObjectiveState("Wave2","COMPLETED")
OFP:missionCompleted()
end
end
This also defines a function. isAlive. But who calls that function and when?
I found a list of events in DROPP. I presume that's the mission editor thing you're talking about. On certain events it will run certain functions. Like onAllplayersDead() would be called if all players are dead.
Explaining this all would be beyond the scope of this community. Just read through all of http://www.suderman.com/OFPDR/DROPP/reference.html and all files in http://www.suderman.com/OFPDR/DROPP/download.html
EventScripts = {
onAllPlayersDead = 0,
onArriveAtWaypoint = 0,
onCmdCompleted = 0,
onDeath = 0,
onDespawnEntitySet = 0,
onDespawnEntity = 0,
onDismount = 0,
onEnter = 0,
onEnterRVPoint = 0,
onFirepowerKill = 0,
onHit = 0,
onIdentified = 0,
onIncap = 0,
onLand = 0,
onLeave = 0,
onMissionStart = 0,
onMobilityKill = 0,
onMount = 0,
onMultiplayerMissionLoaded = 0,
onNoAmmo = 0,
onNoAmmoAll = 0,
onObjectDamage = 0,
onObjectDamage = 0,
onObjectiveCompleted = 0,
onObjectiveFailed = 0,
onObjectiveVisible = 0,
onOffboardSupp = 0,
onPinned = 0,
onPlaceableKill = 0,
onPlayEnter = 0,
onPlayDone = 0,
onPlayFailed = 0,
onPlayInvalid = 0,
onPvPMissionEnd = 0,
onRespawn = 0,
onSpawnedReady = 0,
onSpeechEnd = 0,
onSuppressed = 0,
onSuspected = 0,
onUnsuppressed = 0,
}

Lua table variables the same even for new objects

I'm trying to create a Lua table that represents a matrix, however I keep running into a problem where if I create two Matrices, and initialize some values they both have the same values.
--Test.Lua
require"Matrix"
M1 = Matrix.Matrix:New()
M2 = Matrix.Matrix:New()
M1._11 = 2
print(M1._11) --Prints 2
print(M2._11) --Prints 2
--Matrix.lua
module("Matrix", package.seeall)
Matrix = {}
Matrix = { _11 = 0, _12 = 0, _13 = 0,
_21 = 0, _22 = 0, _23 = 0,
_31 = 0, _32 = 0, _33 = 0
}
function Matrix:New()
object = object or {}
setmetatable(object, self)
self.__index = self
return object
end
object = object or {}
This is why that happens. You only ever create one Matrix object. There is only every one object table which you return, and there is only ever one self table that you use as a metatable.
So how can you expect different instances when Matrix:New will always return the exact same value on every call?
You need to return a new table for each New call; that's why we use that name ;) Because of the way you're using a metatable, you also have to return a new metatable; you can't return the same metatable attached to new tables and expect it to work.
As nicol is explaining, on one hand you are trying to "reuse the same object over and over" (probably to "make it faster") and on the other you want to have different objects.
The solution is - don't reuse object on New call.
local Matrix = {} -- don't use the module function. Make Matrix local ...
Matrix.__index = Matrix
function Matrix:New()
local object = { -- create one local variable on every call to New
_11 = 0, _12 = 0, _13 = 0,
_21 = 0, _22 = 0, _23 = 0,
_31 = 0, _32 = 0, _33 = 0
}
setmetatable(object, self)
return object
end
return Matrix -- ... and return the Matrix local var at the end
A couple notes:
You really must learn how to use local
Usage of the module function is not recommended. Return a local table instead, as in my example.
Usage: assuming that that file is called "Matrix.lua":
local Matrix = require 'Matrix'
local M1 = Matrix:New()
local M2 = Matrix:New()
-- etc
As a sidenote, the Matrix:New() function can be made shorter (and faster). The following implementation works exactly as the one above, but it's slightly more efficient:
function Matrix:New()
return setmetatable({
_11 = 0, _12 = 0, _13 = 0,
_21 = 0, _22 = 0, _23 = 0,
_31 = 0, _32 = 0, _33 = 0
},
self)
end
This works because setmetatable(t,m) returns t with m already set as its metatable.

Resources