freeslot("sfx_piopen")
sfxinfo[sfx_piopen].caption = "PopIt Open"
freeslot("sfx_piclos")
sfxinfo[sfx_piclos].caption = "PopIt Close"
freeslot("sfx_pimove")
sfxinfo[sfx_pimove].caption = "PopIt Move"
freeslot("sfx_stcker")
sfxinfo[sfx_stcker].caption = "PLASH!"
freeslot("sfx_sprays")
sfxinfo[sfx_sprays].caption = "SpraySmoke"
freeslot("sfx_pientr")
sfxinfo[sfx_pientr].caption = "QuickSpray Selected"
freeslot("MT_STICKER")
freeslot("S_STICKER")
freeslot("SPR_STCK")
freeslot("S_HIDDENSTICKER")
freeslot("SPR_NONS")
 

rawset(_G, "STICKER", {})

STICKER.size = {
  [0] = FRACUNIT/3,
  [1] = FRACUNIT/2,
  [2] = FRACUNIT/4,
  [3] = FRACUNIT/2,
  [4] = FRACUNIT/2,
  [5] = FRACUNIT/2,
  [6] = FRACUNIT/3,
  [7] = FRACUNIT/3,
  [8] = FRACUNIT/3
}	 

STICKER.title = {
  [0] = "'HUE HUE HUE'",
  [1] = "'pointy tails'",
  [2] = "'LMAOOOO'",
  [3] = "'Self Portrait'",
  [4] = "'D:'",
  [5] = "'EGGMAN propaganda'",
  [6] = "'ASSino'",
  [7] = "'Greatful amy'",
  [8] = "'the fighter'"
}	

STICKER.credit = {
  [0] = "By: Duder",
  [1] = "By: Duder",
  [2] = "By: Duder",
  [3] = "By: Renraks",
  [4] = "By: Woofle",
  [5] = "By: Duder",
  [6] = "By: MCpig",
  [7] = "By: Duder",
  [8] = "By: Duder"
}	

STICKER.body = {
  [0] = S_STICKER,
  [1] = S_STICKER,
  [2] = S_STICKER,
  [3] = S_STICKER,
  [4] = S_STICKER,
  [5] = S_STICKER,
  [6] = S_STICKER,
  [7] = S_STICKER,
  [8] = S_STICKER
}	

STICKER.sprite = {
  [0] = "STCK",
  [1] = "STCK",
  [2] = "STCK",
  [3] = "STCK",
  [4] = "STCK",
  [5] = "STCK",
  [6] = "STCK",
  [7] = "STCK",
  [8] = "STCK"
}	

STICKER.frame = {
  [0] = 0,
  [1] = 1,
  [2] = 2,
  [3] = 3,
  [4] = 4,
  [5] = 5,
  [6] = 6,
  [7] = 7,
  [8] = 8
}

STICKER.set = {
  [0] = 10
}

addHook("PlayerSpawn", function(p)
p.pimenu = 0
p.cooldown = 0
p.maxscroll = STICKER.set[0]
p.maxrows = p.maxscroll/3
if p.maxscroll/3 != p.maxscroll
p.maxrows = $ + 2
end
p.holdc1 = false
p.holdc2 = false
p.holdc1ag = false
p.canscroll = false
p.rot = 1
end)

addHook("PlayerThink", function(p) //PasteSticker
if p != nil and p.valid
and p.mo != nil and p.mo.valid
and p.mo.health then
if P_PlayerInPain(p) == false
 if p.aimingpi == true
 if (p.cmd.buttons & BT_CUSTOM1) and p.holdc1 == false
   local sticker = P_SpawnPlayerMissile(p.mo, MT_STICKER)
   sticker.pangle = p.mo.angle
   sticker.tracer = p.mo
   sticker.stickerfrm = STICKER.frame[ p.scrollpi - 1 ]
   sticker.stickerstate = STICKER.body[ p.scrollpi - 1 ]
   p.holdc1ag = true
   p.holdc1 = true
end
 if (p.cmd.buttons & BT_CUSTOM2) and p.holdc2 == false
   if p.rot == 1
    p.rot = -1
    p.holdc2 = true
   elseif p.rot == -1
    p.rot = 1
    p.holdc2 = true
   end
  end
if not (p.cmd.buttons & BT_CUSTOM2) and p.holdc2 == true
  p.holdc2 = false
 end
end
 if not (p.cmd.buttons & BT_CUSTOM1) and p.holdc1ag == true
 p.holdc1ag = false
 p.holdc1ag = false
 p.holdc1 = false
 p.aimingpi = false
 p.pimenu = 1
 p.canscroll = true
 p.rot = 1
end
end
end
end)

//POPIT OPEN AND CLOSE CODE
addHook("PlayerThink", function(p)
if p != nil and p.valid
and p.mo != nil and p.mo.valid
and p.mo.health then
if P_PlayerInPain(p) == false and P_IsObjectOnGround(p.mo) == true then
 if (p.cmd.buttons & BT_CUSTOM3) and p.popit != true and p.holdc3 != true
  p.popit = true
  p.pimenu = 1
  p.holdc3 = true
  p.aimingpi = false
  p.canscroll = true
  p.rot = 1
  S_StartSound(mo, sfx_piopen, p)
 elseif (p.cmd.buttons & BT_CUSTOM3) and p.popit != false and p.holdc3 != true
  p.popit = false
  p.holdc3 = true
  p.powers[pw_nocontrol] = 0
  p.menu = 0
  p.canscroll = false
  S_StartSound(mo, sfx_piclos, p)
 end
 if not (p.cmd.buttons & BT_CUSTOM3)
  p.holdc3 = false
 end
if p.popit == true
if (p.cmd.buttons & BT_CUSTOM1) and p.holdc1ag == false
if p.aimingpi != true
p.aimingpi = true
p.pimenu = 2
p.canscroll = false
p.holdc1 = true
end
end
if p.holdc1 == true and not (p.cmd.buttons & BT_CUSTOM1)
p.holdc1 = false
end
if p.aimingpi != true
p.mo.momx = 0
p.mo.momy = 0
p.mo.momz = 0
p.powers[pw_nocontrol] = 1
end
end
end
end
end)

addHook("PlayerThink", function(p) //quickspray select
if p != nil and p.valid
and p.mo != nil and p.mo.valid
and p.mo.health then
 if p.popit == true
 if (p.cmd.buttons & BT_CUSTOM2) and p.holdc2 != true
  p.holdc2 = true
  p.quick = p.scrollpi
 S_StartSound(p.mo, sfx_pientr, p)
 print("QuickSpray selected")
 elseif (p.cmd.buttons & BT_CUSTOM2) and p.holdc2 == true
  p.holdc2 = true
 end
 if not (p.cmd.buttons & BT_CUSTOM2)
  p.holdc2 = false
 end
end
end
end)

addHook("PreThinkFrame", function()
for p in players.iterate do
if p != nil and p.valid
and p.mo != nil and p.mo.valid
and p.mo.health then
if p.popit == true
if p.canscroll == true
if p.scrollpi == nil
p.scrollpi = 1
p.scrside = 1
p.scrup = 1
end
if p.cmd.sidemove > 0 and p.holdside != true
S_StartSound(p.mo, sfx_pimove, p) 
p.holdside = true
if p.scrollpi + 1 < p.maxscroll
p.scrollpi = p.scrollpi + 1
p.scrside = p.scrside + 1
if p.scrside > 3
p.scrollpi = p.scrup*3 - 2
p.scrside = 1
end
end
elseif p.cmd.sidemove < 0 and p.holdside != true
S_StartSound(p.mo, sfx_pimove, p)
p.holdside = true
p.scrollpi = p.scrollpi - 1
p.scrside = p.scrside - 1
if p.scrside < 1
p.scrollpi = p.scrup*3
p.scrside = 3
if p.scrollpi > p.maxscroll or p.scrollpi == p.maxscroll
p.scrollpi = p.scrup*3 - 2
p.scrside = 1
end
end
elseif p.cmd.sidemove == 0
p.holdside = false
end
if p.cmd.forwardmove > 0 and p.holdforward != true
S_StartSound(p.mo, sfx_pimove, p) 
p.holdforward = true
p.scrollpi = p.scrollpi - 3
p.scrup = p.scrup - 1
if p.scrup < 1
p.scrollpi = p.scrside + p.maxrows*3 - 6
p.scrup = p.maxrows - 1
if p.scrollpi >= p.maxscroll
p.scrollpi = p.scrside
p.scrup = 1
end
end
elseif p.cmd.forwardmove < 0 and p.holdforward != true
S_StartSound(p.mo, sfx_pimove, p)
p.holdforward = true
p.scrollpi = p.scrollpi + 3
p.scrup = p.scrup + 1
if p.scrup > p.maxrows - 1 or p.scrollpi >= p.maxscroll
p.scrollpi = p.scrside
p.scrup = 1
end
elseif p.cmd.forwardmove == 0
p.updown = 0
p.holdforward = false
end
end
end
end
end
end)

addHook("HUD", function(v, p)
if p != nil and p.valid
and p.mo != nil and p.mo.valid
and p.mo.health then
if p.popit == true
v.enablehuds = true
if p.pimenu == 1
hud.disable("score")
hud.disable("time")
hud.disable("rings")
local count = 0
local i = 1
local x = 1
local img = 1
local patch = 0
v.drawScaled(205*FRACUNIT, 5*FRACUNIT, FRACUNIT*1,v.cachePatch("PI_BG"), V_PERPLAYER)
repeat
count = count + 1
patch = string.upper(STICKER.sprite[count - 1] + string.char(97 + STICKER.frame[count - 1]) + "0") //ts gives an error but doesnt matter because it still works!!! FUCK YOU
if v.patchExists(patch) == true
if count != p.scrollpi
v.drawScaled(188*FRACUNIT + 35*x*FRACUNIT, 40*i*FRACUNIT, STICKER.size[count - 1],v.cachePatch(patch), V_PERPLAYER)
if count == p.quick
v.drawScaled(200*FRACUNIT + 35*x*FRACUNIT, 40*i*FRACUNIT, FRACUNIT/3,v.cachePatch("PI_QUICK"), V_PERPLAYER)
end
elseif count == p.scrollpi
v.drawString(0, 0, STICKER.title[count - 1], V_REDMAP, "left")
v.drawString(0, 10, STICKER.credit[count - 1], V_SNAPTOLEFT, "left")
v.drawScaled(188*FRACUNIT + 35*x*FRACUNIT, 40*i*FRACUNIT, FRACUNIT/1,v.cachePatch(patch), V_PERPLAYER)
end
elseif v.patchExists(patch) == false
i = p.maxrows
end
x = x + 1
img = img + 1
if x == 4
x = 1
i = i + 1
end
until i == p.maxrows
end
if p.pimenu == 2
local patch = string.upper(STICKER.sprite[p.scrollpi - 1] + string.char(97 + STICKER.frame[p.scrollpi - 1]) + "0")
if p.rot == 1
v.drawScaled(300*FRACUNIT, 35*FRACUNIT, STICKER.size[p.scrollpi - 1], v.cachePatch(patch), V_SNAPTORIGHT)
elseif p.rot == -1
v.drawScaled(300*FRACUNIT, 35*FRACUNIT, STICKER.size[p.scrollpi - 1], v.cachePatch(patch), V_FLIP)
end
end
end
if v.enablehuds == true and p.popit == false
hud.enable("score")
hud.enable("time")
hud.enable("rings")
v.enablehuds = false
end
end
end)