Releasing my Classic Snake mod
Snake originally written by mock @otland.net
Talkactions:
Access: 5 /rsnakegvalue -- Set global storage to 0 (if snake is bugging)
Access: 5 /rsnakehighscore -- Reset Snake server highscore
Access: 0 /resetsnake -- Reset your own highscore
Examples:
/rsnakegvalue yes
/rsnakehighscore yes
/resetsnake yes
----------------------------------------------------------------------------------------------------------------------------
SQL Queries for highscore system:
Query 1:
Query 2:
Query 3: - Make sure you have a character with ID 1, otherwise enter another random Character ID (id in players table of database) in the (NULL,0,IDHERE); it doesnt matter who that character is.
Mod file code:
- - - Updated - - -
If a moderator would be so kind and remove the ' in the title.. it's not Mock is, it's Mocks >_<
Snake originally written by mock @otland.net
Talkactions:
Access: 5 /rsnakegvalue -- Set global storage to 0 (if snake is bugging)
Access: 5 /rsnakehighscore -- Reset Snake server highscore
Access: 0 /resetsnake -- Reset your own highscore
Examples:
/rsnakegvalue yes
/rsnakehighscore yes
/resetsnake yes
----------------------------------------------------------------------------------------------------------------------------
- *Rewritten to mod
- *Added configurations
- *Added SQL Highscore System
- *Added Talkactions
SQL Queries for highscore system:
Query 1:
Code:
ALTER TABLE `accounts` ADD
`snakehigh` bigint(20) NOT NULL DEFAULT 0;
Query 2:
Code:
CREATE TABLE IF NOT EXISTS `game_highscores` (
`id` int(11) NOT NULL auto_increment,
`snake` bigint(20) NOT NULL,
`snakename` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Query 3: - Make sure you have a character with ID 1, otherwise enter another random Character ID (id in players table of database) in the (NULL,0,IDHERE); it doesnt matter who that character is.
Code:
INSERT INTO `game_highscores` VALUES (NULL,0,1);
Mod file code:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="snake" version="1.0" author="Pheenix" contact="otland.net" enabled="true">
<description><![CDATA[
______ _ _ ______ _
(_____ \ | | (_) /\ / _____) (_)
_____) )| | ____ _ ____ / \ _ _ _ ____ ___ ___ ____ ____ | / ___ ____ ____ _ ____ ____
| ____/ | | / _ || || _ \ / /\ \ | | | | / _ ) /___) / _ \ | \ / _ ) | | (___) / _ || \ | || _ \ / _ |
| | | |( ( | || || | | | | |__| || | | |( (/ / |___ || |_| || | | |( (/ / | \____/|( ( | || | | || || | | |( ( | |
|_| |_| \_||_||_||_| |_| |______| \____| \____)(___/ \___/ |_|_|_| \____) \_____/ \_||_||_|_|_||_||_| |_| \_|| |
______ (_____|
(_____ \ _
_____) ) ____ ____ ___ ____ ____ | |_ ___ _
| ____/ / ___) / _ ) /___) / _ )| _ \ | _) /___)(_)
| | | | ( (/ / |___ |( (/ / | | | || |__ |___ | _
|_| |_| \____)(___/ \____)|_| |_| \___)(___/ (_)
______ _ _ _ _
/ _____)| | (_) | | | |
| / | | ____ ___ ___ _ ____ \ \ ____ ____ | | _ ____
| | | | / _ | /___) /___)| | / ___) \ \ | _ \ / _ || | / ) / _ )
| \_____ | |( ( | ||___ ||___ || |( (___ _____) )| | | |( ( | || |< ( ( (/ /
\______)|_| \_||_|(___/ (___/ |_| \____) (______/ |_| |_| \_||_||_| \_) \____)
Snake originally written by mock @otland.net
----------------------------------------------------------------------------------------------------------------------------
Access: Talkactions: Example:
5 /rsnakegvalue -- Set global storage to 0 (if snake is bugging) /rsnakegvalue yes
5 /rsnakehighscore -- Reset Snake server highscore /rsnakehighscore yes
0 /resetsnake -- Reset your own highscore /resetsnake yes
----------------------------------------------------------------------------------------------------------------------------
*Rewritten to mod
*Added configurations
*Added SQL Highscore System
*Added Talkactions
by Pheenix @otland.net
----------------------------------------------------------------------------------------------------------------------------
SQL Querys for highscores:
Query 1:
ALTER TABLE `accounts` ADD
`snakehigh` bigint(20) NOT NULL DEFAULT 0;
Query 2:
CREATE TABLE IF NOT EXISTS `game_highscores` (
`id` int(11) NOT NULL auto_increment,
`snake` bigint(20) NOT NULL,
`snakename` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Query 3:
INSERT INTO `game_highscores` VALUES (NULL,0,1);
----------------------------------------------------------------------------------------------------------------------------
]]></description>
<config name="snake-Conf"><![CDATA[
sConf = {
-- Configuration --
----------------------------------------------------------------------------------------------------------------------------
itemid=11756, -- Snake
freeglobalstorage=28107, -- If you dont know what it does, dont touch it!
itemFood=10000, -- Food item
controlpos={x=30732,y=31535,z=6}, -- Control position (center position one level above the playing area)
exitpos = {x=30731,y=31524,z=7}, -- Where to go when the game has ended.
centerpos={x=30731,y=31534,z=7} -- Center Position of the playing area (9 squares high and 13 squares wide, the border around is not included in this)
----------------------------------------------------------------------------------------------------------------------------
-- Configuration End --
}
]]></config>
<lib name="snake-lib"><![CDATA[
domodlib('snake-Conf')
function getServerSnakeHigh()
local random = db.getResult("SELECT `snake` FROM `game_highscores` WHERE `id` = 1 LIMIT 1")
if random:getID() ~= LUA_ERROR then
local snake=random:getDataInt("snake")
random:free()
return snake
end
return LUA_ERROR
end
function getServerSnakeHname()
local sHname = db.getResult("SELECT `snakename` FROM `game_highscores` WHERE `id` = 1 LIMIT 1")
if sHname:getID() ~= LUA_ERROR then
local snakename=sHname:getDataInt("snakename")
sHname:free()
return snakename
end
return LUA_ERROR
end
function getPlayerSnakeHigh(cid)
local Info = db.getResult("SELECT `snakehigh` FROM `accounts` WHERE `id` = " .. getPlayerAccountId(cid) .. " LIMIT 1")
if Info:getID() ~= LUA_ERROR then
local snakehigh=Info:getDataInt("snakehigh")
Info:free()
return snakehigh
end
return LUA_ERROR
end
SNAKE = {
timer = function(cid,n,pos_,time)
local pos_ = pos_ or {{sConf.centerpos}}
setGlobalStorageValue(sConf.freeglobalstorage,cid)
if not isPlayer(cid) then
SNAKE.clean()
return
end
for i,pos in pairs(pos_) do
SNAKE.find_and_delete(pos[1])
if i == 1 then
pos[2] = SNAKE.copypos(pos[1])
pos[1] = getPosByDir({x=pos[1].x,y=pos[1].y,z=pos[1].z,stackpos=255},getCreatureLookDir(cid))
else
pos[2] = SNAKE.copypos(pos[1])
pos[1] = pos_[i-1][2]
end
local ret,p,walk = SNAKE.check(pos[1])
if ret == 1 or ret == 3 then
addEvent(doTeleportThing,1000,cid,sConf.exitpos)
addEvent(doCreatureSay,1100,cid,'I got '..(#pos_-1)..' points.',34)
local sHigh = getServerSnakeHigh()
local sHname = getPlayerNameByGUID(getServerSnakeHname())
local score = tonumber(#pos_-1)
local snakehigh = getPlayerSnakeHigh(cid)
local shit = 1
if snakehigh == 0 then
if score > sHigh then
if sHigh == 0 then
doBroadcastMessage("[Classic Snake]: "..getPlayerName(cid).." has set the first highscore in Classic Snake and it is now "..score.."!", MESSAGE_EVENT_ADVANCE)
else
doBroadcastMessage("[Classic Snake]: "..getPlayerName(cid).." has beaten "..sHname.."s server highscore of "..sHigh.." in Classic Snake. The server highscore is now "..score.."!", MESSAGE_EVENT_ADVANCE)
end
db.executeQuery("UPDATE `game_highscores` SET `snake` = '"..score.."',`snakename` = '"..getPlayerGUID(cid).."' WHERE `id` ="..shit..";")
end
doPlayerPopupFYI(cid, "Your highscore is now "..score.."!")
doPlayerSendTextMessage(cid,4, "[Classic Snake]: Your highscore is now "..score.."!")
db.query("UPDATE `accounts` SET `snakehigh` = "..score.." WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
SNAKE.clean()
setGlobalStorageValue(sConf.freeglobalstorage,0)
return
elseif (snakehigh > score) or (snakehigh == score) or (snakehigh == nil) then
if score > sHigh then
if sHigh == 0 then
doBroadcastMessage("[Classic Snake]: "..getPlayerName(cid).." has set the first highscore in Classic Snake and it is now "..score.."!", MESSAGE_EVENT_ADVANCE)
else
doBroadcastMessage("[Classic Snake]: "..getPlayerName(cid).." has beaten "..sHname.."s server highscore of "..sHigh.." in Classic Snake. The server highscore is now "..score.."!", MESSAGE_EVENT_ADVANCE)
end
db.executeQuery("UPDATE `game_highscores` SET `snake` = '"..score.."',`snakename` = '"..getPlayerGUID(cid).."' WHERE `id` ="..shit..";")
end
SNAKE.clean()
setGlobalStorageValue(sConf.freeglobalstorage,0)
return
elseif snakehigh < score then
if score > sHigh then
if sHigh == 0 then
doBroadcastMessage("[Classic Snake]: "..getPlayerName(cid).." has set the first highscore in Classic Snake and it is now "..score.."!", MESSAGE_EVENT_ADVANCE)
else
doBroadcastMessage("[Classic Snake]: "..getPlayerName(cid).." has beaten "..sHname.."s server highscore of "..sHigh.." in Classic Snake. The server highscore is now "..score.."!", MESSAGE_EVENT_ADVANCE)
end
db.executeQuery("UPDATE `game_highscores` SET `snake` = '"..score.."',`snakename` = '"..getPlayerGUID(cid).."' WHERE `id` ="..shit..";")
end
doPlayerPopupFYI(cid, "You beat your old highscore of "..snakehigh..". \nYour new highscore is now "..score.."!")
doPlayerSendTextMessage(cid,4, "[Classic Snake]: You beat your old highscore of "..snakehigh..". \nYour new highscore is now "..score.."!")
db.executeQuery("UPDATE `accounts` SET `snakehigh` = '"..score.."' WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
SNAKE.clean()
setGlobalStorageValue(sConf.freeglobalstorage,0)
return
end
end
if ret == 2 then
doRemoveItem(p.uid,-1)
if p.itemid == sConf.itemFood then
pos_[#pos_+1] = {pos[2],pos[2]}
for i=1,5 do
addEvent(doSendMagicEffect,100*i,pos[1],29)
end
SNAKE.generateFood()
end
end
doCreateItem(sConf.itemid,1,pos[1])
end
local plpos = getCreaturePosition(cid)
local generated = {}
for i=0,3 do
generated[i] = getPosByDir({x=sConf.controlpos.x,y=sConf.controlpos.y,z=sConf.controlpos.z},i)
end
for i,pos in pairs(generated) do
if SNAKE.samepos(plpos,pos) then
doTeleportThing(cid,sConf.controlpos,false)
end
addEvent(doSendMagicEffect,100,pos,56,cid)
end
addEvent(SNAKE.timer,time,cid,n,pos_,time)
end,
copypos = function(p)
return {x=p.x,y=p.y,z=p.z,stackpos=p.stackpos}
end,
samepos = function(p1,p2)
if p1.x == p2.x and p2.y == p2.y then
return true
end
return false
end,
generateFood = function()
local pp = {x=sConf.centerpos.x+math.random(-6,6),y=sConf.centerpos.y+math.random(-4,4),z=sConf.centerpos.z}
for i=1,5 do
addEvent(doSendMagicEffect,100*i,pp,30)
end
doCreateItem(sConf.itemFood,1,pp)
end,
clean = function()
for y=-4,4 do
for x=-6,6 do
local pp = {x=sConf.centerpos.x+x,y=sConf.centerpos.y+y,z=sConf.centerpos.z}
for i=250,255 do
pp.stackpos = i
local p = getThingFromPos(pp)
if p.itemid ~= 0 then
doRemoveItem(p.uid,-1)
doSendMagicEffect(pp,15)
end
end
end
end
end,
check = function(pos)
for i=1,10 do
pos.stackpos = i
local p = getThingFromPos(pos)
if p.itemid == sConf.itemid then
return 1,p,true
elseif not SNAKE.isWalkable(pos) then
return 3,p,false
elseif p.itemid ~= 0 then
return 2,p
end
end
return false
end,
find_and_delete = function(pos)
for i=0,255 do
pos.stackpos = 255-i
local p = getThingFromPos(pos)
if p.itemid == sConf.itemid then
return doRemoveItem(p.uid,1)
end
end
end,
isWalkable = function(pos, creature, proj, pz)-- by Nord
if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then
return false
end
if getTopCreature(pos).uid > 0 and creature then
return false
end
if getTileInfo(pos).protection and pz then
return false, true
end
local n = not proj and 3 or 2
for i = 0, 255 do
pos.stackpos = i
local tile = getTileThingByPos(pos)
if tile.itemid ~= 0 and not isCreature(tile.uid) then
if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
return false
end
end
end
return true
end,
}
]]></lib>
<action uniqueid="9000" event="script"><![CDATA[
domodlib('snake-Conf')
domodlib('snake-lib')
function onUse(cid, item, frompos, item2, topos)
if not isPlayer(getGlobalStorageValue(sConf.freeglobalstorage)) then
doTeleportThing(cid,sConf.controlpos)
SNAKE.timer(cid,1,nil,item.actionid == 0 and 500 or item.actionid)
doPlayerSendTextMessage(cid,17,'[Classic Snake]: Hold key CTRL and use the arrows to control snake.')
SNAKE.generateFood()
else
doPlayerSendTextMessage(cid,17,'Please wait.')
end
end
]]></action>
<action uniqueid="9001" event="script"><![CDATA[
domodlib('snake-Conf')
domodlib('snake-lib')
function onUse(cid, item, frompos, item2, topos)
if not isPlayer(getGlobalStorageValue(sConf.freeglobalstorage)) then
doTeleportThing(cid,sConf.controlpos)
SNAKE.timer(cid,1,nil,item.actionid == 0 and 500 or item.actionid)
doPlayerSendTextMessage(cid,25,'Hold key CTRL and use the arrows to control snake.')
SNAKE.generateFood()
else
doPlayerSendTextMessage(cid,25,'Please wait.')
end
end
]]></action>
<action uniqueid="9002" event="script"><![CDATA[
domodlib('snake-Conf')
domodlib('snake-lib')
function onUse(cid, item, frompos, item2, topos)
if not isPlayer(getGlobalStorageValue(sConf.freeglobalstorage)) then
doTeleportThing(cid,sConf.controlpos)
SNAKE.timer(cid,1,nil,item.actionid == 0 and 500 or item.actionid)
doPlayerSendTextMessage(cid,25,'Hold key CTRL and use the arrows to control snake.')
SNAKE.generateFood()
else
doPlayerSendTextMessage(cid,25,'Please wait.')
end
end
]]></action>
<talkaction log="yes" words="/rsnakegvalue;!rsnakegvalue" access="5" event="script"><![CDATA[
domodlib('snake-Conf')
domodlib('snake-lib')
function onSay(cid, words, param, channel)
if param == "" then
doPlayerSendTextMessage(cid,35, "[Classic Snake]: If you really want to reset the global storage value of snake write: /rsnakegvalue yes")
return true
end
if param == "yes" then
setGlobalStorageValue(sConf.freeglobalstorage,0)
doPlayerSendTextMessage(cid,4, "[Classic Snake]: You have reseted the global storage for Classic Snake.")
return true
end
end
]]></talkaction>
<talkaction log="yes" words="/resetsnake;!resetsnake" access="0" event="script"><![CDATA[
domodlib('snake-Conf')
domodlib('snake-lib')
function onSay(cid, words, param, channel)
if param == "" then
doPlayerSendTextMessage(cid,35, "[Classic Snake]: If you really want to reset your highscore for Classic Snake write: /resetsnake yes")
return true
end
if param == "yes" then
doPlayerSendTextMessage(cid,4, "[Classic Snake]: You have reseted your highscore for Classic Snake.")
db.executeQuery("UPDATE `accounts` SET `snakehigh` = '0' WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
return true
end
end
]]></talkaction>
<talkaction log="yes" words="/rsnakehighscore;!rsnakehighscore" access="5" event="script"><![CDATA[
domodlib('snake-Conf')
domodlib('snake-lib')
function onSay(cid, words, param, channel)
if param == "" then
doPlayerSendTextMessage(cid,35, "[Classic Snake]: If you really want to reset the server highscore for Classic Snake write: /rsnakehighscore yes")
return true
end
if (param == "yes" and (getPlayerGuildName(cid) == 'PAG Crew')) then
db.query("UPDATE `game_highscores` SET `snake` = 0 AND 'snakename' = "..getPlayerGUID(cid).." WHERE `id` = 1;")
doPlayerSendTextMessage(cid,4, "[Classic Snake]: You have reseted the server highscore for Classic Snake.")
return true
end
end
]]></talkaction>
</mod>
- - - Updated - - -
If a moderator would be so kind and remove the ' in the title.. it's not Mock is, it's Mocks >_<
Last edited: