Page 26 of 32
Re: Need help with lua? - LunaLua General Help
Posted: Wed Aug 24, 2022 7:55 pm
by Emral
deice wrote: ↑Wed Aug 24, 2022 4:43 pm
however, if the lua file itself is right in your episode folder too (as opposed to a level's custom folder), the resolveFile() call is superfluous and can be removed:
Code: Select all
Graphics.loadImage("Folder/MyItem.png")
To my knowledge this is untrue, as all lua looks in the level folder of the current level first.
Re: Need help with lua? - LunaLua General Help
Posted: Wed Aug 24, 2022 10:24 pm
by LunarCatUSA
Thanks, now is it possible to trigger a door's opening effect without the player warping in front of it?
Like when the player is physically colliding with the door and does a certain action, how would I go about playing its opening effect?
And yes, I can confirm Enji is right.
Re: Need help with lua? - LunaLua General Help
Posted: Thu Aug 25, 2022 6:07 am
by deice
Enjl wrote: ↑Wed Aug 24, 2022 7:55 pm
To my knowledge this is untrue, as all lua looks in the level folder of the current level first.
my bad, i hadn't actually bothered to check whether the loadImage() call itself returned nil or not, haha~
LunarCatUSA wrote:
Thanks, now is it possible to trigger a door's opening effect without the player warping in front of it?
the door effects work like any other ones to my knowledge, just
spawning one at the door's location should be fine.
Re: Need help with lua? - LunaLua General Help
Posted: Thu Aug 25, 2022 4:38 pm
by LunarCatUSA
Okay so the code I have here:
Code: Select all
function onTick()
DynamicBackgrounds = BGO.get()
Interactibles = NPC.get(465)
-- Can the player hide here? --
for k,v in ipairs(Interactibles) do
if v.data._settings._global.hidingSpot and (colliders.collide(v, player)) and player.downKeyPressing == true then
playerhiding = true
SFX.play("Hide_Wood1.wav")
for kk,vv in ipairs(DynamicBackgrounds) do
if colliders.collide(vv, player) and vv.id == 87 then
spawnhideanim = Effect.spawn(55, vv)
spawnhideanim.x = vv.x
spawnhideanim.y = vv.y
end
end
end
end
And the code works up until effect spawn where I try the command, but it doesn't spawn there at all.
Am I calling the effect incorrectly? Or is this another thing where there's an extra step involved?
Added in 4 hours 54 minutes 23 seconds:
Okay, so other effects spawn but not doors for some reason. That's strange.
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 26, 2022 7:51 am
by deice
LunarCatUSA wrote: ↑Thu Aug 25, 2022 9:33 pm
And the code works up until effect spawn where I try the command, but it doesn't spawn there at all.
Am I calling the effect incorrectly? Or is this another thing where there's an extra step involved?
Added in 4 hours 54 minutes 23 seconds:
Okay, so other effects spawn but not doors for some reason. That's strange.
i ran the code myself and the door effect
does indeed spawn, however for some reason it isn't getting drawn (it's not that it's somehow getting drawn below the door either, i tried spawning it in other locations, same results). no idea what could be causing this, could a dev maybe chime in?
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 26, 2022 10:11 am
by Emral
Unsure, but it might make sense to simply copy the door effect from config/effects into the custom range and use that. other effects like underwater effects are known to be finnicky to spawn, so perhaps doors are the same.
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 26, 2022 1:08 pm
by LunarCatUSA
Hmmm.... I edited the txt file for effect-55 to become similar to the explosion effect-108 because that one actually works, but I guess that didn't do it. I may just edit one of the others to look like the door one and alter its effect text file.
Added in 7 hours 7 minutes 29 seconds:
Oh also, is it possible to have an enemy active off-screen?
I'm trying to give an enemy a "chase" mechanic similar to Phanto and I'm curious as to what makes it function off screen.
Re: Need help with lua? - LunaLua General Help
Posted: Sat Aug 27, 2022 3:26 pm
by LunarCatUSA
Oh, I found Enji's spawnzone code. I wonder if I should use that for my enemy's code.
Re: Need help with lua? - LunaLua General Help
Posted: Sat Aug 27, 2022 3:40 pm
by deice
LunarCatUSA wrote: ↑Fri Aug 26, 2022 8:15 pm
Oh also, is it possible to have an enemy active off-screen?
I'm trying to give an enemy a "chase" mechanic similar to Phanto and I'm curious as to what makes it function off screen.
you can just set it's despawnTimer to a positive value.
(as for the effects, as enjl said, all you need to do is make a custom effect, copy "effect-55.txt" from "data/config/effects" and rename it to fit the ID you need)
Re: Need help with lua? - LunaLua General Help
Posted: Sat Aug 27, 2022 10:41 pm
by LunarCatUSA
Thanks, I take it that it doesn't work if the enemy is in a different section? If that's the case, I'll probably just make a room change code for the 'search-for-the-player code' within the script of the level itself.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Aug 28, 2022 7:00 am
by deice
LunarCatUSA wrote: ↑Sat Aug 27, 2022 10:41 pm
Thanks, I take it that it doesn't work if the enemy is in a different section? If that's the case, I'll probably just make a room change code for the 'search-for-the-player code' within the script of the level itself.
a good example of how a basegame npc handles section changing can be found in the phanto ai script ("data/npc/ai/phantos.lua") from around line 205.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Aug 28, 2022 9:38 pm
by LunarCatUSA
Hmmm... yeah, I'm looking at that line of phanto code where it says 'StubbornTarget', I just gotta find out what keeps the dude active and moving in other sections while the player is in another one. I'll probably find it eventually.
Added in 1 hour 46 minutes 55 seconds:
Worst case scenario, I could always just keep everything to one section and just make it big for the rooms and warps. Change backgrounds and music via scripts.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Aug 29, 2022 12:33 pm
by LunarCatUSA
Question, is it possible to spawn a light point with specific attributes?
I want to spawn an instance of npc-668, the light, on a certain npc to make a 'glowing eye' feel. But I want to have the light span out to a certain radius and adjust its color accordingly.
I know how to spawn the npc, I just want to know how to make these adjustments, if it's possible.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Aug 29, 2022 1:00 pm
by deice
LunarCatUSA wrote: ↑Mon Aug 29, 2022 12:33 pm
Question, is it possible to spawn a light point with specific attributes?
yes:
Code: Select all
local v = NPC.spawn(668, ...)
local light = v.data._basegame.light
"light" can then be accessed by any other light source object.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Aug 29, 2022 1:16 pm
by LunarCatUSA
Alright, I'll try that. I think Enji made a video explaining how to put a light on things but for some reason,
local EnemyLight = darkness.Light(0,0,128,1,Color.white)
gives an error message and I can't find anything in the wohlsoft or codehaus guides explaining lights all that well.
I do know that I can attach em with the :attach() command.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Aug 29, 2022 1:49 pm
by deice
LunarCatUSA wrote: ↑Mon Aug 29, 2022 1:16 pm
local EnemyLight = darkness.Light(0,0,128,1,Color.white)
"darkness" should be "Darkness", capital; and "Light" should be "light", lowercase. you no longer need to explicitly load the library.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Aug 29, 2022 2:23 pm
by LunarCatUSA
Alright, I make the light
local biolum = Darkness.light(0,0,128,1,false,Color.white)
and then under onStart() I add
biolum:Attach(player)
end
and the player is still in the dark. Does it need to be enabled like an effect or is there another reason?
Added in 10 hours 10 minutes 31 seconds:
Okay, so here's my code for my NPC.
Code: Select all
Warppoints = Warp.get()
PlayersPath = {}
-- Warps it already passed through --
AlreadyCameFrom = {}
State = {"patrol", "search", "chase"}
if v.isValid == true then
Actpattern = State[1]
end
-- Patrol, this enemy is searching rooms for the player, it is in the same section as the player --
if Actpattern == State[1] then
if v.direction == -1 then
v.speedX = -1
elseif v.direction == 1 then
v.speedX = 1
end
for k, w in ipairs(Warppoints) do
if colliders.collide(v, w) and w ~= AlreadyCameFrom[1] then
headsortails = RNG.randomInt(0,100)
if headsortails <= 30 then
v:transform(897,true,true)
v.x=w.entranceX
v.y=w.entranceY-32
if AlreadyCameFrom[1] ~= nil then
table.remove(AlreadyCameFrom)
end
table.insert(AlreadyCameFrom, w)
end
elseif colliders.collide(v, w) and w == AlreadyCameFrom[1] then
headsortails = RNG.randomInt(0,100)
if headsortails <= 5 then
v:transform(897,true,true)
v.x=w.entranceX
v.y=w.entranceY-32
table.remove(AlreadyCameFrom)
table.insert(AlreadyCameFrom, w)
end
end
end
end
Basically, I want to make the code so that my enemy will pass a warp point and if it isn't the warppoint it exited, it has a 30% chance to enter it and if it is the warppoint it exited, it has a 5% chance to enter. Entering results in it spawning a smaller version of itself in the form of an animation that enters the door and spawns it on the end-side. That part is all done and good in another code but here's the issue; it gives an error message named "Unknown collider type". Does the collider not work with warp points?
Added in 9 hours 7 minutes 30 seconds:
Hmm... looks like the warp list perpetually defines all warp entrances and exits as NIL. I wonder if it shouldn't be under OnTick()
Added in 6 minutes 48 seconds:
Oh wait, x and y aren't actual variables for the warps, I need to check entranceX and entranceY
Re: Need help with lua? - LunaLua General Help
Posted: Tue Aug 30, 2022 10:24 am
by Marioman2007
LunarCatUSA wrote: ↑Tue Aug 30, 2022 9:48 am
Alright, I make the light
local biolum = Darkness.light(0,0,128,1,false,Color.white)
and then under onStart() I add
biolum:Attach(player)
end
and the player is still in the dark. Does it need to be enabled like an effect or is there another reason?
use onDraw()
Re: Need help with lua? - LunaLua General Help
Posted: Tue Aug 30, 2022 11:11 am
by Emral
Marioman2007 wrote: ↑Tue Aug 30, 2022 10:24 am
LunarCatUSA wrote: ↑Tue Aug 30, 2022 9:48 am
Alright, I make the light
local biolum = Darkness.light(0,0,128,1,false,Color.white)
and then under onStart() I add
biolum:Attach(player)
end
and the player is still in the dark. Does it need to be enabled like an effect or is there another reason?
use onDraw()
no? the point of the attach method is that it handles the position updates for you if done once.
https://docs.codehaus.moe/#/handbook/lu ... d-lighting
Lights need to be added to a darkness field explicitly, via Darkness.addLight(biolum)
Re: Need help with lua? - LunaLua General Help
Posted: Tue Aug 30, 2022 12:02 pm
by Marioman2007
ohh, glad to know now lol
I thought it was just a function that sets the position for one frame