Re: Need help with lua? - LunaLua General Help
Posted: Sat Jul 16, 2016 1:04 pm
Oh I meant regular custom graphics.Spinda wrote:Do you mean sprites you draw with Lua or built-in graphics like NPCs?
Forums for SMBX
https://www.smbxgame.com/forums/
Oh I meant regular custom graphics.Spinda wrote:Do you mean sprites you draw with Lua or built-in graphics like NPCs?
I think the best way to do it would be to use the Sprite Override class. You would start by loading an image of a fully transparent graphics file of the correct size and then use the Graphics.sprites function to override whatever graphic(s) you want. For example, if you wanted to make npc-1 transparent using a graphics file named "transparent", you would do:Quantix wrote:Oh I meant regular custom graphics.Spinda wrote:Do you mean sprites you draw with Lua or built-in graphics like NPCs?
Code: Select all
local transparent = Graphics.loadImage("transparent.png");
function onStart()
Graphics.sprites.npc[1] = transparent;
end
Code: Select all
Graphics.sprites.npc[1] = nil;
Code: Select all
local transparent = Graphics.loadImage("transparent.png");
local spriteIDs = {1, 6, 29, 46, 48};
function onStart()
for i = 1, 5 do
Graphics.sprites.npc[i] = transparent;
end
end
Yoshi021 wrote:I want to trigger an event, every time I press the "Spin Jump" button, but this script triggers the event everytime I press any button. How do I fix this?Code: Select all
function onKeyUp() Counter = Counter + 1 end
Code: Select all
function onInputUpdate(KEY_SPINJUMP)
if player.altJumpKeyPressing then
Counter = Counter + 1
end
end
ThanksMECHDRAGON777 wrote:Yoshi021 wrote:I want to trigger an event, every time I press the "Spin Jump" button, but this script triggers the event everytime I press any button. How do I fix this?Code: Select all
function onKeyUp() Counter = Counter + 1 end
Code: Select all
function onInputUpdate(KEY_SPINJUMP) if player.altJumpKeyPressing then Counter = Counter + 1 end end
That's actually wrong in a sense though. You shouldn't be putting KEY_SPINJUMP in the onInputUpdate event's brackets. It's like typing into a calculator 2+2 to find that it equals four and then typing the same thing into another answer to find out again that you get the same answerYoshi021 wrote:ThanksMECHDRAGON777 wrote:Yoshi021 wrote:I want to trigger an event, every time I press the "Spin Jump" button, but this script triggers the event everytime I press any button. How do I fix this?Code: Select all
function onKeyUp() Counter = Counter + 1 end
Code: Select all
function onInputUpdate(KEY_SPINJUMP) if player.altJumpKeyPressing then Counter = Counter + 1 end end
No.MECHDRAGON777 wrote:Yoshi021 wrote:I want to trigger an event, every time I press the "Spin Jump" button, but this script triggers the event everytime I press any button. How do I fix this?Code: Select all
function onKeyUp() Counter = Counter + 1 end
Code: Select all
function onInputUpdate(KEY_SPINJUMP) if player.altJumpKeyPressing then Counter = Counter + 1 end end
Code: Select all
local inputs2 = API.load("inputs2")
local Counter = 0
function onTick()
if inputs2.state[1].altjump == inputs.PRESS then --if player 1 pressed altjump this frame
Counter = Counter + 1
end
end
Code: Select all
function onKeyDown(value)
if value == KEY_SPINJUMP then
CharacterState = CharacterState - 1
end
end
function onTick()
player:mem(0x120,FIELD_WORD,1)
end
Use inputs2.luaYoshi021 wrote:Somehow this managed to work. I don't know if the inputs2.lua better, but this seems to get the work done.Code: Select all
function onKeyDown(value) if value == KEY_SPINJUMP then CharacterState = CharacterState - 1 end end function onTick() player:mem(0x120,FIELD_WORD,1) end
Use the Event class and a condition involving the Player memory regarding player state. I think 2 is powering down which is what you'll want to check forYoshi021 wrote:How can I trigger an event once when the player gets hurt?
Yes.TheWarpyro wrote:Hey, after i download the vanilla+launcher version of Lunalua (v 0.7.3 Beta), do i place it on the smbx folder with the other smbx files?
v.ai1 for boos overrides your changes because it's set by smbx around where speedX and speedY are set. The boo ai is pretty simple to recreate though so just creating a lua object or replacing a goomba shouldn't be too much of an issue.Reign wrote:I guess my idea for a boo that always follows you isn't really working like this?
function onLoop()
for k,v in pairs(NPC.get(38,player.section)) do
v:mem(0xF0,FIELD_DFLOAT,1)
end
end
Is it even possible to manipulate this AI value?
Code: Select all
local menu = 0
local mapNil = Graphics.loadImage("Map Tiles/Empty Map.png")
local mapUnexplored = Graphics.loadImage("Map Tiles/Unexplored Map.png")
function onKeyUpdate()
if menu = 0 then
if Player.pauseKeyPressing then
Player.pauseKeyPressing = false
<HELP (FREEZE ALL ACTIONS)>
menu = 1
end
elseif menu = 1 then
if Player.pauseKeyPressing then
Player.pauseKeyPressing = false
<HELP (UNFREEZE ALL ACTIONS)>
menu = 0
end
end
end
function onTick()
onMap()
if menu == 1 then
onMenuA()
elseif menu == 0 then
onMenuB()
end
end
function onMenuA()
if Graphics.activateHud then
Graphics.activateHud = false
end
if mapData:get("Map Collected") == 0 then
Graphics.drawImageWP(mapNil, 0, 0, 3)
elseif mapData:get("Map Collected") == 1 then
Graphics.drawImageWP(mapUnexplored, 0, 0, 3)
end
end
function onMenuB()
if Graphics.activateHud == false then
Graphics.activateHud
end
end
This will work:MECHDRAGON777 wrote:Is it possible to freeze time with a lua code on the press of a button?
I know you can lock controls, I even know how to do it. I just want to know how to make the game act like it is paused while the menu is up. (It is quite obvious it is a map from when you look at the code.) My thing is just trying to get the game to freeze all actions like the game was paused, and show the image instead of the pause screen. I think I messed up the function to hide the HUD during that time, but freezing all actions, that is what I am confused on how to do.Code: Select all
local menu = 0 local mapNil = Graphics.loadImage("Map Tiles/Empty Map.png") local mapUnexplored = Graphics.loadImage("Map Tiles/Unexplored Map.png") function onKeyUpdate() if menu = 0 then if Player.pauseKeyPressing then Player.pauseKeyPressing = false <HELP (FREEZE ALL ACTIONS)> menu = 1 end elseif menu = 1 then if Player.pauseKeyPressing then Player.pauseKeyPressing = false <HELP (UNFREEZE ALL ACTIONS)> menu = 0 end end end function onTick() onMap() if menu == 1 then onMenuA() elseif menu == 0 then onMenuB() end end function onMenuA() if Graphics.activateHud then Graphics.activateHud = false end if mapData:get("Map Collected") == 0 then Graphics.drawImageWP(mapNil, 0, 0, 3) elseif mapData:get("Map Collected") == 1 then Graphics.drawImageWP(mapUnexplored, 0, 0, 3) end end function onMenuB() if Graphics.activateHud == false then Graphics.activateHud end end
Code: Select all
Defines.levelFreeze = true
Thanks, now I just got to hope thatYoshi021 wrote:This will work:MECHDRAGON777 wrote:Is it possible to freeze time with a lua code on the press of a button?
I know you can lock controls, I even know how to do it. I just want to know how to make the game act like it is paused while the menu is up. (It is quite obvious it is a map from when you look at the code.) My thing is just trying to get the game to freeze all actions like the game was paused, and show the image instead of the pause screen. I think I messed up the function to hide the HUD during that time, but freezing all actions, that is what I am confused on how to do.Code: Select all
local menu = 0 local mapNil = Graphics.loadImage("Map Tiles/Empty Map.png") local mapUnexplored = Graphics.loadImage("Map Tiles/Unexplored Map.png") function onKeyUpdate() if menu = 0 then if Player.pauseKeyPressing then Player.pauseKeyPressing = false <HELP (FREEZE ALL ACTIONS)> menu = 1 end elseif menu = 1 then if Player.pauseKeyPressing then Player.pauseKeyPressing = false <HELP (UNFREEZE ALL ACTIONS)> menu = 0 end end end function onTick() onMap() if menu == 1 then onMenuA() elseif menu == 0 then onMenuB() end end function onMenuA() if Graphics.activateHud then Graphics.activateHud = false end if mapData:get("Map Collected") == 0 then Graphics.drawImageWP(mapNil, 0, 0, 3) elseif mapData:get("Map Collected") == 1 then Graphics.drawImageWP(mapUnexplored, 0, 0, 3) end end function onMenuB() if Graphics.activateHud == false then Graphics.activateHud end end
Code: Select all
Defines.levelFreeze = true
Code: Select all
if Graphics.activateHud == false then
Graphics.activateHud
end
Graphics.activateHud() is a function to activate the HUD using an argument with a boolean value, Graphics.isHudActivated() returns whether or not the HUD is activatedMECHDRAGON777 wrote:Thanks, now I just got to hope thatYoshi021 wrote:This will work:MECHDRAGON777 wrote:Is it possible to freeze time with a lua code on the press of a button?
I know you can lock controls, I even know how to do it. I just want to know how to make the game act like it is paused while the menu is up. (It is quite obvious it is a map from when you look at the code.) My thing is just trying to get the game to freeze all actions like the game was paused, and show the image instead of the pause screen. I think I messed up the function to hide the HUD during that time, but freezing all actions, that is what I am confused on how to do.Code: Select all
local menu = 0 local mapNil = Graphics.loadImage("Map Tiles/Empty Map.png") local mapUnexplored = Graphics.loadImage("Map Tiles/Unexplored Map.png") function onKeyUpdate() if menu = 0 then if Player.pauseKeyPressing then Player.pauseKeyPressing = false <HELP (FREEZE ALL ACTIONS)> menu = 1 end elseif menu = 1 then if Player.pauseKeyPressing then Player.pauseKeyPressing = false <HELP (UNFREEZE ALL ACTIONS)> menu = 0 end end end function onTick() onMap() if menu == 1 then onMenuA() elseif menu == 0 then onMenuB() end end function onMenuA() if Graphics.activateHud then Graphics.activateHud = false end if mapData:get("Map Collected") == 0 then Graphics.drawImageWP(mapNil, 0, 0, 3) elseif mapData:get("Map Collected") == 1 then Graphics.drawImageWP(mapUnexplored, 0, 0, 3) end end function onMenuB() if Graphics.activateHud == false then Graphics.activateHud end end
Code: Select all
Defines.levelFreeze = true
is the correct thing as well as the opposite of it.Code: Select all
if Graphics.activateHud == false then Graphics.activateHud end