Page 30 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Sat Jul 16, 2016 1:04 pm
by Quantix
Spinda wrote:Do you mean sprites you draw with Lua or built-in graphics like NPCs?
Oh I meant regular custom graphics.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Jul 16, 2016 1:17 pm
by PixelPest
Quantix wrote:
Spinda wrote:Do you mean sprites you draw with Lua or built-in graphics like NPCs?
Oh I meant regular custom graphics.
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:

Code: Select all

local transparent = Graphics.loadImage("transparent.png");

function onStart()
   Graphics.sprites.npc[1] = transparent;
end 
To undo this, do:

Code: Select all

 Graphics.sprites.npc[1] = nil; 
I haven't tried it, but you could probably pass a table of NPC IDs through the function by doing:

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 

Re: Need help with lua? - LunaLua General Help

Posted: Sat Jul 16, 2016 1:31 pm
by MECHDRAGON777
Yoshi021 wrote:

Code: Select all

function onKeyUp()
    Counter = Counter + 1
end
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 onInputUpdate(KEY_SPINJUMP)
    if player.altJumpKeyPressing then
        Counter = Counter + 1
    end
end

Re: Need help with lua? - LunaLua General Help

Posted: Sat Jul 16, 2016 1:37 pm
by Yoshi021
MECHDRAGON777 wrote:
Yoshi021 wrote:

Code: Select all

function onKeyUp()
    Counter = Counter + 1
end
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 onInputUpdate(KEY_SPINJUMP)
    if player.altJumpKeyPressing then
        Counter = Counter + 1
    end
end
Thanks

Re: Need help with lua? - LunaLua General Help

Posted: Sat Jul 16, 2016 1:44 pm
by PixelPest
Yoshi021 wrote:
MECHDRAGON777 wrote:
Yoshi021 wrote:

Code: Select all

function onKeyUp()
    Counter = Counter + 1
end
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 onInputUpdate(KEY_SPINJUMP)
    if player.altJumpKeyPressing then
        Counter = Counter + 1
    end
end
Thanks
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 answer

Re: Need help with lua? - LunaLua General Help

Posted: Sat Jul 16, 2016 1:47 pm
by Emral
MECHDRAGON777 wrote:
Yoshi021 wrote:

Code: Select all

function onKeyUp()
    Counter = Counter + 1
end
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 onInputUpdate(KEY_SPINJUMP)
    if player.altJumpKeyPressing then
        Counter = Counter + 1
    end
end
No.
Few problems.
1) you don't pass any variables to onInputUpdate. KEY_SPINJUMP in this code will ALWAYS be nil.
2) This script will trigger every time the player will press ANY button while the spinjump button is held.

If you wanna check for the frame a key is pressed I suggest loading the inputs2 api:

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
http://wohlsoft.ru/pgewiki/Inputs2.lua

Re: Need help with lua? - LunaLua General Help

Posted: Sat Jul 16, 2016 4:01 pm
by Yoshi021

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
Somehow this managed to work. I don't know if the inputs2.lua better, but this seems to get the work done.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Jul 16, 2016 4:21 pm
by PixelPest
Yoshi021 wrote:

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
Somehow this managed to work. I don't know if the inputs2.lua better, but this seems to get the work done.
Use inputs2.lua

Re: Need help with lua? - LunaLua General Help

Posted: Mon Jul 18, 2016 8:41 pm
by Yoshi021
How can I trigger an event once when the player gets hurt?

Re: Need help with lua? - LunaLua General Help

Posted: Mon Jul 18, 2016 9:15 pm
by PixelPest
Yoshi021 wrote:How can I trigger an event once when the player gets hurt?
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 for

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jul 19, 2016 10:32 am
by TheWarpyro
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?

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jul 19, 2016 10:50 am
by Reign
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?

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jul 19, 2016 10:54 am
by Emral
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?
Yes.
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?
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.

Also use onTick instead of onLoop :V

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jul 19, 2016 10:57 am
by TheWarpyro
All of them?
(Mind talking about this via PMs?)

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jul 19, 2016 11:04 am
by Emral
yes all of them

Re: Need help with lua? - LunaLua General Help

Posted: Wed Jul 20, 2016 1:21 am
by MECHDRAGON777
Is it possible to freeze time with a lua code on the press of a button?

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
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.

Re: Need help with lua? - LunaLua General Help

Posted: Wed Jul 20, 2016 8:44 am
by Yoshi021
MECHDRAGON777 wrote:Is it possible to freeze time with a lua code on the press of a button?

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
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.
This will work:

Code: Select all

Defines.levelFreeze = true

Re: Need help with lua? - LunaLua General Help

Posted: Wed Jul 20, 2016 8:50 am
by MECHDRAGON777
Yoshi021 wrote:
MECHDRAGON777 wrote:Is it possible to freeze time with a lua code on the press of a button?

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
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.
This will work:

Code: Select all

Defines.levelFreeze = true
Thanks, now I just got to hope that

Code: Select all

if Graphics.activateHud == false then
    Graphics.activateHud
end
is the correct thing as well as the opposite of it.

Re: Need help with lua? - LunaLua General Help

Posted: Wed Jul 20, 2016 3:42 pm
by PixelPest
MECHDRAGON777 wrote:
Yoshi021 wrote:
MECHDRAGON777 wrote:Is it possible to freeze time with a lua code on the press of a button?

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
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.
This will work:

Code: Select all

Defines.levelFreeze = true
Thanks, now I just got to hope that

Code: Select all

if Graphics.activateHud == false then
    Graphics.activateHud
end
is the correct thing as well as the opposite of it.
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 activated

Re: Need help with lua? - LunaLua General Help

Posted: Fri Jul 22, 2016 6:38 am
by Mario_and_Luigi_55
Is there a way to make LunaLua count seconds?