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("MT_STICKER")
freeslot("S_STICKER")
freeslot("SPR_STCK")
freeslot("S_HIDDENSTICKER")
freeslot("SPR_NONS")

//STICKER DISPLAY SIZE LIST 

local StickerDisplay = {
  [0] = FRACUNIT/3,
  [1] = FRACUNIT/2,
  [2] = FRACUNIT/4,
  [3] = FRACUNIT/2,
  [4] = FRACUNIT/2,
  [5] = FRACUNIT/2,
  [6] = FRACUNIT/3,
  [7] = FRACUNIT/3
}	 

local StickerTitle = {
  [0] = "'HUE HUE HUE'",
  [1] = "'pointy tails'",
  [2] = "'LMAOOOO'",
  [3] = "'Self Portrait'",
  [4] = "'D:'",
  [5] = "'EGGMAN propaganda'",
  [6] = "'REAL SONIC'",
  [7] = "'Greatful amy'"
}	

local StickerCredit = {
  [0] = "By: Duder",
  [1] = "By: Duder",
  [2] = "By: Duder",
  [3] = "By: Renraks",
  [4] = "By: Woofle",
  [5] = "By: Duder",
  [6] = "By: Duder",
  [7] = "By: Duder"
}	



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

addHook("PlayerThink", function(p) //PasteSticker
if p.mo.valid then
if P_PlayerInPain(p) == false
 if p.aimingpi == true
 if (p.cmd.buttons & BT_CUSTOM1) and p.holdc1 == false
   P_SpawnPlayerMissile(p.mo, MT_STICKER)
   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.mo.valid then
if P_PlayerInPain(p) == false
 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)
 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)
 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
if p.mo.valid then
 if p.popit == true
 if (p.cmd.buttons & BT_CUSTOM2) and p.holdc2 != true
  p.holdc2 = true
  p.quick = p.scrollpi
 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()
local p = consoleplayer
if p != nil
if p.mo.valid 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.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.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.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.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)
local p = consoleplayer
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
v.drawScaled(205*FRACUNIT, 5*FRACUNIT, FRACUNIT*1,v.cachePatch("PI_BG"), V_PERPLAYER)
repeat
count = count + 1
if v.patchExists(string.upper("STCK" + string.char(96 + img) + "0")) == true
if count != p.scrollpi
v.drawScaled(188*FRACUNIT + 35*x*FRACUNIT, 40*i*FRACUNIT, StickerDisplay[count - 1],v.cachePatch(string.upper("STCK" + string.char(96 + img) + "0")), 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, StickerTitle[count - 1], V_REDMAP, "left")
v.drawString(0, 10, StickerCredit[count - 1], V_SNAPTOLEFT, "left")
v.drawScaled(188*FRACUNIT + 35*x*FRACUNIT, 40*i*FRACUNIT, FRACUNIT/1,v.cachePatch(string.upper("STCK" + string.char(96 + img) + "0")), V_PERPLAYER)
end
elseif v.patchExists(string.upper("STCK" + string.char(96 + img) + "0")) == 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
if p.rot == 1
v.drawScaled(300*FRACUNIT, 35*FRACUNIT, StickerDisplay[p.scrollpi - 1], v.cachePatch(string.upper("STCK" + string.char(96 + p.scrollpi) + "0")), V_SNAPTORIGHT)
elseif p.rot == -1
v.drawScaled(300*FRACUNIT, 35*FRACUNIT, StickerDisplay[p.scrollpi - 1], v.cachePatch(string.upper("STCK" + string.char(96 + p.scrollpi) + "0")), 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)