I can't even tell which problems I'm having.
Look at this, it's a medium-sized script:
In singleplayer, it works like a charm.
But in multiplayer, the script goes downhill:
Supposedly, when you hold down the custom button 1 you start draining YOUR fuel to be propelled upwards, but for some reason the entire fuel meter is drained for the entire server (and the one using it gets propelled upwards). If you have 600 fuel, someone else can use every bit of it.
It's like it is being synchronized to everyone.
And if that wasn't enough, the variable that is supposed to lock the custom button 2 to not be held, doesn't lock it and you can easily drain the fuel by holding it.
I'm doing something wrong that I didn't notice?
Look at this, it's a medium-sized script:
Code:
local boostlock = 0
local fuel = 0
local boost_fuel_cost = 30
local rings_to_fuel = 10
local fuel_gain = 75
addHook("ThinkFrame", function()
for player in players.iterate do
if boost_fuel_cost == nil then
boost_fuel_cost = server.boost_fuel_cost
--print("I'm NIL")
end
-- Jetpack action
if (player.cmd.buttons & BT_CUSTOM1) and (player.mo ~= nil) then
if fuel > 0 then
P_SpawnGhostMobj(player.mo)
if player.mo.momz < 20*FRACUNIT then
player.mo.momz = $ + 1*FRACUNIT
end
S_StartSound(player.mo, sfx_buzz4)
fuel = $ - 1
end
end
-- Boost action - Like, you press it once to throw yourself upwards.
if (player.cmd.buttons & BT_CUSTOM2) and (boostlock == 0) and (player.mo ~= nil) then
if fuel >= boost_fuel_cost then
boostlock = 1
P_SpawnGhostMobj(player.mo)
player.mo.momz = $ + 18*FRACUNIT
S_StartSound(player.mo, sfx_pogo)
fuel = $ - boost_fuel_cost
end
elseif not (player.cmd.buttons & BT_CUSTOM2) then
boostlock = 0
end
if player.spectator then fuel = 0 end
end
end)
COM_AddCommand("ringfuel", function(p, buy)
if p.mo ~= nil then
if buy == nil then
CONS_Printf(p, "\x82[Jetpack]\x80 ringfuel <buy>: Takes some rings and transforms the rings into fuel.")
CONS_Printf(p, "\x82[Jetpack]\x80 Current price: "..rings_to_fuel.." rings for "..fuel_gain.." fuel.")
CONS_Printf(p, "\x82[Jetpack]\x80 Type 'ringfuel buy' to exchange rings for fuel at the current price.")
elseif buy == "buy" then
if p.mo.health > rings_to_fuel then
fuel = $ + fuel_gain
p.mo.health = $ - rings_to_fuel
p.health = $ - rings_to_fuel
else
CONS_Printf(p, "\x82[Jetpack]\x80 You don't have enough rings to buy fuel!")
end
else
CONS_Printf(p, "\x82[Jetpack]\x80 Invalid syntax. Try again.")
end
else
CONS_Printf(p, "\x82[Jetpack]\x80 Get out of spectator before executing this command!")
end
end, 0)
COM_AddCommand("fuelprice", function(p, ring, gas)
ring = tonumber(ring)
gas = tonumber(gas)
if ring == nil then
CONS_Printf(p, "\x82[Jetpack]\x80 fuelprice <rings for fuel> <fuel gain>: Sets how much rings do you need for X fuel.")
end
if (ring ~= nil) and (gas ~= nil) then
rings_to_fuel = ring
fuel_gain = gas
CONS_Printf(p, "\x82[Jetpack]\x80 New price: "..rings_to_fuel.." rings for "..fuel_gain.." fuel.")
end
end, 1)
COM_AddCommand("boostprice", function(p, boost)
boost = tonumber(boost)
if boost == nil then
CONS_Printf(p, "\x82[Jetpack]\x80 boostprice <self-descriptive>: Sets how much rings do you need for a quick boost.")
end
if (boost ~= nil) then
boost_fuel_cost = boost
CONS_Printf(p, "\x82[Jetpack]\x80 Now every boost costs "..boost_fuel_cost.." fuel. ur 3 expensiv bruh")
end
end, 1)
local function hud_drawfuel(v, stplyr)
for player in players.iterate
v.drawString(15, 72, "JETPACK", V_SNAPTOLEFT)
v.drawString(15, 80, "FUEL", V_SNAPTOLEFT)
v.drawNum(45, 90, fuel, V_SNAPTORIGHT)
end
end
hud.add(hud_drawfuel)
In singleplayer, it works like a charm.
But in multiplayer, the script goes downhill:
Supposedly, when you hold down the custom button 1 you start draining YOUR fuel to be propelled upwards, but for some reason the entire fuel meter is drained for the entire server (and the one using it gets propelled upwards). If you have 600 fuel, someone else can use every bit of it.
It's like it is being synchronized to everyone.
And if that wasn't enough, the variable that is supposed to lock the custom button 2 to not be held, doesn't lock it and you can easily drain the fuel by holding it.
I'm doing something wrong that I didn't notice?