Page 37 of 47
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 12:10 pm
by PixelPest
PixelPest wrote:Spinda wrote:Code: Select all
for _,v in pairs(NPC.Get(NPCID,player.section) do
if Blocks.getIntersecting(v.x - 1,v.y - 1,v.x + v.width + 1,v.y + v.height + 1) ~= {} then
v:kill()
end
end
Thanks Spinda.
Except now it doesn't work:
Code: Select all
function onLoop()
for _,v in pairs(NPC.Get(229,player.section) do
if Blocks.getIntersecting(v.x - 1,v.y - 1,v.x + v.width + 1,v.y + v.height + 1) ~= {} then
v:kill()
end
end
end
It keeps on saying ')' expected after 'do' (on line 2).
EDIT:
Enjl wrote:There's also NPC.collidesBlock(Bottom/Left/Top/Right), which are boolean values for each direction.
If you wanna kill NPCs at the ceiling you can check for
if NPC.collidesBlockTop then
v:kill()
end
Thanks Enjl, but the NPCs actually spawn from the ceiling using Lua so I don't think this would work. Might be useful in the future though.
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 12:15 pm
by Emral
PixelPest wrote:PixelPest wrote:Spinda wrote:Code: Select all
for _,v in pairs(NPC.Get(NPCID,player.section) do
if Blocks.getIntersecting(v.x - 1,v.y - 1,v.x + v.width + 1,v.y + v.height + 1) ~= {} then
v:kill()
end
end
Thanks Spinda.
Except now it doesn't work:
Code: Select all
function onLoop()
for _,v in pairs(NPC.Get(229,player.section) do
if Blocks.getIntersecting(v.x - 1,v.y - 1,v.x + v.width + 1,v.y + v.height + 1) ~= {} then
v:kill()
end
end
end
It keeps on saying ')' expected after 'do' (on line 2).
It says "near" do. Which means that it's missing a ")" BEFORE the "do".
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 12:19 pm
by PixelPest
Thanks Enjl. Didn't notice that.
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 12:20 pm
by lotus006
yay I found the Left Click Offsets for the mouse
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 12:28 pm
by PixelPest
==> no static 'Get' in class 'NPC'
==============
stack traceback:
[string "mainV2.lua"]:164:in function <[string "mainV2.lua"]:162>
[C]: in function '__index'
...\Daniel\SMBX\<name of CC level>\<name of CC level\lunadll.lua:2: in function <...\Daniel\SMBX\<name of CC level>\<name of CC level>\lunadll.lua:1>
[C]: in function '__xpcall'
[string "mainV2.lua"]:582: in function <[string "mainV2.lua"]:535>
This is the error the script Spinda provided me above is giving me now even after adding the bracket.
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 12:31 pm
by underFlo
yeah it's NPC.get sorry for that
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 12:58 pm
by PixelPest
Spinda wrote:yeah it's NPC.get sorry for that
And now it's saying that it's trying to index 'Blocks', a nil value.
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 1:20 pm
by underFlo
it's Block.getInteresecting
man i'm really dumb today
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 1:26 pm
by PixelPest
Spinda wrote:it's Block.getInteresecting
man i'm really dumb today
Okay. It's not giving me an error anymore, however it isn't working either. The NPCs spawn randomly at the top of the screen like they are supposed to however they are killed instantly.
Might as well just post the whole script:
Code: Select all
local spawnchance = {}
local xvalue = {}
local recent = {0}
local recent2 = {0}
local recent3 = {0}
local recent4 = {0}
local recent5 = {0}
local recent6 = {0}
local recent7 = {0}
local recent8 = {0}
local recent9 = {0}
local recent10 = {0}
function onLoop()
for _,v in pairs(NPC.get(229,player.section)) do
if Block.getIntersecting(v.x - 1,v.y - 1,v.x + v.width + 1,v.y + v.height + 1) ~= {} then
v:kill()
end
end
spawnchance = math.random(1, 35)
if recent ~= 0 then
if recent == xvalue then
spawnchance = 1
recent = xvalue
if recent10 ~= 0 then
recent10 = 0
end
end
end
if recent2 ~= 0 then
if recent2 == xvalue then
spawnchance = 1
recent2 = xvalue
if recent1 ~= 0 then
recent1 = 0
end
end
end
if recent3 ~= 0 then
if recent3 == xvalue then
spawnchance = 1
recent3 = xvalue
if recent2 ~= 0 then
recent2 = 0
end
end
end
if recent4 ~= 0 then
if recent4 == xvalue then
spawnchance = 1
recent4 = xvalue
if recent3 ~= 0 then
recent3 = 0
end
end
end
if recent5 ~= 0 then
if recent5 == xvalue then
spawnchance = 1
recent5 = xvalue
if recent4 ~= 0 then
recent4 = 0
end
end
end
if recent6 ~= 0 then
if recent6 == xvalue then
spawnchance = 1
recent6 = xvalue
if recent5 ~= 0 then
recent5 = 0
end
end
end
if recent7 ~= 0 then
if recent7 == xvalue then
spawnchance = 1
recent7 = xvalue
if recent6 ~= 0 then
recent6 = 0
end
end
end
if recent8 ~= 0 then
if recent8 == xvalue then
spawnchance = 1
recent8 = xvalue
if recent7 ~= 0 then
recent7 = 0
end
end
end
if recent9 ~= 0 then
if recent9 == xvalue then
spawnchance = 1
recent9 = xvalue
if recent8 ~= 0 then
recent8 = 0
end
end
end
if recent10 ~= 0 then
if recent10 == xvalue then
spawnchance = 1
recent10 = xvalue
if recent9 ~= 0 then
recent9 = 0
end
end
end
if spawnchance == 35 then
xvalue = math.random(-6250, -6170)*32
NPC.spawn(229, xvalue, -200608, 0)
end
end
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 3:33 pm
by Kevsoft
try:
Code: Select all
if #Block.getIntersecting(v.x - 1,v.y - 1,v.x + v.width + 1,v.y + v.height + 1) > 0 then
v:kill()
end
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 3:43 pm
by underFlo
oh right you can do that
man i'm really dumb today
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 3:50 pm
by PixelPest
Kevsoft wrote:try:
Code: Select all
if #Block.getIntersecting(v.x - 1,v.y - 1,v.x + v.width + 1,v.y + v.height + 1) > 0 then
v:kill()
end
Okay. That worked. Thank you.
One more thing: How can I remove the sound for the death of npc-229 without removing the death sound for all of the other NPCs in the level?
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 3:59 pm
by HenryRichard
Instead of kill() use kill(7) - if I recall correctly that kills it with no animation or sound (if you need the animation use Animation.spawn())
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 7:06 pm
by Nat The Porcupine
I'm having issues with loading a custom standing sprite in for Super Mario. Apparently SMBX 2.0 is having issues finding the "Player:getCurrentSpriteIndex()" function & possibly also having the same issue with the "Player:setCurrentSpriteIndex()" as well (I haven't bothered to test that last one on it's own yet, but I'm willing to guess that my prediction is correct). I have tried setting the memory values instead with unexpected results; there are no errors but the image index isn't actually set.
This is my code:
Code: Select all
local CurrentSprite = {}
local BigMario = false
loadHitboxes(1, 2, "mario-2.ini")
function onLoop()
CurrentSprite = Player:getCurrentSpriteIndex()
if Player.Character == CHARACTER_MARIO and Player.Powerup == PLAYER_BIG then
BigMario = true;
else
BigMario = false;
end
if BigMario == true then
if Player.Xspeed == 0 and Player.Yspeed == 0 and CurrentSprite(5,0) then
Player:setCurrentSpriteIndex(7,6,false);
end
if Player.Xspeed == 0 and Player.Yspeed == 0 and CurrentSprite(4,8) then
Player:setCurrentSpriteIndex(2,2,false);
end
end
end
And this is the resulting error message:
Code: Select all
==> no static 'getCurrentSpriteIndex' in class 'Player'
=============
stack traceback:
[string "mainV2.lua"]:164: in function <[string "mainV2.lua"]:162>
[C]: in function '_index'
C:\Users\Nathan\Desktop\SMBX 2.0\worlds\Test\lunadll.lua:8: in
function <C:\Users\Nathan\Desktop\SMBX 2.0\worlds\Test\lunadll.lua:6>
[C]: in function '_xpcall'
[string "mainV2.lua"]:582: in function <[string "mainV2.lua"]:535>
I am a programmer (sort of; I mainly do HTML5 & GameMaker's proprietary programming language), but I am totally stumped on this...
I'm actually not even sure if I'm checking for the current sprite correctly using that "CurrentSprite" variable I set up, so some insight on that may be helpful as well.
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 7:43 pm
by Hoeloe
Nat The Porcupine wrote:I'm having issues with loading a custom standing sprite in for Super Mario.
Capitalisation makes a difference.
is not the same thing as
The first of these looks for a variable called "Character" in the Player class, while the second looks for a variable called "character" (note the capitalisation) in the player
object.
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 8:10 pm
by Nat The Porcupine
Hoeloe wrote:Nat The Porcupine wrote:I'm having issues with loading a custom standing sprite in for Super Mario.
Capitalisation makes a difference.
is not the same thing as
The first of these looks for a variable called "Character" in the Player class, while the second looks for a variable called "character" (note the capitalisation) in the player
object.
Thank you. That certainly helped a lot. Now I'm having issues trying to actually checking for the current player sprite being used. How exactly am I supposed to properly check for something that returns 2 values? I can't even print the indexY value to the screen; only indexX value shows up.
EDIT: I resorted to using memory values partially. What I have found is that the 'setCurrentSpriteIndex' function doesn't work at all. It only changes the image index for a single frame after the left or right keys are pressed, making this function totally pointless. Looks like I'll have to find a creative workaround...
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 8:52 pm
by PixelPest
HenryRichard wrote:Instead of kill() use kill(7) - if I recall correctly that kills it with no animation or sound (if you need the animation use Animation.spawn())
Nope. That did absolutely nothing. Anyone else no how to get rid of the death effect sound for this NPC using this code?:
Code: Select all
function onLoop()
for _,v in pairs(NPC.get(229,player.section)) do
if #Block.getIntersecting(v.x,v.y,v.x + v.width,v.y + v.height) > 0 then
v:kill(7)
end
end
end
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 8:54 pm
by HenryRichard
You could try using sound overrides or teleporting the NPC offscreen.
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 8:59 pm
by PixelPest
HenryRichard wrote:You could try using sound overrides or teleporting the NPC offscreen.
What do you mean by sounds overrides? Could you give me an example?
Re: LunaLua Offical Thread - SMBX Usermod Framework
Posted: Sat Feb 13, 2016 9:02 pm
by HenryRichard
http://wohlsoft.ru/pgewiki/SoundOverride_(class)
It's probably better to teleport the NPC offscreen though.