Page 1 of 1

[Update:05/10/21] [Tips] Things used in creating a Customizable NPC

Posted: 6 Jan 2021, 7:25
by Victor ManuelMR
Everything that is said here, can be amateur, and may undergo changes and improvements over time.
You can change the values, as you wish, depending on what you are doing.

Configuring Facing:
There is a way to configure Facing, in a simple way, using the following script:
• X = Value

Code: Select all

.xsp = X *(1-2*.facing)


Make the NPC Jump (Koopa Jump AI):
If you want the NPC to jump like the Koopa with Wings:

Code: Select all

if .stand = 1 then .ysp = -8 'Checking if the NPC touched the ground, if so his speed will be -8 (Obs: Only when he touches the ground)
.ysp += 0.2692 'Simulated Gravity
if .ysp > 8 then .ysp = 8 'If the SpeedY (Ysp) is greater than 8 (>8), then it will be 8

SMBX data:
• NPC Jump Force: -8.2
• Acceleration used in NPCs (Normal): 0.2692
• NPC Gravity Limit: 8

The NPC chases the player:
There is a simple way to make the NPC go towards the player (Like Metroids from the Metroid Series):

Code: Select all

.xsp = (char(1).x-.x)*0.01 'It will follow the player horizontally.   
.ysp = (char(1).y-.y)*0.01 'It will follow the player vertically.

Thanks to Twisty for the script.

Detecting Damage to an NPC:
In order to detect a Damage, you will have to store a value, which will be used to compare with the NPC's amount of health. (In this case, it can be a variable, or an internal NPC variable [.ivalX | X = a, b, c])
In this example, I will be using a normal variable, which I will call "HStore" (Preferably, it (the variable HStore) has the same value as the health quantity of the NPC.)

Code: Select all

if .health < val(HStore) then 'If the NPC's life span is less than the variable(HStore)
val(HStore) -= 1 'then the variable will decrease by 1.
end


Detecting the collision of the NPC (If it is a collectable):
One way in which you detect a collision between the player and NPC.

Code: Select all

If ((char(1).x + char(1).pwidth >= .x and char(1).x <= .x + .width and char(1).y + char(1).pheight >= .y and char(1).y <= .y + .height))
'Code
end


When a platform is being stepped on (Platform NPC):
In case you want to check, when an NPC platform is being stepped on or not:

Code: Select all

with npc(sysval(param1))
    if sysval(param3) = 1 and .ivala <> 3
        .ivala = 1
        'behaviour for being stepped on!
    else
        if .ivala = 2
            .ivala = 3
        elseif .ivala = 3
            'behaviour for being left!
        end if
        .touchevent = "Script Name Here"
        if .ivala <> 0 and .ivala <> 3
            .ivala = 2
        end if
    end if
end with
'Script by FyreNova


Configuring the NoMove:

Code: Select all

.xsp = xsp_value * (1-2*.facing) * (1-1*.nomove)
Create by coolXD