Finally, I managed to make a new custom button in the game. Here is the script:
/////////////////NEW SWITCHES
gamevar LOTAGSAVED 0 2
gamevar HITAGSAVED 0 2
action ONE 1
state CUSTOMSWITCH
ifpdistl 1548
ifp palive
ifp pfacing
ifcansee
ifhitspace
ifcount 13
{
sound SWITCH_ON
ifvare HITAGSAVED 0 { ifactor LAMEBUTTON sound SWITCH_ON} else { soundvar HITAGSAVED }
ifaction 0 { action ONE } else ifaction ONE { action 0 }
operateactivators LOTAGSAVED THISACTOR
operaterespawns LOTAGSAVED
operatemasterswitches LOTAGSAVED
resetcount
}
else ifactor LAMEBUTTON
ifhitweapon
ifcount 13
{
strength 1
cstator 256
ifvare HITAGSAVED 0 { ifactor LAMEBUTTON sound SWITCH_ON } else { soundvar HITAGSAVED }
ifaction 0 { action ONE } else ifaction ONE { action 0 }
operateactivators LOTAGSAVED THISACTOR
operaterespawns LOTAGSAVED
operatemasterswitches LOTAGSAVED
resetcount
}
ends
useractor notenemy LAMEBUTTON
cstator 256
state CUSTOMSWITCH
enda
eventloadactor 10445
{
getactor[THISACTOR].hitag HITAGSAVED
getactor[THISACTOR].lotag LOTAGSAVED
setactor[THISACTOR].hitag 0
setactor[THISACTOR].lotag 0
}
enda
With this, I can now use it as a base to create all the other custom buttons in my maps. It was based on a mod's script. It took me several hours to make a functional script, but here it is, in case anyone wants to use this code as a base to create a functional button, related to the use of lotags and hitags. It is not enough to just create an actor, there has to be something that allows this actor to interact with sector activation functions. I took advantage of some tips about operateactivators, operaterespawns and operatemasterswitches and then I ended up discovering them in the mod, and then I incorporated them into the script and bingo, it finally worked. The next step now is to add new custom access cards, in addition to custom access switches, something I've already done and it worked, and which I'll show you next.
/////////////////NEW KEYCARD
gamevar ACCESSKEY2 0 1
gamevar TEMP 0 2
gamevar TEMP2 0 2
gamevar TEMP3 0 2
gamevar TEMP4 0 2
gamevar TEMP5 0 2
gamevar TEMP6 0 2
gamevar TEMP7 0 2
gamevar LOTAGSAVED 0 2
gamevar HITAGSAVED 0 2
gamevar CUSTOMKEYCARDPOS 0
gamevar CKEYCARDPAL 0 0
gamevar CKEYCARDTILE 0 0
gamevar ACCESSKEY2 0 1
gamevar ZERO 0 2
gamevar ANIMATIONACTIVE 0
gamevar ANIMTIMER 0
define DOUBLESIZE 131072
define NORMALSIZE 65536
define HALFSIZE 32768
define QUARTERSIZE 16384
define ANIMDELAY 16
define EVENT_GETACCESSCARD 100
define EVENT_USESWITCH 13
define EVENT_DISPLAYCROSSHAIR 9
define EVENT_DISPLAYROOMS 6
define EVENT_ACTIVATESWITCH 8
action ONE 1
action LOCKED 0
action UNLOCKING 0
action UNLOCKED 1
state DISPLAYGREYKEY
rotatesprite 261 31 QUARTERSIZE 0 15175 0 4 545 ZERO ZERO xdim ydim
rotatesprite 260 30 QUARTERSIZE 0 15175 0 12 512 ZERO ZERO xdim ydim
ends
state DISPLAYGREENKEY
rotatesprite 251 21 QUARTERSIZE 0 15175 0 4 545 ZERO ZERO xdim ydim
rotatesprite 250 20 QUARTERSIZE 0 15175 0 11 512 ZERO ZERO xdim ydim
ends
state DISPLAYBROWNKEY
rotatesprite 241 11 QUARTERSIZE 0 15175 0 4 545 ZERO ZERO xdim ydim
rotatesprite 240 10 QUARTERSIZE 0 15175 0 15 512 ZERO ZERO xdim ydim
ends
eventloadactor ACCESSCARD2
setactor[THISACTOR].xrepeat 28
setactor[THISACTOR].yrepeat 28
enda
useractor notenemy ACCESSCARD2
ifp pshrunk nullop
else
ifp palive
ifpdistl RETRIEVEDISTANCE
ifcount 6
ifcanseetarget
{
ifspritepal 12
{
ifvarand ACCESSKEY2 1 { break }
else
{
addvar ACCESSKEY2 1
quote 1013 // "GREY ACCESS CARD ACQUIRED"
}
}
else
ifspritepal 11
{
ifvarand ACCESSKEY2 2 { break }
else
{
addvar ACCESSKEY2 2
quote 1014 // "GREEN ACCESS CARD ACQUIRED"
}
}
else
ifspritepal 15
{
ifvarand ACCESSKEY2 4 { break }
else
{
addvar ACCESSKEY2 4
quote 1015 // "BROWN ACCESS CARD ACQUIRED"
}
}
globalsound DUKE_GET
quote 43
palfrom 16 0 32
killit
}
enda
onevent EVENT_DISPLAYCROSSHAIR
ifvarand ACCESSKEY2 1 { state DISPLAYGREYKEY }
ifvarand ACCESSKEY2 2 { state DISPLAYGREENKEY }
ifvarand ACCESSKEY2 4 { state DISPLAYBROWNKEY }
endevent
/////////////////NEW ACCESSSWITCH
eventloadactor ACCESSSWITCH3
{
espawn 2568
getactor[THISACTOR].pal TEMP
setactor[RETURN].pal TEMP
getactor[THISACTOR].hitag HITAGSAVED
getactor[THISACTOR].lotag LOTAGSAVED
setactor[THISACTOR].hitag 0
setactor[THISACTOR].lotag 0
}
enda
state checkcounterpart2
setvar TEMP 0
whilevarn TEMP 16384
{
getactor[TEMP].statnum TEMP4
ifvarn TEMP4 1024
{
getactor[TEMP].picnum TEMP2
ifvare TEMP2 ACCESSSWITCH3
{
getactorvar[TEMP].LOTAGSAVED TEMP3
ifvarvare LOTAGSAVED TEMP3 { setactor[TEMP].picnum 15177 }
}
}
addvar TEMP 1
}
ends
state CUSTOMACCESSSWITCH
ifaction 0 { action LOCKED }
ifpdistl 1024 ifhitspace ifaction LOCKED
{
getactor[THISACTOR].pal TEMP
ifvare TEMP 11
{
ifvarand ACCESSKEY2 2
{
quote 1016 // "GREEN ACCESS CARD GRANTED"
state checkcounterpart2
sound SWITCH_ON
setvar CUSTOMKEYCARDPOS 1
operateactivators LOTAGSAVED THISACTOR
operaterespawns LOTAGSAVED
operatemasterswitches LOTAGSAVED
action UNLOCKED
subvar ACCESSKEY2 2
}
else { quote 1013 } // "GREEN ACCESS CARD REQUIRED"
}
else ifvare TEMP 12
{
ifvarand ACCESSKEY2 1
{
quote 1017 // "GREY ACCESS CARD GRANTED"
state checkcounterpart2
sound SWITCH_ON
setvar CUSTOMKEYCARDPOS 1
operateactivators LOTAGSAVED THISACTOR
operaterespawns LOTAGSAVED
operatemasterswitches LOTAGSAVED
action UNLOCKED
subvar ACCESSKEY2 1
}
else { quote 1014 } // "GREY ACCESS CARD REQUIRED"
}
else ifvare TEMP 15
{
ifvarand ACCESSKEY2 4
{
quote 1018 // "BROWN ACCESS CARD GRANTED"
state checkcounterpart2
sound SWITCH_ON
setvar CUSTOMKEYCARDPOS 1
operateactivators LOTAGSAVED THISACTOR
operaterespawns LOTAGSAVED
operatemasterswitches LOTAGSAVED
action UNLOCKED
subvar ACCESSKEY2 4
}
else { quote 1015 } // "BROWN ACCESS CARD REQUIRED"
}
}
ends
useractor notenemy ACCESSSWITCH3
state CUSTOMACCESSSWITCH
enda
Here is the code I used to make functional cards and switches. And not only that, but I also used different palettes, for green (11), gray (12) and brown (15). I got this code from Nuclear Showndown, so I already had the basis, but I still lacked knowledge about the codes and parameters. In this case, I had to do a lot of trial and error with the help of artificial intelligence (Claude 3.5 Sonnet and GPT 4), because it was too difficult for me to understand how to assemble the code alone. On several occasions, the AI made mistakes, but on other occasions I was the one who made the mistakes while assembling the script. This way, I ended up learning better how to create custom cards as well as customizable card switches. Because of so much trial and error and code research, I ended up getting a better understanding of the syntax and how scripts should be constructed, although I'm still not an expert in this. After all, game programming has become a new thing for me recently.
Also, based on Nuclear Showndown, I managed to make the icons of the cards I pick up appear on the HUD, more or less like they do in the mod. But I only did it for the extra colors, and not for the ones that are already in the game originally.
For those who need a script to create new cards and switches, here it is for newbies in .CON programming who need this. One day, when I've already managed to create several things using codes, maybe I'll create a topic just for this.
Ok, now that the cards and switches are working normally on my map, as well as the icons of the cards acquired in the HUD, all that's left is to deal with the animation, the one when the player activates a switch and Duke Nukem's hand appears holding a card and then the hand without the card. I spent over a day trying to deal with this, with partial success.
/////////////////NEW CARD ANIMATIONS
onevent EVENT_DISPLAYCROSSHAIR
ifvarn CUSTOMKEYCARDPOS 0
{
addvar ANIMTIMER 256
ifvarn ANIMTIMER 512
{
setvar ANIMTIMER 0
switch CUSTOMKEYCARDPOS
case 0: break
case 1:
rotatesprite 160 134 NORMALSIZE 1024 HANDHOLDINGACCESS 0 0 260 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 2:
rotatesprite 160 134 NORMALSIZE 1024 HANDHOLDINGACCESS 0 0 260 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 3:
rotatesprite 160 134 NORMALSIZE 1024 HANDHOLDINGACCESS 0 0 260 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 4:
rotatesprite 160 134 NORMALSIZE 1024 HANDHOLDINGACCESS 0 0 260 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 5:
rotatesprite 160 134 NORMALSIZE 1024 HANDHOLDINGACCESS 0 0 260 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 6:
rotatesprite 160 134 NORMALSIZE 1024 HANDHOLDINGACCESS 0 0 260 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 7:
rotatesprite 160 134 NORMALSIZE 1024 HANDHOLDINGACCESS 0 0 260 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 8:
rotatesprite 160 134 NORMALSIZE 1024 HANDHOLDINGACCESS 0 0 260 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 9:
rotatesprite 160 134 NORMALSIZE 1024 HANDHOLDINGACCESS 0 0 260 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 10:
rotatesprite 160 134 NORMALSIZE 1024 HANDHOLDINGACCESS 0 0 260 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 11:
rotatesprite 160 134 NORMALSIZE 1024 HANDHOLDINGACCESS 0 0 260 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 12:
rotatesprite 160 134 NORMALSIZE 1024 HANDHOLDINGACCESS 0 0 260 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 13:
rotatesprite 160 134 NORMALSIZE 0 2563 0 0 0 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 14:
rotatesprite 160 134 NORMALSIZE 0 2563 0 0 0 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 15:
rotatesprite 160 134 NORMALSIZE 0 2563 0 0 0 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 16:
rotatesprite 160 134 NORMALSIZE 0 2563 0 0 0 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 17:
rotatesprite 120 134 NORMALSIZE 0 2564 0 0 0 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 18:
rotatesprite 120 134 NORMALSIZE 0 2564 0 0 0 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 19:
rotatesprite 120 134 NORMALSIZE 0 2564 0 0 0 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 20:
rotatesprite 120 134 NORMALSIZE 0 2564 0 0 0 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 21:
rotatesprite 80 134 NORMALSIZE 0 2565 0 0 0 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 22:
rotatesprite 80 134 NORMALSIZE 0 2565 0 0 0 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 23:
rotatesprite 80 134 NORMALSIZE 0 2565 0 0 0 0 0 xdim ydim
addvar CUSTOMKEYCARDPOS 1
break
case 24:
rotatesprite 80 134 NORMALSIZE 0 2565 0 0 0 0 0 xdim ydim
setvar CUSTOMKEYCARDPOS 0
setvar ANIMATIONACTIVE 0
break
endswitch
}
}
endevent
onevent EVENT_ACTIVATESWITCH
ifvare ANIMATIONACTIVE 0
{
setvar CUSTOMKEYCARDPOS 1
setvar ANIMATIONACTIVE 1
}
endevent
The animation involves several repeated lines, since if I put only one animation line for each texture and color, it will appear very fast in the animation, while the original in the game is slower and smoother between animations.
Now this is the part where I'm having trouble. I'm starting to understand this rotatesprite thing and its parameters, after countless trials and errors using flags. HANDHOLDINGACCESS (texture 2568) was more complicated, because the original texture is in a horizontally inverted position in relation to what appears in the animation, so I had to use a flag and change the sprite angle value. Then I was able to straighten it, like in the game's animation. Then, since there are other textures in the animation in the game, I also had to use those (textures 2563, 2564 and 2565) for the texture of the hand without the card. Since in this case the textures are already in the right position in relation to the animation in the game, I didn't need to change the angle. If you test the animation script, you'll notice that the animation is very similar to the original in the game. There's just one little problem. I've tried several times to use flags to put the texture behind the status bar, but I can't do it through flags, not even by setting the specific pure value for it.
I'm also not sure if "setvar CUSTOMKEYCARDPOS 1" is correct in the switch and animation script so that the animation responds according to the specific color for accesscard and acessswitch.
And this is where I need help. Then all that's left is to establish a set of independent animations for each card color (green, gray and brown).
If I can do this or if someone can help me with this, I'll have achieved everything I need regarding cards, switches and card animations.