This is the place for discussion and support for LunaLua and related modifications and libraries.
Moderator: Userbase Moderators
Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9890
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Sat Dec 17, 2016 9:19 am
PixelPest wrote:RPG_Magician wrote:Can someone give me an idea of how to get an npc to move (like a big leap) to one position to another?
First you'll need to load pnpc.lua. Then in onTick() you'll have to grab all of that NPC in the level using in pairs and then wrap each NPC via pnpc.wrap(). From here you'll have to create a data object for each NPC that acts as a counter to tell it when to jump via something like:
Code: Select all if npc.data.counter == nil then
npc.data.counter = 300;
elseif (npc.data.counter == 100) and (not npc.collideBlockBottom) then
npc.data.counter = 101;
elseif (npc.data.counter < 100) and (npc.data
counter > 0) and (not npc.collideBlockBottom) then
npc.speedY = num;
else
npc.data.counter = 300;
end
You'll likely want to change "num" to a formula to create a nice parabolic jump and you can edit the counter values too. I also added a test to see if the NPC is not touching the ground or else the jump should end as well as a similar test to make sure that before it jumps it is in fact touching the ground. You may or may not need to edit speedX during the jump too. Depending on the NPC you may need to use npcconfig.lua to set nogravity to 1 for that NPC during the jump to get a bit more control. After this code I posted above you'll need to subtract 1 from npc.data.counter each tick. An alternate way to do this would be to use the SMB3 paragoomba or SMW paragaloomba and modify its AI fields. You may still need pnpc.lua to do that though in a similar fashion as I've shown above, it will just make the jump itself easier to handle
Your code is untested and littered with errors.
First of all, it's collidesBlockBottom.
Secondly, you're never modifying counter, nor is it clear from your explanation what you're even trying to do with it. The way this code is set up is confusing as hell.
You also only ever modify speedY when the enemy is NOT touching the ground. From the looks of it, it'll NEVER jump, as the counter will be stuck at 101.
Another hassle is the fact that NPC.speedX and NPC.speedY can only be modified if the NPC isn't already modifying these fields in vanilla SMBX. Editing speedX for most NPCs is impossible and it's easier to use NPC.dontMove or program an NPC-like object from scratch.
Applying the force for 100 frames is silly as well, so is setting nogravity. npcconfig modifies config for all npcs of an id. You can't do anything for individual npcs with it. The force also only needs to be applied for one frame. After that you can let gravity handle the rest.
|
|
|
|
|
|
|
|
|
-
DeMuZ
- Fighter Fly

- Posts: 37
- Joined: Thu Aug 18, 2016 2:35 pm
Postby DeMuZ » Sat Dec 17, 2016 12:22 pm
Code: Select all local ssj0 = Graphics.loadAnimatedImage(getSMBXPath().."\\worlds\\The Seven Stars (by DeMuZ)\\hud gfx\\ssj 0.gif")
function onTick()
Graphics.drawImageToSceneWP(ssj0, X1, Y1, 5)
end
Am I doing it wrong? It doesn't work.
|
|
|
|
|
|
|
|
|
-
PixelPest
- Link

- Posts: 7111
- Joined: Sun Jul 12, 2015 5:38 pm
- Flair: Tamer of Boom Booms
-
Contact:
Postby PixelPest » Sat Dec 17, 2016 1:17 pm
It doesn't look like you've defined X1 or Y1 anywhere and also you might need to use a .png file (not 100% sure about that though)
|
|
|
|
|
|
|
|
|
-
loop
- Ninji

- Posts: 984
- Joined: Sun Apr 17, 2016 5:56 pm
- Flair: i may be dumb but im not stupid!
- Pronouns: he/him/they
Postby loop » Sat Dec 17, 2016 1:21 pm
PixelPest wrote:It doesn't look like you've defined X1 or Y1 anywhere and also you might need to use a .png file (not 100% sure about that though)
I am pretty sure that it does require PNGs.
|
|
|
|
|
|
|
|
|
-
Kevsoft
- Ripper II

- Posts: 375
- Joined: Sun Jul 27, 2014 8:03 am
Postby Kevsoft » Sat Dec 17, 2016 1:41 pm
DeMuZ wrote:Code: Select all local ssj0 = Graphics.loadAnimatedImage(getSMBXPath().."\\worlds\\The Seven Stars (by DeMuZ)\\hud gfx\\ssj 0.gif")
function onTick()
Graphics.drawImageToSceneWP(ssj0, X1, Y1, 5)
end
Am I doing it wrong? It doesn't work.
PGE Wiki wrote:
table of LuaImageResource
The return value of Graphics.loadAnimatedImage is a table of LuaImageResource.
|
|
|
|
|
|
|
|
|
-
DeMuZ
- Fighter Fly

- Posts: 37
- Joined: Thu Aug 18, 2016 2:35 pm
Postby DeMuZ » Sat Dec 17, 2016 1:52 pm
A TABLE??? Oh... i forgot about it  thanks
btw, X1 and Y1 were defines, that was only a few lines of my code
Loads an animated image (i.e. gifs) and returns a table of each frame in the animated image. The second return argument is the average frame speed (SMBX frames per frame switch) given by the gif metadata.
After reading this, I still don't know how to use it in other functions :<
|
|
|
|
|
|
|
|
|
-
timocomsmbx2345
- Foo

- Posts: 853
- Joined: Sat Feb 06, 2016 1:44 pm
-
Contact:
Postby timocomsmbx2345 » Sat Dec 17, 2016 3:51 pm
I need help with using anything inside the LuaScriptsLib folder.
|
|
|
|
|
|
|
|
|
-
Kevsoft
- Ripper II

- Posts: 375
- Joined: Sun Jul 27, 2014 8:03 am
Postby Kevsoft » Sat Dec 17, 2016 4:27 pm
DeMuZ wrote:A TABLE??? Oh... i forgot about it  thanks
btw, X1 and Y1 were defines, that was only a few lines of my code
Loads an animated image (i.e. gifs) and returns a table of each frame in the animated image. The second return argument is the average frame speed (SMBX frames per frame switch) given by the gif metadata.
After reading this, I still don't know how to use it in other functions :<
Well, it's quite simple. If your gif has a total of 3 frames, then you can extract those pretty easy:
Code: Select all local ssj0 = Graphics.loadAnimatedImage(getSMBXPath().."\\worlds\\The Seven Stars (by DeMuZ)\\hud gfx\\ssj 0.gif")
local ssj0_1 = ssj0[1]
local ssj0_2 = ssj0[2]
local ssj0_3 = ssj0[3]
or iterate through all frames:
Code: Select all local ssj0 = Graphics.loadAnimatedImage(getSMBXPath().."\\worlds\\The Seven Stars (by DeMuZ)\\hud gfx\\ssj 0.gif")
for i in 1, #ssj0 do
local frame = ssj0[i]
-- Do something with frame here
end
|
|
|
|
|
|
|
|
|
-
timocomsmbx2345
- Foo

- Posts: 853
- Joined: Sat Feb 06, 2016 1:44 pm
-
Contact:
Postby timocomsmbx2345 » Sat Dec 17, 2016 4:30 pm
My PGE doesn't know what ".lua" file are, becuase they dont work
Becuase I need help with using anything inside the LuaScriptsLib folder.
|
|
|
|
|
|
|
|
|
-
loop
- Ninji

- Posts: 984
- Joined: Sun Apr 17, 2016 5:56 pm
- Flair: i may be dumb but im not stupid!
- Pronouns: he/him/they
Postby loop » Sat Dec 17, 2016 5:17 pm
timocomsmbx2345 wrote:My PGE doesn't know what ".lua" file are, becuase they dont work
Becuase I need help with using anything inside the LuaScriptsLib folder.
Weird. Try putting the used codes in the same folder the lunadll.lua file is in.
|
|
|
|
|
|
|
|
|
-
timocomsmbx2345
- Foo

- Posts: 853
- Joined: Sat Feb 06, 2016 1:44 pm
-
Contact:
Postby timocomsmbx2345 » Sat Dec 17, 2016 5:26 pm
Quantix wrote:timocomsmbx2345 wrote:Jayce 777 wrote:
Use moarrinkas.lua and NPCParse.lua.
but that didnt work for me the engine doesnt know those files are in th folders
Well, you need to type it as ("NPCs//moarrinkas") for it to work. Though, the API's kinda broken as of now so you're better off not using it anyway.
Well how does this then? https://www.youtube.com/watch?v=yhcnNsdLqbU&t=3s
|
|
|
|
|
|
|
|
|
-
DeMuZ
- Fighter Fly

- Posts: 37
- Joined: Thu Aug 18, 2016 2:35 pm
Postby DeMuZ » Sat Dec 17, 2016 6:39 pm
|
|
|
|
|
|
|
|
|
-
Mr10crossing
- Cheep-Cheep

- Posts: 13
- Joined: Sat Sep 05, 2015 5:47 pm
Postby Mr10crossing » Sat Dec 17, 2016 8:12 pm
Is there a way I can replace the starman music using LunaLua in SMBX 2.0 Beta 3?
|
|
|
|
|
|
|
|
|
-
loop
- Ninji

- Posts: 984
- Joined: Sun Apr 17, 2016 5:56 pm
- Flair: i may be dumb but im not stupid!
- Pronouns: he/him/they
Postby loop » Sat Dec 17, 2016 8:17 pm
Mr10crossing wrote:Is there a way I can replace the starman music using LunaLua in SMBX 2.0 Beta 3?
That should be simpler than drawing a tesseract. I haven't touched SMBX in a month due to my laptop breaking again though. Someone else should be able to help though. 
|
|
|
|
|
|
|
|
|
-
Wohlstand
- Chargin' Chuck

- Posts: 2008
- Joined: Tue Feb 11, 2014 4:44 pm
- Flair: [ˈvoːlˌʃtant], 狐エンジニア
- Pronouns: he/him
-
Contact:
Postby Wohlstand » Sun Dec 18, 2016 1:00 am
timocomsmbx2345 wrote:My PGE doesn't know what ".lua" file are, because they don't work
Becuase I need help with using anything inside the LuaScriptsLib folder.
What are you trying to do with them?
- PGE Editor doesn't have internal IDE for that. Yet. (But are some ideas to make IDE-like thing to edit LUA codes directly from PGE with adding hints for LunaLua and PGE Engine's APIs, etc. That for far future, because now are more important reorganizing in the process).
- PGE Engine has own Lua APIs on NPC-AI, Level-Global, Playable Character and not yet per-level APIs (therefore doesn't work yet. P.S. LunaLua API will be PARTIALLY compatible with PGE Engine's in-level API, because no super-specific to SMBX commands and no mem() commands because super-useless on PGE side)
- "luna.lua" script names are new (to replace old names like "lunadll.lua") and requiring you fresh LunaLua version. It's already in public and latest SMBX 2.0 package. You still use "File" -> "Open custom data folder" menu item to quickly open a custom folder of your level.
|
|
|
|
|
|
|
|
|
-
DeMuZ
- Fighter Fly

- Posts: 37
- Joined: Thu Aug 18, 2016 2:35 pm
Postby DeMuZ » Sun Dec 18, 2016 8:36 am
Ok... I think I'm too dumb to make my code work with animated gif :v
If someone makes it work, he'll be given a virtual cookie.
The whole code:
Code: Select all local colliders = loadSharedAPI("colliders")
local rng = loadSharedAPI("rng")
local encrypt = loadSharedAPI("encrypt")
xData = encrypt.Data(Data.DATA_WORLD,true)
intro = false
local hurt = 0
local time = 100
local Aura = 0
local showInstruction = 0
------------------------------------------------------------------------------------------
local star_gfx = Graphics.loadImage(getSMBXPath().."\\worlds\\The Seven Stars (by DeMuZ)\\hud gfx\\star.png")
local hp_gfx = Graphics.loadImage(getSMBXPath().."\\worlds\\The Seven Stars (by DeMuZ)\\hud gfx\\hp.png")
local coin_gfx = Graphics.loadImage(getSMBXPath().."\\worlds\\The Seven Stars (by DeMuZ)\\hud gfx\\coin.png")
local life_gfx = Graphics.loadImage(getSMBXPath().."\\worlds\\The Seven Stars (by DeMuZ)\\hud gfx\\1up.png")
local ssj0 = Graphics.loadAnimatedImage(getSMBXPath().."\\worlds\\The Seven Stars (by DeMuZ)\\hud gfx\\ssj 0.gif")
local ssj1 = Graphics.loadAnimatedImage(getSMBXPath().."\\worlds\\The Seven Stars (by DeMuZ)\\hud gfx\\ssj 1.gif")
local ssj2 = Graphics.loadAnimatedImage(getSMBXPath().."\\worlds\\The Seven Stars (by DeMuZ)\\hud gfx\\ssj 2.gif")
local ssj3 = Graphics.loadAnimatedImage(getSMBXPath().."\\worlds\\The Seven Stars (by DeMuZ)\\hud gfx\\ssj 3.gif")
local ssj_blue = Graphics.loadAnimatedImage(getSMBXPath().."\\worlds\\The Seven Stars (by DeMuZ)\\hud gfx\\ssj 4.gif")
------------------------------------------------------------------------------------------
if xData:get("coins") == nil then
xData:set("coins",0)
xData:save()
end
if xData:get("Max_hp") == nil then
xData:set("Max_hp",5)
xData:save()
end
if xData:get("world") == nil then
xData:set("world",1)
xData:save()
end
if xData:get("aura") == nil then
xData:set("aura",0)
xData:save()
end
------------------------------------------------------------------------------------------
local max_hp = xData:get("Max_hp")
------------------------------------------------------------------------------------------
function onTick()
max_hp = xData:get("Max_hp")
--all the forms
if xData:get("hp") > max_hp*2/3 then
aura()
else
Aura = 0
if player.altJumpKeyPressing == true then
player.altJumpKeyPressing = false
player.jumpKeyPressing = true
end
Defines.jumpheight = 16
Defines.jumpheight_bounce = 16
Defines.player_runspeed = 5
Defines.player_walkspeed = 2.5
end
--hp_system_core
HP()
if Level.filename() == "intro.lvl" then
if intro == true then
player.speedX = 0
player.speedY = 0
player.jumpKeyPressing = false
player.altJumpKeyPressing = false
end
end
if Level.filename() ~= "intro.lvl" then
--hp
Graphics.drawImage(hp_gfx,8,64)
Text.print(xData:get("hp").."/"..max_hp,32,64)
--lives
Graphics.drawImage(life_gfx,8,44)
Text.print(mem(0x00B2C5AC,FIELD_FLOAT),32,44)
--coins
coins()
--stars
if mem(0x00B251E0,FIELD_WORD) > 0 then
Graphics.drawImage(star_gfx,8,84)
Text.print(mem(0x00B251E0,FIELD_WORD).."/7",32,84)
end
end
end
------------------------------------------------------------------------------------------
Graphics.activateHud(false)
------------------------------------------------------------------------------------------
function aura()
local X1 = player.x - 12
local Y1 = player.y - 12
if Aura < 0 then
Aura = 0
end
function onKeyboardPress(key)
--instruction
if key == VK_TAB then
showInstruction = 100
end
--power up!!!
if key == VK_SPACE then
if Aura < (xData:get("aura")+1)*20 then
Aura = Aura + 1
end
else
if Aura < 20 then
Aura = 0
elseif Aura < 40 then
Aura = 20
elseif Aura < 60 then
Aura = 40
elseif Aura < 80 then
Aura = 60
elseif Aura < 100 then
Aura = 80
end
end
end
--power down!!!
if player.altRunKeyPressing then
Aura = 0
end
--instruction
if showInstruction > 0 then
Text.print("Hold (Space) to power up.",8,556)
Text.print("Press (Tanooki) to power down.",8,576)
showInstruction = showInstruction - 1
else
Text.print("(TAB)",8,576)
end
--base form
if Aura < 20 then
if player.altJumpKeyPressing == true then
player.altJumpKeyPressing = false
player.jumpKeyPressing = true
end
Defines.jumpheight = 16
Defines.jumpheight_bounce = 16
Defines.player_runspeed = 5
Defines.player_walkspeed = 2.5
end
--full potential base form
if Aura >= 20 and Aura < 40 then
for i = 1, 3 do
frame = ssj0[i]
Graphics.drawImageToSceneWP(frame, X1, Y1, 5)
end
Defines.jumpheight = 20
Defines.jumpheight_bounce = 20
Defines.player_runspeed = 6
Defines.player_walkspeed = 3
end
--super saiyan form (ssj)
if Aura >= 40 and Aura < 60 and xData:get("aura") > 0 then
for i = 1, 3 do
frame = ssj1[i]
Graphics.drawImageToSceneWP(frame, X1, Y1, 5)
end
player.powerup = PLAYER_FIREFLOWER
Defines.jumpheight = 24
Defines.jumpheight_bounce = 24
Defines.player_runspeed = 7
Defines.player_walkspeed = 3.5
end
--ascended super saiyan form (ssj2)
if Aura >= 60 and Aura < 80 and xData:get("aura") > 1 then
for i = 1, 3 do
frame = ssj2[i]
Graphics.drawImageToSceneWP(frame, X1, Y1, 5)
end
Defines.jumpheight = 28
Defines.jumpheight_bounce = 28
Defines.player_runspeed = 8
Defines.player_walkspeed = 4
end
--final super saiyan form (ssj3)
if Aura >= 80 and Aura < 100 and xData:get("aura") > 2 then
for i = 1, 3 do
frame = ssj3[i]
Graphics.drawImageToSceneWP(frame, X1, Y1, 5)
end
Defines.jumpheight = 32
Defines.jumpheight_bounce = 32
Defines.player_runspeed = 9
Defines.player_walkspeed = 4.5
end
--super saiyan blue (ssjb)
if Aura >= 100 and xData:get("aura") > 3 then
for i = 1, 3 do
frame = ssj_blue[i]
Graphics.drawImageToSceneWP(frame, X1, Y1, 5)
end
Defines.jumpheight = 36
Defines.jumpheight_bounce = 36
Defines.player_runspeed = 8
Defines.player_walkspeed = 4
end
end
------------------------------------------------------------------------------------------
function coins()
if mem(0x00B2C5A8,FIELD_WORD) > 0 then
xData:set("coins",xData:get("coins")+1)
mem(0x00B2C5A8,FIELD_WORD,mem(0x00B2C5A8,FIELD_WORD)-1)
end
Graphics.drawImage(coin_gfx,8,24)
Text.print(xData:get("coins"),32,24)
end
------------------------------------------------------------------------------------------
function onExitLevel()
xData:save()
end
---------------------------------------------------------------------------------
function onEvent(name)
if name == "checkpoint" and xData:get("hp") < max_hp and time == 0 then
xData:set("hp", xData:get("hp")+1)
xData:save()
end
if name == "exit1" then
xData:set("world",2)
xData:save()
end
intro = false
if name == "START" then
intro = true
end
--SHOP!!!
if name == "SHOP mushroom" and xData:get("coins") >= 200 and xData:get("hp") < max_hp then
xData:set("hp", xData:get("hp")+1)
xData:set("coins", xData:get("coins")-200)
xData:save()
end
if name == "SHOP 1up" and xData:get("coins") >= 300 then
mem(0x00B2C5AC,FIELD_FLOAT, mem(0x00B2C5AC,FIELD_FLOAT)+1)
xData:set("coins", xData:get("coins")-300)
xData:save()
end
if name == "SHOP max_hp 6" and xData:get("coins") >= 1000 and xData:get("Max_hp") < 6 then
xData:set("Max_hp", 6)
xData:set("coins", xData:get("coins")-1000)
xData:save()
end
end
---------------------------------------------------------------------------------
function onStart()
if Level.filename() == "intro.lvl" then
xData:set("coins",0)
xData:set("hp",1)
xData:set("Max_hp",5)
xData:set("world",1)
xData:set("aura",0)
xData:save()
end
if xData:get("hp") == nil or xData:get("hp") == 0 then
xData:set("hp",1)
xData:save()
end
if xData:get("world") > 1 then
triggerEvent("warp1")
end
end
---------------------------------------------------------------------------------
function onNPCKill(eventObj, npcObj, npcKillReason)
if xData:get("hp") < max_hp and npcObj.id == 9 and npcKillReason == 9 then
xData:set("hp", xData:get("hp")+1)
xData:save()
end
if npcObj.id == 184 and npcKillReason == 9 then
xData:set("hp", max_hp)
xData:save()
end
end
--<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
function HP()
if time > 0 then
time = time - 1
end
if player.powerup ~= PLAYER_SMALL and xData:get("hp") == 1 then
player.powerup = PLAYER_SMALL
player:mem(0x122,FIELD_WORD,12)
end
if player.powerup == PLAYER_HAMMER then
player.powerup = PLAYER_BIG
end
if player:mem(0x158, FIELD_WORD) == 9 then
player:mem(0x158, FIELD_WORD,0)
end
if player:mem(0x13E, FIELD_WORD) > 0 and hurt == 0 then
xData:set("hp",0)
xData:save()
end
if hurt == 0 then
if player:mem(0x122, FIELD_WORD) == 2 then
xData:set("hp", xData:get("hp")-1)
xData:save()
hurt = 1
end
end
if player:mem(0x122, FIELD_WORD) ~= 2 and hurt > 0 then
hurt = 0
end
if xData:get("hp") > 1 and player.powerup == PLAYER_SMALL then
player.powerup = PLAYER_BIG
player:mem(0x122,FIELD_WORD,12)
end
end
|
|
|
|
|
|
|
|
|
-
Kevsoft
- Ripper II

- Posts: 375
- Joined: Sun Jul 27, 2014 8:03 am
Postby Kevsoft » Sun Dec 18, 2016 10:11 am
Okay, other question: How many frames does your animated gif have? You don't want to draw all the frames at once of course!
|
|
|
|
|
|
|
|
|
-
DeMuZ
- Fighter Fly

- Posts: 37
- Joined: Thu Aug 18, 2016 2:35 pm
Postby DeMuZ » Sun Dec 18, 2016 11:57 am
I posted links for that animations a few posts ago. Just right-click and save. I think it'll be more helpful (for me) than just giving the number of frames.
|
|
|
|
|
|
|
|
|
-
Kevsoft
- Ripper II

- Posts: 375
- Joined: Sun Jul 27, 2014 8:03 am
Postby Kevsoft » Sun Dec 18, 2016 2:19 pm
Well a simple way to draw the right frame, is to make a local variable of the current frame you want to draw:
Code: Select all
local frameNum_ssj0 = 1
-- <code>
-- somewhere for rendering
Graphics.draw(ssj0[frameNum_ssj0], X1, Y1, 5)
frameNum_ssj0 = frameNum_ssj0 + 1
if frameNum_ssj0 > #ssj0 then
frameNum_ssj0 = 1
end
I hope it makes somewhat sense for you
|
|
|
|
|
|
|
|
|
-
Angelus
- Tweeter

- Posts: 132
- Joined: Tue Jun 21, 2016 9:38 am
Postby Angelus » Mon Dec 19, 2016 11:48 am
Hello there, I've been trying to use LunaLua for custom music and while it works pretty well for most of the time, I'm facing a little problem here:
I know how to set the music to play into a specific event, but I would like to know how to make it stop after a posterior event, replacing it by silence. The problem is, all my attempts have failed since the music just start over again when I expected it to stop playing. Here's the code I have so far. Am I doing something wrong?
play = false
function onLoop()
if play then
Audio.SeizeStream(1.14)
Audio.MusicOpen("1 - 1 Boss.ogg")
Audio.MusicPlay()
end
end
function onEvent(eventname)
if eventname == "Cutscene 4 - 15" then
play = true
else
if eventname == "Cutscene 5 - 1" then
play = false
Audio.ReleaseStream(1.14)
end
end
|
|
|
|
|
Return to “LunaLua”
Users browsing this forum: No registered users and 3 guests
|