How to make "One Hit Deadly" npc?
Posted: Mon Oct 04, 2021 1:02 pm
I know this will be a stupid question probably, But i'm really interested. How?
Forums for SMBX
https://www.smbxgame.com/forums/
Code: Select all
-- IDs 1 and 2 instakill. Edit the numbers in here to match the IDs you want. Separated by comma.
local INSTAKILLNPCS = {1, 2}
function onPostPlayerHarm(hurtPlayer)
for k,v in ipairs(Colliders.getColliding{a = hurtPlayer, b = INSTAKILLNPCS, btype=Colliders.NPC} do
hurtPlayer:kill()
end
end
sorry for not noticing this reply earlier, but i wanted to ask under which conditions would these misfires happen? according to the documentation, triggered events happen after onTick (and conversely, i assume this means they also execute after onTickNPC) which executes before SMBX's game logic, and i don't intuitively see what could (within that game logic) disturb the collision checking (as a collision check within the game's code surely has to be performed anyways for onPlayerHarm to trigger).
Ah, sorry, must've worded that badly. I just meant avoiding doing collision checks on frames where you're not sure there's anything to check for. Think running the getColliding once every couple seconds rather than once every frame.deice wrote: ↑Tue Oct 19, 2021 12:07 pmsorry for not noticing this reply earlier, but i wanted to ask under which conditions would these misfires happen? according to the documentation, triggered events happen after onTick (and conversely, i assume this means they also execute after onTickNPC) which executes before SMBX's game logic, and i don't intuitively see what could (within that game logic) disturb the collision checking (as a collision check within the game's code surely has to be performed anyways for onPlayerHarm to trigger).
i'd like this cleared up as it would be useful to know when making an NPC and because the documentation (both new and old) don't seem to cover nuances like this and i don't feel like sifting through a bulk of the 1.3 source code
oh, i see! thank you very much for clearing it up. looking at it logically, it is certainly faster to just let the game do it's thing rather than performing a potential myriad of unnecessary checks.
looking at enjl's code it seems he did indeed forget to put a parenthesis to close the ipairs() call.Someone wrote: ↑Thu Nov 25, 2021 7:35 amThanks for answer! although it seems there's a problem with the code. i tried to copy the code at the end of level Luna. And then into world luna, but every time there's the same error... " ')' expected near 'do' ".. does somebody know how to remove that error? should i copy the code somewhere else?
Code: Select all
for k,v in ipairs(Colliders.getColliding{a = hurtPlayer, b = INSTAKILLNPCS, btype=Colliders.NPC} do
Code: Select all
for k,v in ipairs(Colliders.getColliding{a = hurtPlayer, b = INSTAKILLNPCS, btype=Colliders.NPC}) do
Okay. so uh... Error message gone. that's good. but it seems like code didn't really work. The NPC's which were put at "local INSTAKILLNPCS" are working as regular enemy's. I tried once again putting it at the end of Level luna (and after that didn't work. at world luna) but it didn't work...deice wrote: ↑Thu Nov 25, 2021 9:12 amlooking at enjl's code it seems he did indeed forget to put a parenthesis to close the ipairs() call.Someone wrote: ↑Thu Nov 25, 2021 7:35 amThanks for answer! although it seems there's a problem with the code. i tried to copy the code at the end of level Luna. And then into world luna, but every time there's the same error... " ')' expected near 'do' ".. does somebody know how to remove that error? should i copy the code somewhere else?
so, replacewithCode: Select all
for k,v in ipairs(Colliders.getColliding{a = hurtPlayer, b = INSTAKILLNPCS, btype=Colliders.NPC} do
and it should work fine.Code: Select all
for k,v in ipairs(Colliders.getColliding{a = hurtPlayer, b = INSTAKILLNPCS, btype=Colliders.NPC}) do