local t = {
fromPos = {x = 1012, y = 1016, z = 7},
toPos = {x = 1028, y = 1026, z = 7},
s1 = 1023,
s2 = 1042,
scorePosition = {
red = {x = 1015, y = 1021, z = 7},
blue = {x = 1025, y = 1021, z = 7}
},
redStorage = 1000,
blueStorage = 2000,
centerPosition = {x = 1020, y = 1021, z = 7}
}
local function score()
local positions = {
{storage = t.s1, pos1 = {x = 1020, y = 1016, z = 7}, text = "Red"},
{storage = t.s2, pos1 = {x = 1020, y = 1026, z = 7}, text = "Blue"}
}
for _, pos in ipairs(positions) do
addEvent(doSendAnimatedText, 5 * 1000, pos.pos1, getGlobalStorageValue(pos.storage) .. " Score" .. (getGlobalStorageValue(pos.storage) < 2 and "" or "s") .. "!", math.random(1, 254))
addEvent(doSendAnimatedText, 10 * 1000, pos.pos1, pos.text, math.random(1, 254))
end
return addEvent(score, 2 * 1000)
end
function onStepIn(cid, item, position, fromPosition, toPosition)
local dir = getCreatureLookDirection(cid)
local pos = getThingPos(cid)
local nextPos = {}
if isInRange(getThingPos(cid), t.fromPos, t.toPos) then
if dir == NORTH then
nextPos = {x = pos.x, y = pos.y-1, z = pos.z}
elseif dir == SOUTH then
nextPos = {x = pos.x, y = pos.y+1, z = pos.z}
elseif dir == EAST then
nextPos = {x = pos.x+1, y = pos.y, z = pos.z}
elseif dir == WEST then
nextPos = {x = pos.x-1, y = pos.y, z = pos.z}
end
if nextPos ~= {} then
doRemoveItem(getTileItemById(position, item.itemid).uid)
doCreateItem(11251, 1, nextPos)
if getGlobalStorageValue(t.s1) == -1 then
setGlobalStorageValue(t.s1, 0)
end
if getGlobalStorageValue(t.s2) == -1 then
setGlobalStorageValue(t.s2, 0)
end
if t.scorePosition.red.x == nextPos.x and t.scorePosition.red.y == nextPos.y then
if getPlayerStorageValue(cid, t.redStorage) == 1 then
setGlobalStorageValue(t.s1, getGlobalStorageValue(t.s1)+1)
doBroadcastMessage(getCreatureName(cid) .. " has scored 1 point for the Red Team!")
end
elseif t.scorePosition.blue.x == nextPos.x and t.scorePosition.blue.y == nextPos.y then
if getPlayerStorageValue(cid, t.blueStorage) == 1 then
setGlobalStorageValue(t.s2, getGlobalStorageValue(t.s2)+1)
doBroadcastMessage(getCreatureName(cid) .. " has scored 1 point for the Blue Team!")
end
end
if nextPos.x == (t.scorePosition.red.x or t.scorePosition.blue.x) and nextPos.y == (t.scorePosition.red.y or t.scorePosition.blue.y) then
doRemoveItem(getTileItemById(nextPos, item.itemid).uid)
doCreateItem(11251, 1, t.centerPosition)
doBroadcastMessage("Current Basketball Score:\nRed Team: " .. getGlobalStorageValue(t.s1) .. "\nBlue Team: " .. getGlobalStorageValue(t.s2))
score()
end
end
end
return true
end