LunaLua Help
Re: LunaLua Help
Okay lets get cracking!
I want to make a level based around the Starman, but I also want to try making some modifications to it's code (specifically, add a counter for after the music loops end and make use of the Colliders API), I think I understand what's going on for most of it, but some of the functions I have no clue what they do. For instance in starman.onTick there's something called NPC.getIntersecting. Is that for when mario picks up the star?
Another thing I tried to figure out last night is how to make Mario's fireballs shoot correctly (have only two on-screen at a time, with no timer in-between firing, and a change to their x-speed). But when I first tried it I didn't know what function or API I could use to count the fireballs in Mario's current section. I tried NPC.get but it returned some hex values, and NPC.count, which I couldn't figure out. I don't know what arguments .count takes, if any.
EDIT: Alright, I figured out the fireballs, but they persist while offscreen. I figure, I'll just find the screen coordinates and kill the npcs when they're about 4 blocks out, but I don't know how player.screen works. Its a RECT type and I went to look it up. Seems like its a function that returns the four boundary values? But whenever I try to use it I get "==> no such operator defined". Do I have to define a new RECT using player.screen? I'm clueless.
I want to make a level based around the Starman, but I also want to try making some modifications to it's code (specifically, add a counter for after the music loops end and make use of the Colliders API), I think I understand what's going on for most of it, but some of the functions I have no clue what they do. For instance in starman.onTick there's something called NPC.getIntersecting. Is that for when mario picks up the star?
Another thing I tried to figure out last night is how to make Mario's fireballs shoot correctly (have only two on-screen at a time, with no timer in-between firing, and a change to their x-speed). But when I first tried it I didn't know what function or API I could use to count the fireballs in Mario's current section. I tried NPC.get but it returned some hex values, and NPC.count, which I couldn't figure out. I don't know what arguments .count takes, if any.
EDIT: Alright, I figured out the fireballs, but they persist while offscreen. I figure, I'll just find the screen coordinates and kill the npcs when they're about 4 blocks out, but I don't know how player.screen works. Its a RECT type and I went to look it up. Seems like its a function that returns the four boundary values? But whenever I try to use it I get "==> no such operator defined". Do I have to define a new RECT using player.screen? I'm clueless.
Re: LunaLua Help
Okay! I finally figured all that fireball jazz out. It works in the level just fine. So I tried to put it into it's own API, but then I get this error:
I went to mainV2.lua to check it out, but it looks as though its just defining the events for each API. I think it may be that I have to return some data from the API to the host level file but I don't know what needs to be returned.
Code:
I went to mainV2.lua to check it out, but it looks as though its just defining the events for each API. I think it may be that I have to return some data from the API to the host level file but I don't know what needs to be returned.
Code:
Code: Select all
local properFireballs = {}
function properFireballs.onTick()
local fireballs = NPC.get(13,player.section);
local iceballs = NPC.get(265,player.section);
local hammers = NPC.get(171,player.section);
for _, v in pairs(fireballs) do
local offscreen = v:mem(0x128,FIELD_WORD)
if offscreen == -1 then
v:mem(0x12A,FIELD_WORD,0) --If shots are offscreen, set despawn to instant
end
if v.direction > 0 then
v.speedX = 8
else if v.direction < 0 then
v.speedX = -8
end
end
if fireballs[2] == nil then --Checks if second index is filled for player section
player:mem(0x160,FIELD_WORD,0)
else
player:mem(0x160,FIELD_WORD,1)
end
end
for _, v in pairs(iceballs) do
local offscreen = v:mem(0x128,FIELD_WORD)
if offscreen == -1 then
v:mem(0x12A,FIELD_WORD,0)
end
if v.direction > 0 then
v.speedX = 5.6
else if v.direction < 0 then
v.speedX = -5.6
end
end
if iceballs[2] == nil then
player:mem(0x160,FIELD_WORD,0)
else
player:mem(0x160,FIELD_WORD,1)
end
end
for _, v in pairs(hammers) do
local offscreen = v:mem(0x128,FIELD_WORD)
if offscreen == -1 then
v:mem(0x12A,FIELD_WORD,0)
end
if hammers[2] == nil then
player:mem(0x160,FIELD_WORD,0)
else
player:mem(0x160,FIELD_WORD,1)
end
end
end
function properFireballs.onInitAPI()
registerEvent(properFirealls,"onTick","onTick")
end
return properFireballs;
Re: LunaLua Help
Isrieri wrote:registerEvent(properFirealls,"onTick","onTick")
Isrieri wrote:properFirealls
Isrieri wrote:Firealls
Be sure to check your spellingIsrieri wrote:alls
Re: LunaLua Help
Oh my god, that was actually it. I'm so pissed at myself.
Thank you, Hoeloe! Now I know what to do if that error shows up again.
Thank you, Hoeloe! Now I know what to do if that error shows up again.
-
- Posts: 4
- Joined: 7 years ago
- Location: USA
Re: LunaLua Help
CinematX is very old and broken and never quite worked properly. It's really not recommended to even try using it.KittyTristy wrote:No matter what I do, I can't get cinematX to work. I've followed the wiki and examples I've seen, and it just doesn't work at all. :/
Does anyone have any levels using cinematX that are working with SMBX 2.0 that I could take a look at?
-
- Posts: 4
- Joined: 7 years ago
- Location: USA
Re: LunaLua Help
KittyTristy wrote: Ah. Well it was included with SMBX 2.0 and it's on the wiki so it didn't really seem like that way when I was looking around about it. Oh well. Thanks anyways. :3
It's been kept in for compatibility, but really you shouldn't be using it. There are some tools to do what it does in separate forms. The event scheduling is now part of eventu.lua, there's a simple "follower" script used by Bowser to replicate follower behaviour, pnpc.lua deals with keeping track of and modifying NPCs, and textblox.lua can deal with extra text printing (though that one is undergoing renovation at the moment). There's also imagic.lua, which can be used for drawing things like text boxes and speech bubbles should you want to.
-
- Posts: 4
- Joined: 7 years ago
- Location: USA
-
- Posts: 4
- Joined: 7 years ago
- Location: USA
- Camwood777
- oh man what
- Posts: 14
- Joined: 7 years ago
- First name: Cam
- Pronouns: he/him/his
- Location: the land of tong-nou
Re: LunaLua Help
For whatever reason, I can't get midpoints to work at all. I tried looking it up on the wiki, and it tells me to use multipoints.lua, so I guess it's a Lunalua thing.
At the same time, though, that raises more issues; Lunalua won't even open for me! It tells me to select a program... Can someone help me out here?
At the same time, though, that raises more issues; Lunalua won't even open for me! It tells me to select a program... Can someone help me out here?
also goes by "camwoodstock", "camwood", "cws", or some variant thereof
plays video games i think
plays video games i think
- ztarwuff
- What the heck is a flair and why am I being asked to write one for my profile?
- Posts: 553
- Joined: 11 years ago
- Location: Not a great mental space TBH.
Re: LunaLua Help
Oh midpoints! Yes, midpoints are very easy.Camwood777 wrote:For whatever reason, I can't get midpoints to work at all. I tried looking it up on the wiki, and it tells me to use multipoints.lua, so I guess it's a Lunalua thing.
At the same time, though, that raises more issues; Lunalua won't even open for me! It tells me to select a program... Can someone help me out here?
The .lua files are basically just text documents. The notepad program that comes bundled with Windows can open them, but it's probably a better idea to get a free version of Notepad++. Notepad++ colour codes your lua code as you go along.
You'll need to create a .lua file called lunadll.lua in your level folder. Notepad doesn't give you the option, so you have to select all files, then type in lunadll.lua. NotePad++ however, does give you the option of saving as a .lua.
Here's a sample from one of my levels submitted to A2XT Episode 2:
Code: Select all
local multipoints = loadAPI("multipoints");
multipoints.addLuaCheckpoint(-19809, -20064, 9);
multipoints.addLuaCheckpoint(-199296, -200063, 0);
So in the above example, I have a midpoint in Section 10 and Section 1.
Re: LunaLua Help
But of an odd question. Is there a way to draw something behind the player without putting it on their sprite sheet? Basically I'd like to imitate how the cape animates in SMW on a custom character, so it can animate independently and be drawn regardless of powerup state.
Re: LunaLua Help
Absolutely! Take a look at the render priority system: http://wohlsoft.ru/pgewiki/LunaLua_Render_Priority
Certain functions in LunaLua allow you to supply a priority. Most priority levels are negative, and if you use a priority below the player (that's more negative than -25) when drawing with Lua, you can draw things behind the player.
Re: LunaLua Help
I want to make a level where things generate at random. There will be a total of 10 random screens generated horizontally before the flagpole and all pipes generated lead to a normal underground bonus section. When they come back up, the flagpole is there immediately.
Re: LunaLua Help
I've re-skinned Ludwig and would like to have him throw hammers instead of fireballs. I feel like a total dope, not knowing this when it seems basic.
A very shy ghost.
Re: LunaLua Help
Is it possible to check if the player/game is in a frozen state from powering down? I'm manipulating layers with LunaLua using an in-code timer, but if the player takes damage, the layers stop but the timer keeps running, massively desynching things. I need to make the timer stop if the player's unable to take action, but I'm struggling to find out how to do this through the wiki
Re: LunaLua Help
Ah! I managed to miss that. Thank you, Hoeloe!
- LunarNeedle
- The Golden Spork
- Posts: 51
- Joined: 11 years ago
- First name: Matthew
- Location: Canada, Canada
Re: LunaLua Help
This might be really dumb, but what are some ways a player can cause a change in a Lua variable (preferably boolean) through the players own actions like killing an NPC, hitting a block, standing on a certain block, a SMBX event, or anything. The best I have is to count the plunger NPC every frame and when the count goes down, trigger the change in the variable; which is less than ideal considering the wiki suggests making variables off of NPC.count() local only or there will be problems.
Never thought this would be the problem, but it might be coming from my inexperience with PGE and the engine overall.
Never thought this would be the problem, but it might be coming from my inexperience with PGE and the engine overall.
"All these flavors and you choose to be salty"
- Grandma
- Grandma
- Emral
- Posts: 941
- Joined: 10 years ago
- https://enjl.talkhaus.com/
Re: LunaLua Help
https://wohlsoft.ru/pgewiki/LunaLua_events
Check out some of these. They get triggered on certain conditions. onNPCKill and onEvent are particularly interesting. "eventObj" (the first argument) in onNPCKill refers to the event of the NPC dying, not the SMBX event it might invoke.
There's also onMessageBox and onBlockHit(eventObj, hitBlock, fromUpper?, playerOrNil), and onNPCHarm(eventObj, killedNPC, killReason, culpritOrNil) which trigger when their name suggests.
For standing on a particular block it's best to do a player:isGroundTouching() check and, if that passes, check if there's the desired block below the player using a for loop over Block.getIntersecting(left, top, right, bottom)
Check out some of these. They get triggered on certain conditions. onNPCKill and onEvent are particularly interesting. "eventObj" (the first argument) in onNPCKill refers to the event of the NPC dying, not the SMBX event it might invoke.
There's also onMessageBox and onBlockHit(eventObj, hitBlock, fromUpper?, playerOrNil), and onNPCHarm(eventObj, killedNPC, killReason, culpritOrNil) which trigger when their name suggests.
For standing on a particular block it's best to do a player:isGroundTouching() check and, if that passes, check if there's the desired block below the player using a for loop over Block.getIntersecting(left, top, right, bottom)
I do things. You can find them on my talkhaus site. https://enjl.talkhaus.com/
Here is another link. This one lets you draw.
https://enjl.talkhaus.com/draw.html
Here is another link. This one lets you draw.
https://enjl.talkhaus.com/draw.html
Re: LunaLua Help
I'm assuming this is possible, but I can't figure out how... How do I get the angle between two points? As far as I can tell, Lua doesn't have atan2. Is it through the VectR library? Will the dot product of two vector2 vectors produce the direction I seek, or am I barking up the wrong tree? For full context: I'm wanting to make a function that will check if a player is within a specific range of an NPC, but the checks get blocked by solid tiles. ...come to think of it, just finding the angle alone wouldn't be enough- I'd still need sine and cosine functions, too, to get X and Y positions out of the degree/radian... Hrm. Maybe right now this sort of thing isn't possible in SMBX2?
Re: LunaLua Help
Ah, thanks. I thought that the math API wasn't built-in, but I guess I was wrong! Now I'm trying to debug this code and figure out why it's not giving me the right angle :/
Code: Select all
local ang = math.atan2(player.x-ax, player.y-ay);
NPC.spawn(137, player.x + (96 * math.cos(ang)), player.y + (96 * math.sin(ang)), 7);
Re: LunaLua Help
You might find this easier to do with vectors.
From what it looks like, you're trying to spawn an NPC part way between the player and some other object, right?
Doing this with vectors is pretty simple:
Is the basic gist.
From what it looks like, you're trying to spawn an NPC part way between the player and some other object, right?
Doing this with vectors is pretty simple:
Code: Select all
local direction = vector(player.x-ax, player.y-ay):normalize()
NPC.spawn(id, player.x + dist*direction.x, player.y + dist*direction.y, player.section)