Goomba Star Spawn

Fearl

Member
Modder
Mar 24, 2024
13
6
490
Pronouns
he/him
Hello, im porting a hack, and it contains that when you kill 5 big goombas a star appears, I tried this code but doesnt work, the star appears instantly without killing the goombas

Code:
---@param obj Object
function bhv_custom_goomba_star_spawn_loop(obj)
if obj.oAction == 1 then
return
end
if count_objects_with_behavior(get_id_from_behavior(id_bhvGoomba)) ~= 0 then
return
end
obj.oAction = 1
local star = spawn_red_coin_cutscene_star(obj.oPosX, obj.oPosY, obj.oPosZ)
star.oBehParams = obj.oBehParams
end

id_bhvGoombaStar = hook_behavior(nil,OBJ_LIST_LEVEL,false,nil,bhv_custom_goomba_star_spawn_loop)
 
Solution
Fearl, I'm extremely confused, help!

Hook into the mario update event, check if mario's player index is 0, if it is, can you run this code


Code:
local np = gNetworkPlayers[0]

if np.currLevelNum == LEVEL_BOB and np.currAreaIndex == 3 and np.currAreaSyncValid then
    if obj_count_objects_with_behavior_id(id_bhvGoomba) <= 0 then
        djui_chat_message_create("All Goomba's Killed")
    end
end

This will spray chat if all the goomba's are killed.

Does the chat message go and then stop, or is it constantly saying all goomba's are killed?
Try checking if gNetworkPlayers[0].currAreaSyncValid is true
hmm like this?

function bhv_custom_goomba_star_spawn_loop(obj)
local np = gNetworkPlayers[0]
---@param o Object
function bhv_custom_goomba_star_spawn_loop(o)
if np.currLevelNum == LEVEL_BOB and np.currAreaIndex == 3 then
elseif np.currAreaSyncValid == true then
if o.oAction == 1 then
return
end
if count_objects_with_behavior(get_id_from_behavior(id_bhvGoomba)) ~= 0 then
return
end
obj.oAction = 1
local star = spawn_red_coin_cutscene_star(o.oPosX, o.oPosY, o.oPosZ)
star.oBehParams = o.oBehParams
end
end
end
id_bhvGoombaStar = hook_behavior(nil,OBJ_LIST_LEVEL,false,nil,bhv_custom_goomba_star_spawn_loop)

the star now doesn't spawn immediately which is cool, now when you kill the 5 goombas it still does not spawn
 
If you aren't using visual studio code, download that, and get it set up using this.

I've formatted the code, I'll go thru what I changed
Code:
---@param obj Object
function bhv_custom_goomba_star_spawn_loop(obj)
    if obj.oAction == 1 then
        return
    end

    if count_objects_with_behavior(get_behavior_from_id(id_bhvGoomba)) ~= 0 then
        return
    end

    if not gNetworkPlayers[0].currAreaSyncValid then return end

    obj.oAction = 1

    local star = spawn_red_coin_cutscene_star(obj.oPosX, obj.oPosY, obj.oPosZ)
    star.oBehParams = obj.oBehParams
end

    
id_bhvGoombaStar = hook_behavior(nil, OBJ_LIST_LEVEL, false, nil, bhv_custom_goomba_star_spawn_loop)

Firstly, lets look at the currAreaSyncValid code. I changed it to be a 1 liner, simply checking if the area isn't synced. With booleans you don't need to do explicit checks for true or false, you would simply do:

if x then print("True") end
if not x then print("False") end

The main thing that was wrong was you were using get_id_from_behavior and not get_behavior_from_id. So you were attempting to get the behavior id from, well, a behavior id.

If you have any questions feel free to ask :]
 
understood, should i add something else for the code to work, it seems like is not counting the number of goombas that are in that area, making the star appear instantly
 
Firstly, something I missed, you can use `obj_count_objects_with_behavior_id` and just pass in the behavior id instead of converting it to a behavior. Another thing is instead of using oAction, just delete the object using obj_mark_for_deletion when the star is spawned.

I can't point you in one single direction for how to fix it, however, what I can say is that the problem most likely stems from what behavior you're searching for. Do the "big goombas" use a custom behavior? If so, check for those instead. Other than that, without more context, I can't really figure it out, either that or i'm being stupid and another modder can find the problem in 5 seconds lol.
 
lol, Ive checked and the behavior of the goombas is the same as always, now the custom star detects 5 or more dead goombas, just like bbh bigboo with the boos but now with a star and goombas.
 
Fearl, I'm extremely confused, help!

Hook into the mario update event, check if mario's player index is 0, if it is, can you run this code


Code:
local np = gNetworkPlayers[0]

if np.currLevelNum == LEVEL_BOB and np.currAreaIndex == 3 and np.currAreaSyncValid then
    if obj_count_objects_with_behavior_id(id_bhvGoomba) <= 0 then
        djui_chat_message_create("All Goomba's Killed")
    end
end

This will spray chat if all the goomba's are killed.

Does the chat message go and then stop, or is it constantly saying all goomba's are killed?
 
Solution
no message appears, goombas are not counted for some strange reason Edit: ok i made a mistake lol, the message appear and yes its constantly saying all goomba's are killed
Don't double post! Use that edit button! Post automatically merged:

Fearl, I'm extremely confused, help!

Hook into the mario update event, check if mario's player index is 0, if it is, can you run this code


Code:
local np = gNetworkPlayers[0]

if np.currLevelNum == LEVEL_BOB and np.currAreaIndex == 3 and np.currAreaSyncValid then
    if obj_count_objects_with_behavior_id(id_bhvGoomba) <= 0 then
        djui_chat_message_create("All Goomba's Killed")
    end
end

This will spray chat if all the goomba's are killed.

Does the chat message go and then stop, or is it constantly saying all goomba's are killed?
I got a solution seeing this also I've realized many mistakes I made, thank you very much for the help.
 
Last edited:
Ok, the id your using must be incorrect, so i'm gonna ask a couple of questions.

1. do you hook the behavior and replace it at any point? i.e hook_behavior(id_bhvGoomba, OBJ_LIST_GENACTOR, true, nil, nil)
2. Why was that marked as the solution, did you solve it, am I burning time writing this?!?!?!
3. If 1. is not being done, go into the script.c file for the level and see what bhv it's using

Edit: I was wasting my time, woohoo!!
Don't double post! Use that edit button! Post automatically merged:

no message appears, goombas are not counted for some strange reason Edit: ok i made a mistake lol, the message appear and yes its constantly saying all goomba's are killed
Don't double post! Use that edit button! Post automatically merged:


I got a solution seeing this also I've realized many mistakes I made, thank you very much for the help.
Cool, happy I could help, what was the solution if I may ask?
 
Ok, the id your using must be incorrect, so i'm gonna ask a couple of questions.

1. do you hook the behavior and replace it at any point? i.e hook_behavior(id_bhvGoomba, OBJ_LIST_GENACTOR, true, nil, nil)
2. Why was that marked as the solution, did you solve it, am I burning time writing this?!?!?!
3. If 1. is not being done, go into the script.c file for the level and see what bhv it's using

Edit: I was wasting my time, woohoo!!
Don't double post! Use that edit button! Post automatically merged:


Cool, happy I could help, what was the solution if I may ask?
lmao, the solution was to make it simpler, also make it read values <= 0, my brain exploded right now

---@param obj Object

function bhv_custom_goomba_star_spawn_loop(obj)
local np = gNetworkPlayers[0]
if np.currLevelNum == LEVEL_BOB and np.currAreaIndex == 3 then

if obj_count_objects_with_behavior_id(id_bhvGoomba) <= 0 then
spawn_red_coin_cutscene_star(obj.oPosX, obj.oPosY, obj.oPosZ)

obj.oBehParams = obj.oBehParams
obj.oAction = 1
end

if not np.currAreaSyncValid then return end

end
end
id_bhvGoombaStar = hook_behavior(nil, OBJ_LIST_LEVEL, false, nil, bhv_custom_goomba_star_spawn_loop)

hopefully it's okay, otherwise i'll explode right now lol, once again thanks!
 
> if not np.currAreaSyncValid then return end

A minor thing, that line above does absolutely nothing, cuz where you're spawning the star is done first. Check that where you check the level stuff aswell (and be sure to flip the condition from checking if it's false to true), otherwise though, if that works cool!.
 

Users who are viewing this thread