Spoiler
CARS = {}
CARS_MAXSPEED = 25
CARS_ACCELERATION = function(speed) return speed/2 + 1 end
CARS_DECELERATION = function(speed) return -speed/2 - 1 end
CARS3_IMAGEPATH = "gfx/a car"..math.random(1,10)..".png"
CARS_PRICE = 1000
if not addmoney then
function addmoney(id, amount)
if player(id, 'money') >= amount then
parse(string.format("setmoney %i %i", id, player(id, 'money') - amount))
return true
end
return false
end
end
function addcar(x, y)
table.insert(CARS, {x = x, y = y, speed = 0, image = image(img, x, y, 0), rot = 0, imagepath = img})end
function carpos(car, x, y)
local tilex, tiley = math.floor(car.x/32), math.floor(car.y/32)
if not tile(tilex, tiley, 'walkable') then
return false
end
for _, id in ipairs(player(0, 'table')) do
if car.driver and car.driver ~= id and player(id, 'health') > 0 and math.abs(x - player(id, 'x')) < 16 and math.abs(y - player(id, 'y')) < 16 then
parse(string.format("customkill %i Car %i", car.driver, id))
end
end
car.x, car.y = x, y
if car.driver then
parse(string.format("setpos %i %i %i", car.driver, x, y))
else
imagepos(car.image, x, y, car.rot)
end
return true
end
addhook("ms100", "CARms100")
function CARms100()
for id, car in pairs(CARS) do
if car.driver then
if not player(car.driver, 'exists') or player(car.driver, 'health') <= 0 then
car.driver = nil
car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_DECELERATION(car.speed))
else
car.rot = player(car.driver, 'rot')
car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_ACCELERATION(car.speed))
end
elseif car.speed > 0 then
car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_DECELERATION(car.speed))
end
if car.speed > 0 then
local rot = math.rad(car.rot - 180)
if not carpos(car, car.x - math.sin(rot)*car.speed, car.y + math.cos(rot)*car.speed) then
if car.driver then
parse(string.format("customkill %i Car %i", car.driver, car.driver))
end
freeimage(car.image)
parse(string.format("explosion %i %i 128 250 %i", car.x, car.y, car.driver or 0))
parse(string.format("effect \"fire\" %i %i 256 128", car.x, car.y))
CARS[id] = nil
end
end
end
end
addhook("use", "CARuse")
function CARuse(id,event,data,x,y)
x, y = player(id, 'x'), player(id, 'y')
for _, car in pairs(CARS) do
if not car.driver and math.abs(car.x - x) < 32 and math.abs(car.y - y) < 32 then
car.speedmod = player(id, 'speedmod')
parse(string.format("speedmod %i 0", id))
car.driver = id
freeimage(car.image)
car.image = image(CARS_IMAGEPATH, 1, 0, 200+id)
break
elseif car.driver == id then
parse(string.format("speedmod %i %i", id, car.speedmod))
car.driver = nil
freeimage(car.image)
car.image = image(CARS_IMAGEPATH, player(id, 'x'), player(id, 'y'), 0)
break
end
end
end
addhook("die", "CARdie")
function CARdie(id,killer,weapon,x,y)
x, y = player(id, 'tilex'), player(id, 'tiley')
for id, car in pairs(CARS) do
if car.driver == id then
freeimage(car.image)
parse(string.format("explosion %i %i 128 250 %i", car.x, car.y, car.driver))
parse(string.format("effect \"fire\" %i %i 256 128", car.x, car.y))
CARS[id] = nil
break
end
end
end
local bought, nomoney = "You have bought a car for $" .. CARS_PRICE .. ".", "You do not have enough money to buy a car. ($" .. CARS_PRICE .. ")"
addhook("say", "CARsay")
function CARsay(id,message)
if message == "!car" then
if addmoney(id, CARS_PRICE) then
addcar(player(id, 'x'), player(id, 'y'))
msg2(id, bought)
else
msg2(id, nomoney)
end
return 1
end
end
CARS_MAXSPEED = 25
CARS_ACCELERATION = function(speed) return speed/2 + 1 end
CARS_DECELERATION = function(speed) return -speed/2 - 1 end
CARS3_IMAGEPATH = "gfx/a car"..math.random(1,10)..".png"
CARS_PRICE = 1000
if not addmoney then
function addmoney(id, amount)
if player(id, 'money') >= amount then
parse(string.format("setmoney %i %i", id, player(id, 'money') - amount))
return true
end
return false
end
end
function addcar(x, y)
table.insert(CARS, {x = x, y = y, speed = 0, image = image(img, x, y, 0), rot = 0, imagepath = img})end
function carpos(car, x, y)
local tilex, tiley = math.floor(car.x/32), math.floor(car.y/32)
if not tile(tilex, tiley, 'walkable') then
return false
end
for _, id in ipairs(player(0, 'table')) do
if car.driver and car.driver ~= id and player(id, 'health') > 0 and math.abs(x - player(id, 'x')) < 16 and math.abs(y - player(id, 'y')) < 16 then
parse(string.format("customkill %i Car %i", car.driver, id))
end
end
car.x, car.y = x, y
if car.driver then
parse(string.format("setpos %i %i %i", car.driver, x, y))
else
imagepos(car.image, x, y, car.rot)
end
return true
end
addhook("ms100", "CARms100")
function CARms100()
for id, car in pairs(CARS) do
if car.driver then
if not player(car.driver, 'exists') or player(car.driver, 'health') <= 0 then
car.driver = nil
car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_DECELERATION(car.speed))
else
car.rot = player(car.driver, 'rot')
car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_ACCELERATION(car.speed))
end
elseif car.speed > 0 then
car.speed = math.min(CARS_MAXSPEED, car.speed + CARS_DECELERATION(car.speed))
end
if car.speed > 0 then
local rot = math.rad(car.rot - 180)
if not carpos(car, car.x - math.sin(rot)*car.speed, car.y + math.cos(rot)*car.speed) then
if car.driver then
parse(string.format("customkill %i Car %i", car.driver, car.driver))
end
freeimage(car.image)
parse(string.format("explosion %i %i 128 250 %i", car.x, car.y, car.driver or 0))
parse(string.format("effect \"fire\" %i %i 256 128", car.x, car.y))
CARS[id] = nil
end
end
end
end
addhook("use", "CARuse")
function CARuse(id,event,data,x,y)
x, y = player(id, 'x'), player(id, 'y')
for _, car in pairs(CARS) do
if not car.driver and math.abs(car.x - x) < 32 and math.abs(car.y - y) < 32 then
car.speedmod = player(id, 'speedmod')
parse(string.format("speedmod %i 0", id))
car.driver = id
freeimage(car.image)
car.image = image(CARS_IMAGEPATH, 1, 0, 200+id)
break
elseif car.driver == id then
parse(string.format("speedmod %i %i", id, car.speedmod))
car.driver = nil
freeimage(car.image)
car.image = image(CARS_IMAGEPATH, player(id, 'x'), player(id, 'y'), 0)
break
end
end
end
addhook("die", "CARdie")
function CARdie(id,killer,weapon,x,y)
x, y = player(id, 'tilex'), player(id, 'tiley')
for id, car in pairs(CARS) do
if car.driver == id then
freeimage(car.image)
parse(string.format("explosion %i %i 128 250 %i", car.x, car.y, car.driver))
parse(string.format("effect \"fire\" %i %i 256 128", car.x, car.y))
CARS[id] = nil
break
end
end
end
local bought, nomoney = "You have bought a car for $" .. CARS_PRICE .. ".", "You do not have enough money to buy a car. ($" .. CARS_PRICE .. ")"
addhook("say", "CARsay")
function CARsay(id,message)
if message == "!car" then
if addmoney(id, CARS_PRICE) then
addcar(player(id, 'x'), player(id, 'y'))
msg2(id, bought)
else
msg2(id, nomoney)
end
return 1
end
end
Bad Argument#1 to image Why?
edited 2×, last 22.04.10 09:18:26 pm