Skip to content

Instantly share code, notes, and snippets.

@SwadicalRag
Last active August 29, 2015 14:19
Show Gist options
  • Save SwadicalRag/c73c985ccf702f447068 to your computer and use it in GitHub Desktop.
Save SwadicalRag/c73c985ccf702f447068 to your computer and use it in GitHub Desktop.
HashLib
function installHashLib()hashLib={}function string.levenshtein(a,b)local c=string.len(a)local d=string.len(b)local e={}local f=0;if c==0 then return d elseif d==0 then return c elseif a==b then return 0 end;for g=0,c,1 do e[g]={}e[g][0]=g end;for h=0,d,1 do e[0][h]=h end;for g=1,c,1 do for h=1,d,1 do if a:byte(g)==b:byte(h)then f=0 else f=1 end;e[g][h]=math.min(e[g-1][h]+1,e[g][h-1]+1,e[g-1][h-1]+f)end end;return e[c][d]end;function ayy(i,j,k)j=j or 2;i=i or"lmao"local l='a'for m=1,j,1 do l=l..'y'end;if k then print(l..' '..i)else return l..' '..i end end;hashLib.responders={}hashLib.trigger=function(n,o,p)for m,q in ipairs(hashLib.responders)do if string.levenshtein(string.lower(n),string.lower(q.string))<=1 or string.find(string.lower(n),string.lower(q.string))then if q.specific then if q.targetID==p then print(q.response or"")break end else if type(q.response)=="function"then print(q.response(nick,p,n)or"")else print(q.response or"")end;break end end end end;hook.Add("Message","HashLibMsg",function(o,p,n)hashLib.trigger(n,o,p)end)hashLib.addResp=function(r,s,t,u,v)if r and s then local w={string=r,response=s or"",specific=t or false,targetID=u or""}table.insert(hashLib.responders,w)if not v then print("Now listening for \""..r.."\" and responding with \""..s.."\"")end end end;hashLib.delResp=function(r,s)for m,q in ipairs(hashLib.responders)do if q.string==r and q.response==s then table.remove(hashLib.responders,m)end end end;cookie.feed=function(x)cookie.myStomach=(cookie.myStomach or 0)+x or 1;print('yum')end;hashLib.addResp("deez nuts","Got him!",nil,nil,true)hashLib.addResp("i am gold","Nobody cares.",nil,nil,true)hashLib.addResp("debug.getregistry()","No.",nil,nil,true)hashLib.addResp("no hash",function(nick,p,n)timer.Simple(1,function()print("Please forgive me")end)return"I'm sorry Master"end,nil,nil,true)hashLib.addResp("how do i",function(nick,p,n)return"Actually use google: http://lmgtfy.com/?q="..string.gsub(n,' ','%%20')end,nil,nil,true)print("Installed HashLib.")end;function uninstallHashLib()hook.Remove("Message","HashLibMsg")ayy=nil;hashLib=nil;print("Uninstalled HashLib.")end
function animeify(String)
local max = math.floor(#String/10)
local step1 = string.gsub(String,"my","ore no",math.random(0,max))
local step2 = string.gsub(step1,"nice","KAWAII desu~",math.random(0,max))
local step3 = string.gsub(step2,"good","KAWAII desu~",math.random(0,max))
local step4 = string.gsub(step3,"hi","hai~",math.random(0,max))
local step5 = string.gsub(step4,"hey","hai~",math.random(0,max))
local randomInsertions = {
"kawaii",
"<3333333333333",
"hai",
"Tokyo",
"(O)/"
}
local wordAppends = {
"-san ",
"-chan ",
"-sama ",
"-desu~~~ "
}
local punctuation = {
"!!!!!!!",
"~~~~~",
".........",
",,,,,,,,,,,,,",
">>>>>",
";;;;;;;"
}
local step6 = string.gsub(step5,"%.",punctuation[math.random(1,#punctuation)],math.random(0,max))
local step7 = string.gsub(step6," .+ (.+) ",randomInsertions[math.random(1,#randomInsertions)],math.random(0,max))
local sentence = step7
for i=1,math.random(1,max*3) do
local iPoint = math.random(1,#sentence)
sentence = string.sub(sentence,1,iPoint)..wordAppends[math.random(1,#wordAppends)]..string.sub(sentence,iPoint+1,#sentence)
end
local iPoint = math.random(1,#sentence)
local iPoint2 = math.random(iPoint,#sentence)
return string.sub(sentence,1,iPoint)..string.upper(string.sub(iPoint,iPoint2))..string.sub(iPoint2,#sentence)
end
function installHashLib()
hashLib = {}
function string.levenshtein(a,b)local c=string.len(a)local d=string.len(b)local e={}local f=0;if c==0 then return d elseif d==0 then return c elseif a==b then return 0 end;for g=0,c,1 do e[g]={}e[g][0]=g end;for h=0,d,1 do e[0][h]=h end;for g=1,c,1 do for h=1,d,1 do if a:byte(g)==b:byte(h)then f=0 else f=1 end;e[g][h]=math.min(e[g-1][h]+1,e[g][h-1]+1,e[g-1][h-1]+f)end end;return e[c][d]end
function ayy(lmao,length,shouldPrint)
length = length or 2 lmao = lmao or "lmao"
local toPrint = 'a'
for i=1,length,1 do
toPrint = toPrint..'y'
end
if(shouldPrint) then
print(toPrint..' '..lmao)
else
return (toPrint..' '..lmao)
end
end
hashLib.responders = {}
hashLib.trigger = function(msg,plyNick,steamID)
for i,v in ipairs(hashLib.responders) do
if((string.levenshtein(string.lower(msg),string.lower(v.string)) <= 1) or string.find(string.lower(msg),string.lower(v.string))) then
if(v.specific) then
if(v.targetID == steamID) then
print(v.response or "")
break
end
else
if(type(v.response) == "function") then
print(v.response(nick,steamID,msg) or "")
else
print(v.response or "")
end
break
end
end
end
end
hook.Add("Message","HashLibMsg",function(plyNick,steamID,msg)
hashLib.trigger(msg,plyNick,steamID)
end)
hashLib.addResp = function(listen,response,isSpecific,target,quiet)
if(listen and response) then
local new = {
string = listen,
response = response or "",
specific = isSpecific or false,
targetID = target or ""
}
table.insert(hashLib.responders,new)
if not (quiet) then
print("Now listening for \""..listen.."\" and responding with \""..response.."\"")
end
end
end
hashLib.delResp = function(listen,response)
for i,v in ipairs(hashLib.responders) do
if((v.string == listen) and (v.response == response)) then
table.remove(hashLib.responders,i)
end
end
end
cookie.feed = function(num)
cookie.myStomach = (cookie.myStomach or 0) + (num or 1)
print('yum')
end
hashLib.addResp("deez nuts","Got him!",nil,nil,true)
hashLib.addResp("i am gold","Nobody cares.",nil,nil,true)
hashLib.addResp("debug.getregistry()","No.",nil,nil,true)
hashLib.addResp("no hash",function(nick,steamID,msg)
timer.Simple(1,function()
print("Please forgive me")
end)
return "I'm sorry Master"
end,nil,nil,true)
hashLib.addResp("how do i",function(nick,steamID,msg)
return ("Actually use google: http://lmgtfy.com/?q="..string.gsub(msg,' ','%%20'))
end,nil,nil,true)
print("Installed HashLib.")
end
function uninstallHashLib()
hook.Remove("Message","HashLibMsg")
ayy = nil
hashLib = nil
print("Uninstalled HashLib.")
end
gun = {
ammo = 0,
ammoMax = 7,
caliber = "7.62mm",
name = "Nagant M1895",
cartridge = "7.62×38mmR",
bulletLoc = 0,
firing = false
}
RussianRoulette = {
LoadGun = function()
if(gun.ammo == gun.ammoMax) then
print("The "..gun.name.." is already loaded.")
else
print("You load a "..gun.cartridge.." cartridge into the "..gun.name)
gun.ammo = gun.ammoMax
gun.bulletLoc = math.random(1,gun.ammoMax)
end
end,
Fire = function()
if(gun.firing) then
print("Someone else has the gun.")
else
if(gun.ammo == 0) then
print("The "..gun.name.." is not loaded.")
else
gun.firing = true
print("You press the "..gun.name.." against your head and feel the trigger.")
timer.Simple(1,function()
print("You pull the trigger.")
end)
timer.Simple(2,function()
gun.ammo = gun.ammo -1
if(gun.ammo == gun.bulletLoc) then
print("A loud crack echoes through the room. Blackout. A scream.")
print("# dies.")
else
print("You survive.")
end
end)
timer.Simple(3,function()
if(gun.ammo == gun.bulletLoc) then
gun.ammo = 0
gun.firing = false
print(string.dump(function()end))
else
print("You put the "..gun.name.." back on the table.")
gun.firing = false
end
end)
end
end
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment