Rules:
- Must be about Lua, we have a general chatbox for other stuff.
- Be nice to each other!
Moderator: Plugin Moderators
Code: Select all
"id": "$script",
"type": "script",
"script": "example.lua",
"privileged": [privilege key] // <-- You need this to use this function
GreatØlsken wrote: ↑18 Jun 2020, 13:41How to use City.earnMoney(amount, x, y, showOverlay, budgetItem)
In order to use City.earnMoney() in the first place your script would need to be privileged
JSON:Note: privileged keys are only given to trusted members!Code: Select all
"id": "$script", "type": "script", "script": "example.lua", "privileged": [privilege key] // <-- You need this to use this function
Once you make your script privileged you can the function City.earnMoney()
parameters:showOverlay example:
- amount [number]: The amount of money you will earn when the function is called.
- x [number]: X value of where the green text will appear.
- y [number]: Y value of where the green text will appear.
- showOverlay [boolean]: Whether to show the overlay or not. (default false)
- budgetItem [draft]: *I have no idea what this is*
showOverlay.gif
Green text example:
20200618_202715.jpg
I hope this answered your question @rjroldan1
Bear Out!
viewtopic.php?f=81&t=10561
What do you mean "script:event"?and about to enable if some events occurs with that building ?
Im clueless
Code: Select all
// Script event :
function script:event(x,y,level,event)
if Script.EVENT_UPGRADE and City.countBuildings(draft) >= 1 then
actions
end
end
// with 2 conditions:
function script:update()
if City.countBuildings(draft) == 1 and City.isOnline() then
actions
end
end
Code: Select all
function script:event(x, y, level, event)
if event == Script.EVENT_PLACED then
<...>
end
end
Code: Select all
[
{
"id": "$example_res00",
...
"script": "example_script.lua" // attaches script to draft
},
{
"id": "$example_res01",
...
// doesn't have a script
}
]
Oh, I thought script are separated with Plugins:)Ølsken wrote: ↑19 Jun 2020, 09:55The usage of script:event() is bit wrong so I'll explain it.
Lua (example_script.lua):First you need to use event == [event]Code: Select all
function script:event(x, y, level, event) if event == Script.EVENT_PLACED then <...> end end
Also you can only use events to drafts that are attached to the script.
JSON (example.json):So now the event will only be called for $example_res00 and not for $example_res01.Code: Select all
[ { "id": "$example_res00", ... "script": "example_script.lua" // attaches script to draft }, { "id": "$example_res01", ... // doesn't have a script } ]
So when $example_res00 is placed script:event(x, y, level, event) will return EVENT_PLACED for event. but nil when $example_res01 is placed.
I see on your script (image) in luacheck linting post viewtopic.php?f=115&t=11437 and there are just Script.EVENT_PLACED without event.Ølsken wrote: ↑19 Jun 2020, 09:55The usage of script:event() is bit wrong so I'll explain it.
Lua (example_script.lua):First you need to use event == [event]Code: Select all
function script:event(x, y, level, event) if event == Script.EVENT_PLACED then <...> end end
Sorry about that it should be event == [event]distian wrote: ↑19 Jun 2020, 10:08I see on your script (image) in luacheck linting post viewtopic.php?f=115&t=11437 and there are just Script.EVENT_PLACED without event.Ølsken wrote: ↑19 Jun 2020, 09:55The usage of script:event() is bit wrong so I'll explain it.
Lua (example_script.lua):First you need to use event == [event]Code: Select all
function script:event(x, y, level, event) if event == Script.EVENT_PLACED then <...> end end
![]()
<!> match1 = string.match(..cname, "^Aos") <-- "..cname" would give you an error, you don't need the ".." part
Code: Select all
cname:match("^Aos")
-- Is the same as
string.match(cname, "^Aos")
Code: Select all
if cname:match("^Aos") then
Debug.toast("working")
end
"." would mean find the following inside the table
Code: Select all
local foo = {"Olsken", x = 12, hello = function(t) print("x value of this table is: "..t.x) end}
Code: Select all
print(foo[1])
--- Outputs: Olsken [string]
print(foo.x)
--- Outputs: 12 [number]
print(foo["x"]) <--- This does the same thing as "." would
--- Outputs: 12 [number]
print(foo.hello())
--- Error: attempt to index a nil value (local 't')
print(foo:hello())
--- Output: x value of this table is: 12 [string]
Code: Select all
local foo = {1, 2, 3, 4, 5}
print(#foo)
--- Outputs: 5
Code: Select all
local foo = {x = 12, y = 12}
print(#foo)
--- Outputs: 0
Code: Select all
function table_size(t)
local count = 0
for key, value in pairs(t) do
count = count + 1
end
return count
end
local foo = {x = 12, y = 12}
print(table_size(foo))
--- Outputs: 2
Code: Select all
local mt = {
__len = function()
-- This function will be called when the length operator is used
end
}
Code: Select all
local mt = {
__len = function(t)
local count = 0
for key, value in pairs(t) do
count = count + 1
end
return count
end
}
Code: Select all
setmetatable(foo, mt)
Code: Select all
print(#foo)
--- Outputs: 2
Try this:
Code: Select all
local flag1 = Draft.getDraft('$Aosflag4')
function script:update()
local rank = City.getRank()
end
function script:draw(x,y,level)
... Drawing stuff ...
Drawing.drawImage('flag1')
if rank >= 1 then
Drawing.reset()
end
end