EvoSoft
Is Da Mapper
First bug.. I try to install Snake to my server.
Everything works great (you get in, you stear with ctrl+arrowkeys, items is spawning) but the "snake body" isn't following me (as it is supposed to).
Also, several players can enter the game.. :/
Here's the script:
and here's what errors I get (multiple):
Second bug..
You can't see if anyone is sleeping in beds..
Items.xml:
Thanks for all the help!
Everything works great (you get in, you stear with ctrl+arrowkeys, items is spawning) but the "snake body" isn't following me (as it is supposed to).
Also, several players can enter the game.. :/
Here's the script:
LUA:
-- [TGY]
local snake = {}
local speed = 500
local itemPos = {}
local itemId = 1629
local playing = true
local addTrail = true
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)
local condition = createConditionObject(CONDITION_HASTE)
setConditionParam(condition, CONDITION_PARAM_TICKS, 2000)
setConditionFormula(condition, 200, -200, 200, -200)
setCombatCondition(combat, condition)
-- Combat param for boost!
function onStepIn(cid, item, position, fromPosition)
if not (isPlayer(cid)) then
return true
end
if #isCreatureInArea({x = 32432, y = 32440, z = 7}, {x = 32426, y = 32427, z = 7}) > 0 then
doTeleportThing(cid, fromPosition)
return true
end
areaClean()
doCombat(cid, combat, numberToVariant(cid))
doTeleportThing(cid, {x = 32426, y = 32423, z = 7})
doCreatureSetNoMove(cid, true)
placeDisc(true)
addTrail = false
speed = 500
snake = {}
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "[SNAKE] ------------------------------------------------")
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "[SNAKE] Hold CTRL and use the ARROW KEYS to change direction.")
local score = getPlayerStorageValue(cid, 45720)
if score < 0 then score = 0 end
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "[SNAKE] Your highscore: ".. score ..".")
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "[SNAKE] ------------------------------------------------")
addEvent(playerMove, speed, cid)
playing = true
return true
end
function playerMove(cid)
local dir = getCreatureLookDirection(cid)
local pos = getCreaturePosition(cid) -- Old
if (dir == 0 and pos.y == 32417) or (dir == 2 and pos.y == 32427) or (dir == 1 and pos.x == 32426) or (dir == 3 and pos.x == 32416) then
gameOver(cid) -- Bail out if walking against a wall
return
end
doMoveCreature(cid, dir)
local pos2 = getCreaturePosition(cid) -- New
if isInArea(pos2, {x = 32416, y = 32417, z = 7}, {x = 32426, y = 32427, z = 8}) == false then
gameOver(cid) -- Glitched out somehow (teleport?)
return
end
--[[if #snake == 1 then
if pos2.x == snake[1].x and pos2.y == snake[1].y then
gameOver(cid) -- Bail out knocking in a snake piece
return
end
end]]
for _,v in pairs(snake) do
if pos2.x == v.x and pos2.y == v.y then
gameOver(cid) -- Bail out knocking in a snake piece
return
end
end
if addTrail then
doCreateItem(1486, 1, pos)
table.insert(snake,pos)
addTrail = false
else
-- Move latest trail item
if #snake > 0 then
local part = getTileItemById({x=snake[1].x,y=snake[1].y,z=8}, 1486).uid
if part ~= 0 then
doRemoveItem(part)
doCreateItem(1486, 1, pos)
table.insert(snake,pos)
table.remove(snake,1)
end
end
end
if pos2.x == itemPos.x and pos2.y == itemPos.y then
-- Item caught
speed = math.floor(speed * 0.97)
placeDisc(false)
doSendAnimatedText(pos2, (#snake + 1), TEXTCOLOR_ORANGE)
-- Add item to trail
addTrail = true
end
doCombat(cid, combat, numberToVariant(cid))
addEvent(playerMove, speed, cid)
end
function gameOver(cid)
doCreatureSetNoMove(cid, false)
doTeleportThing(cid, {x = 32345, y = 32222, z = 7})
doRemoveItem(itemId)
for _,v in pairs(snake) do
local part = getThingFromPos({x=snake[1].x,y=snake[1].y,z=7,stackpos=1})
if part.itemid > 0 then
doRemoveItem(part.uid)
end
end
local hscore = getPlayerStorageValue(cid, 45720)
local score = #snake
local profit = math.floor((score - 10)/4)
if profit < 0 then profit = 0 end
if score > hscore then
setPlayerStorageValue(cid, 45720, score)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "[SNAKE] Game ended! Score: ".. score .." (NEW HIGHSCORE). Earnings: ".. profit .." Game Tokens.")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "[SNAKE] Game ended! Score: ".. score .." (Highscore: ".. hscore .."). Earnings: ".. profit .." Game Tokens.")
end
if profit > 0 then
doPlayerAddItem(cid,6527,profit)
end
playing = false
end
function placeDisc(isNew)
if not isNew then
--itemPos = {x=math.random(866,876),y=math.random(923,933),z=8}
doRemoveItem(itemId)
end
local try = 0
while true do
local done = true
try = try + 1
itemPos = {x=math.random(32416,32426),y=math.random(32417,32427),z=7}
for _,v in pairs(snake) do
if itemPos.x == v.x and itemPos.y == v.y then
done = false
--print("exhaust")
break
end
end
if done or try > 25 then break end
end
doItemSetAttribute(doCreateItem(9566, 1, itemPos), "uid", itemId)
--end
end
function areaClean()
for x=32416,32426 do
for y=32417,32427 do
local t = getThingFromPos({x=x,y=y,z=8,stackpos=1})
if t.itemid > 0 then
doRemoveItem(t.uid)
end
end
end
end
and here's what errors I get (multiple):
Second bug..
You can't see if anyone is sleeping in beds..
Items.xml:
LUA:
<item id="1768" article="a" name="cot">
<attribute key="type" value="bed"/>
<attribute key="partnerDirection" value="east" />
<attribute key="maleSleeper" value="1756" />
</item>
Thanks for all the help!