my script is not working

chipakpaka

Member
i'm writing a script to toggle certain flags off once the first emerald is collected.
here is the script in question:

local function changeactionspd()
for p in players.iterate
if p.mo.skin == "c.l.sonic"
if EMERALD1 then
SF_NOJUMPSPIN = false
SF_NOJUMPDAMAGE = false
else
SF_NOJUMPSPIN = true
SF_NOJUMPDAMAGE = true
end
end
end
end
 
i think you need to put like this
local function changeactionspd()
for p in players.iterate
if p.mo.skin == "c.l.sonic"
if EMERALD1 then
(player.pflags & SF_NOJUMPSPIN & SF_NOJUMPDAMAGE)
end
end
end
end)
 
i'll try it and come back to tell if it worked, thx
edit: i tried, it didn't work. thx anyway tho
 
Last edited:
Lua:
local function ChangeAction(player)
    if player.mo.skin ~= "c.l.sonic" then return end

    if (player.powers[pw_emerald] & EMERALD1) then
        player.charflags = $ & ~(SF_NOJUMPSPIN|SF_NOJUMPDAMAGE)
    else
        player.charflags = $ | (SF_NOJUMPSPIN|SF_NOJUMPDAMAGE)
    end
end

addHook("PlayerThink", ChangeAction)

Try something like this. Haven't tested it, but it SHOULD be fine?

That being said, there are so many flaws in this code that I'd recommend looking in other mods' Lua code first. Simple ones, so you can understand the basics. Using addHook, using PlayerThink, knowing that constants (like EMERALD1) are used for comparison, knowing how flags work (mainly player flags and object flags, but this case uses charflags), knowing how bit math works for flags, though that last one requires a detailed explanation so it's okay if you don't immediately grasp it.

https://wiki.srb2.org/wiki/Lua/Userdata_structures This wiki page is always nice to look up what variable you want to change, just make sure to Ctrl+F the thing you're looking for frequently.
 
try this:
Lua:
addHook("PlayerThink", function(player)
    if (player.mo.skin == "c.l.sonic")
        if (emeralds & EMERALD1)
            player.charflags = $ & ~(SF_NOJUMPSPIN|SF_NOJUMPDAMAGE)
        else
            player.charflags = $|(SF_NOJUMPSPIN|SF_NOJUMPDAMAGE)
        end
    end
end)
 
try this:
Lua:
addHook("PlayerThink", function(player)
    if (player.mo.skin == "c.l.sonic")
        if (emeralds & EMERALD1)
            player.charflags = $ & ~(SF_NOJUMPSPIN|SF_NOJUMPDAMAGE)
        else
            player.charflags = $|(SF_NOJUMPSPIN|SF_NOJUMPDAMAGE)
        end
    end
end)
holy baloney that actually worked! thank you so much i am so grateful. do you mind if i use it in a character i plan to upload? i'll credit you and everything
 
try this:
Lua:
addHook("PlayerThink", function(player)
    if (player.mo.skin == "c.l.sonic")
        if (emeralds & EMERALD1)
            player.charflags = $ & ~(SF_NOJUMPSPIN|SF_NOJUMPDAMAGE)
        else
            player.charflags = $|(SF_NOJUMPSPIN|SF_NOJUMPDAMAGE)
        end
    end

[/QUOTE]
do you want for emerald2 3 4 5 6 7?
Post automatically merged:

tell me what flags
 
holy baloney that actually worked! thank you so much i am so grateful. do you mind if i use it in a character i plan to upload? i'll credit you and everything
use it in whatever you want, happy modding!
do you want for emerald2 3 4 5 6 7?
Post automatically merged:

tell me what flags
it's easy, just put
Lua:
(emeralds & EMERALD1) and (emeralds & EMERALD2) etc...
look in the wiki to see all the emerald constants available (https://wiki.srb2.org/wiki/Chaos_Emerald#Technical_information).
 
i think i got it figured out when it comes to emeralds and changing "stats" or whatever. although i am struggling with something else, so i'd really appriciate it if you helped me out with it.
 

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

Back
Top