Lua Thok Scripting Example

Lua Thok Scripting Example V1.1

clairebun

Community Noise Maker
Sonic Team Junior
This script is for educational purposes, and demonstrates how to recreate Sonic's thok completely through lua scripting. Included are two versions: one with comments and print messages to explain the process, and one with just the necessary code.

The goal of this script is to provide a jumping-off point for newcomers to analyze and better understand how to lua script for SRB2.
 

Attachments

  • srb20079.png
    srb20079.png
    298.8 KB · Views: 650
Last edited:
I really appreciate this. This will be a helpful tool for everyone new to scripting.
 
Step 2: Recreate it in SOC
In all seriousness, I could see this being handy in the future
 
how do I change the thoks speed
this thok's speed is controlled by actionspd, a property found in a player, which is copied from the skin that player's using.
changing a character's actionspd will change the speed of the thok.

alternatively, check this, from L_ThokExample-v1.1.lua
L_ThokExample-v1.1.lua:
    --Now do InstaThrust, which resets the object's XY speed and thrusts it in
    --a specified angle and a specified speed amount
    local actionspd = FixedMul(player.mo.scale, player.actionspd)
        -- We multiply player's actionspd by the player object's scale. This
        -- means that if the player is shrunk or enlarged, their thok speed
        -- will be accurate to the player object's new size.
    if player.mo.eflags & MFE_UNDERWATER
        actionspd = $/2 -- We cut actionspd in half if travelling underwater.
    end
    P_InstaThrust(player.mo, player.mo.angle, actionspd)
at line 89 (or for this code block, line 3) a local variable actionspd is made, taking the player's actionspd property and multiplying it by the player's scale.
if you want to use your own number instead of the thok being actionspd dependant, replace that player.actionspd with a number of your choosing. make sure to multiply that number by FRACUNIT so the thrust isn't super weak.
 
this thok's speed is controlled by actionspd, a property found in a player, which is copied from the skin that player's using.
changing a character's actionspd will change the speed of the thok.

alternatively, check this, from L_ThokExample-v1.1.lua
L_ThokExample-v1.1.lua:
    --Now do InstaThrust, which resets the object's XY speed and thrusts it in
    --a specified angle and a specified speed amount
    local actionspd = FixedMul(player.mo.scale, player.actionspd)
        -- We multiply player's actionspd by the player object's scale. This
        -- means that if the player is shrunk or enlarged, their thok speed
        -- will be accurate to the player object's new size.
    if player.mo.eflags & MFE_UNDERWATER
        actionspd = $/2 -- We cut actionspd in half if travelling underwater.
    end
    P_InstaThrust(player.mo, player.mo.angle, actionspd)
at line 89 (or for this code block, line 3) a local variable actionspd is made, taking the player's actionspd property and multiplying it by the player's scale.
if you want to use your own number instead of the thok being actionspd dependant, replace that player.actionspd with a number of your choosing. make sure to multiply that number by FRACUNIT so the thrust isn't super weak.
Thanks
 

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top