Page 32 of 76
Re: Need help with lua? - LunaLua General Help
Posted: Mon Aug 08, 2016 7:39 am
by lotus006
Enchlore wrote:When trying to start SMBX with LunaLua I get this error message:
Here are my computer specs:
I tried to search the forums if anyone provided a solution but didn't find anything.
it's happening often to me, I forgot always to activate the peripherical sound, it's probably deactivated on your side, try first to plug headset to see if change !
Re: Need help with lua? - LunaLua General Help
Posted: Mon Aug 08, 2016 10:04 am
by Emral
there's probably leftover semicolons somewhere in smbx\sounds.ini
Re: Need help with lua? - LunaLua General Help
Posted: Thu Aug 18, 2016 2:50 pm
by DeMuZ
I was trying to write custom api code which would add hp system for player (do not read the code if you don't want to get cancer).
I wrote this code but it doesn't seem to work...
Code: Select all
--HP System (by DeMuZ)---
---------------------------------------
local demuz_hp_system = {}
local max_hp = 3
local hurt = 0
local mushrooms = NPC.get(9,-1)
local encrypt = loadSharedAPI("encrypt")
hpData = encrypt.Data(Data.DATA_WORLD,true)
---------------------------------------------------------------------------------
function demuz_hp_system.onInitAPI()
registerEvent(demuz_hp_system,"onStart","onStart")
registerEvent(demuz_hp_system,"onTick","showHP")
end
function demuz_hp_system.setAmmount(value)
if value > 0 then
max_hp = value
end
end
function demuz_hp_system.onStart()
if hpData:get("hp") == nil or hpData:get("hp") == 0 then
hpData:set("hp",1)
hpData:save()
end
end
function demuz_hp_system.showHP()
Text.print("HP:",0,16)
Text.print(hpData:get("hp"),64,16)
if player:mem(0x13E, FIELD_WORD) > 0 and hurt == 0 then
hpData:set("hp",0)
hpData:save()
hurt = -1
end
if hurt == 0 then
if player:mem(0x122, FIELD_WORD) == 2 then
hpData:set("hp",hpData:get("hp")-1)
hpData:save()
hurt = 1
if player.powerup == PLAYER_SMALL and hpData:get("hp") > 1 then
player.powerup = PLAYER_BIG
end
end
???
end
if player:mem(0x122, FIELD_WORD) ~= 2 and hurt == 1 then
hurt = 0
end
end
return demuz_hp_system
I don't know how to make hpData rise while getting a mushroom if the player is already big.
Would anyone consider helping me?

Re: Need help with lua? - LunaLua General Help
Posted: Thu Aug 18, 2016 4:09 pm
by Hoeloe
DeMuZ wrote:I was trying to write custom api code which would add hp system for player (do not read the code if you don't want to get cancer).
I don't know how to make hpData rise while getting a mushroom if the player is already big.
Would anyone consider helping me?

I would suggest taking a look at
HUD of Time, it's a library that adds extra health and rerenders the HUD of certain characters.
Re: Need help with lua? - LunaLua General Help
Posted: Thu Aug 18, 2016 4:39 pm
by DeMuZ
Hoeloe wrote:I would suggest taking a look at
HUD of Time, it's a library that adds extra health and rerenders the HUD of certain characters.
I would like to make a hp system for Mario/Luigi and HUDofTime.lua seems to work only with Link.
If I can't create that with HUDofTime.lua, the only thing I need is to make "trigger lua code by getting a mushroom even if the player is big"

Re: Need help with lua? - LunaLua General Help
Posted: Thu Aug 18, 2016 4:45 pm
by PixelPest
Yes, but take a look at what it does and see if you can apply it to what you're trying to do
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 19, 2016 12:19 pm
by DeMuZ
PixelPest wrote:Yes, but take a look at what it does and see if you can apply it to what you're trying to do
HUDofTime.lua uses SMBX hearth system to check if it should increase or decrease the ammount of player's hp variable, so it's only possible to use this code for Toad, Peach and Link.
I would like to apply hp variable system to Mario/Luigi, too. :/
EDIT: I think i can make it with onNPCKill() function but I don't know how to use it. I always get this error:
http://imgur.com/kXghMtE
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 19, 2016 12:57 pm
by Kevsoft
Can you post the code (or the code snippet) at line 38?
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 19, 2016 12:59 pm
by DeMuZ
Kevsoft wrote:Can you post the code (or the code snippet) at line 38?
Code: Select all
function demuz_hp_system.onNPCKill(<i don't know what to put here>,NPC.get(9,-1),9)
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 19, 2016 1:26 pm
by Kevsoft
Yea... classical misunderstanding. So the thing is that events will pass you already defined values. You have to name those arguments a specific names.
So
Code: Select all
function someAPI.onNPCKill(eventObj, npcObj, npcKillReason)
if npcObj.id == 9 and npcKillReason == 9 then
<do your stuff here>
end
end
is the correct code.
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 19, 2016 1:53 pm
by DeMuZ
Thank you for help!
EDIT: Why is this code not working? Player falls under the screen when he gets hit.
Code: Select all
function demuz_hp_system.showHP() --onTick
(...)
if hpData:get("hp") > 1 and player.powerup ~= PLAYER_BIG then
player.powerup = PLAYER_BIG
end
(...)
end
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 19, 2016 4:44 pm
by DeMuZ
DOUBLE POST
notice me (any) senpai :>
I wanna finish my episode before September.

Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 19, 2016 5:01 pm
by Yoshi021
Try having this offset activate whenever the player gets hurt.
player:mem(0x122,FIELD_WORD,12)
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 19, 2016 5:06 pm
by PixelPest
Yoshi021 wrote:Try having this offset activate whenever the player gets hurt.
player:mem(0x122,FIELD_WORD,12)
So what's your issue? You can check if player:mem(0x122, FIELD_WORD) == 2 (player is powering down) if that's what you're wondering, but I really don't know what exactly you're asking
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 19, 2016 5:07 pm
by Emral
DeMuZ wrote:Thank you for help! :)
EDIT: Why is this code not working? Player falls under the screen when he gets hit.
Code: Select all
function demuz_hp_system.showHP() --onTick
(...)
if hpData:get("hp") > 1 and player.powerup ~= PLAYER_BIG then
player.powerup = PLAYER_BIG
end
(...)
end
The player's hitbox changes because it loads the hitboxes for small mario. Since the hitbox's origin is at the top of the player, they get gradually pushed downward with each back-and-forth.
You need to offset the player by the difference and make sure to reset offset 0x122
http://wohlsoft.ru/pgewiki/SMBX_Player_Offsets
Yoshi021 wrote:Try having this offset activate whenever the player gets hurt.
player:mem(0x122,FIELD_WORD,12)
When the player gets hurt, 0x122 gets set to 2. Setting that state to 12 will NOT give the player a hammer suit, btw.
PixelPest wrote:Yoshi021 wrote:Try having this offset activate whenever the player gets hurt.
player:mem(0x122,FIELD_WORD,12)
So what's your issue? You can check if player:mem(0x114, FIELD_WORD) == 2 (player is powering down) if that's what you're wondering, but I really don't know what exactly you're asking
No. No. No. No. No. No. No. No. No. No. No.
0x114 is the displayed sprite index. Do NOT check for 0x114 in this scenario.
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 19, 2016 5:07 pm
by Valtteri
DeMuZ wrote:DOUBLE POST
Don't do this.
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 19, 2016 5:10 pm
by PixelPest
Oops. I meant 0x122. Just didn't have the documentation open and mixed them up
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 19, 2016 5:14 pm
by Yoshi021
Enjl wrote:
When the player gets hurt, 0x122 gets set to 2. Setting that state to 12 will NOT give the player a hammer suit, btw.
No, I used to have the same error that DeMuZ had where the player will move under blocks when you get hurt, but by having the Hammer Suit
effect happen when the player gets hurt fixes the error. My intention was never to give the player the hammer suit.
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 19, 2016 5:18 pm
by DeMuZ
Adding this code actually helped!
Thank you for helping me! Now, with more hp, Mario will be happy!

Re: Need help with lua? - LunaLua General Help
Posted: Wed Aug 24, 2016 6:26 pm
by Nessquik
Is CaptureBuffer no longer a function or something? I keep getting a nil value every time I try to call it:
The code is literally just:
local buf = Graphics.CaptureBuffer(800, 600)