Skip to content

Commit

Permalink
player checks
Browse files Browse the repository at this point in the history
fixes the bug with other controller types
  • Loading branch information
Dysoch committed Nov 24, 2023
1 parent 3cc4827 commit 0f4f9ab
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DyWorld-Dynamics-2/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Date: 25. 11. 2023
- Done: 0%
Survival/RPG:
- Done: 5%
- Added in a stronger player check. This should check for online, alive players and if sandbox or editor is activated
- Added in a stronger player check. Bascially 4 factors: Alive, Joined, Not in Editor, Not in Sandbox before any player related script works
Story:
- Done: 0%
GUI:
Expand Down
24 changes: 24 additions & 0 deletions DyWorld-Dynamics-2/data/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,87 @@ function Dy_Diff(NMB, NB, TYPE)
local form = Round((NMB * 5), NB)
if form <= 1 then
return 1
else
return form
end
elseif VAR == "Easy" then
local form = Round((NMB * 2.5), NB)
if form <= 1 then
return 1
else
return form
end
elseif VAR == "Normal" then
local form = Round((NMB), NB)
if form <= 1 then
return 1
else
return form
end
elseif VAR == "Hard" then
local form = Round((NMB * 0.5), NB)
if form <= 1 then
return 1
else
return form
end
elseif VAR == "Insane" then
local form = Round((NMB * 0.25), NB)
if form <= 1 then
return 1
else
return form
end
elseif VAR == "Death" then
local form = Round((NMB * 0.125), NB)
if form <= 1 then
return 1
else
return form
end
end
elseif TYPE == "crafting" then
if VAR == "Very Easy" then
local form = Round((NMB * 10), NB)
if form <= 1 then
return 1
else
return form
end
elseif VAR == "Easy" then
local form = Round((NMB * 5), NB)
if form <= 1 then
return 1
else
return form
end
elseif VAR == "Normal" then
local form = Round((NMB), NB)
if form <= 1 then
return 1
else
return form
end
elseif VAR == "Hard" then
local form = Round((NMB * 0.5), NB)
if form <= 1 then
return 1
else
return form
end
elseif VAR == "Insane" then
local form = Round((NMB * 0.25), NB)
if form <= 1 then
return 1
else
return form
end
elseif VAR == "Death" then
local form = Round((NMB * 0.125), NB)
if form <= 1 then
return 1
else
return form
end
end
else
Expand Down
14 changes: 5 additions & 9 deletions DyWorld-Dynamics-2/script/events/on_tick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,18 @@ function Event_on_tick(event)
end
global.dyworld.time.log = global.dyworld.time.actual.year..":"..global.dyworld.time.actual.day..":"..global.dyworld.time.actual.hour..":"..global.dyworld.time.actual.minute..":"..global.dyworld.time.actual.second

for k,v in pairs(game.players) do
local player = v
local id = k
if global.dyworld.players[id].alive then
Vitals_Change(k, v)
for id,player in pairs(game.players) do
if Player_Check(id) then
Vitals_Change(id, player)
Distance_Calc(id)
Refresh_Personal_GUI(player, id)
end
end
end

if event.tick%(60*60*1)==1 then -- Every Minute --
for k,v in pairs(game.players) do
local player = v
local id = k
if global.dyworld.players[id].alive then
for id,player in pairs(game.players) do
if Player_Check(id) then
DIS_Init(id)
if settings.get_player_settings(id)["DyWorld_DIS_Trash"].value then
DIS_Personal_Trash(id)
Expand Down
35 changes: 35 additions & 0 deletions DyWorld-Dynamics-2/script/lualib/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,41 @@ end

function Player_Check(id)
local player = global.dyworld.players[id]
if game.players[id] then
if game.players[id].character then
global.dyworld.players[id].alive = true
else
global.dyworld.players[id].alive = false
end
if game.players[id].connected then
global.dyworld.players[id].joined = true
else
global.dyworld.players[id].joined = false
end
--game.players[id].print(game.players[id].controller_type)
if game.players[id].controller_type == 1 then
-- character enabled --
global.dyworld.players[id].alive = true
global.dyworld.players[id].sandbox = false
global.dyworld.players[id].editor = false
--elseif game.players[id].controller_type(defines.controllers.god) then
-- sandbox enabled --
--global.dyworld.players[id].alive = true
--global.dyworld.players[id].sandbox = true
--global.dyworld.players[id].editor = false
elseif game.players[id].controller_type == 4 then
-- editor enabled --
global.dyworld.players[id].alive = true
global.dyworld.players[id].sandbox = false
global.dyworld.players[id].editor = true
else
-- safety feature, if dont know, then just disable everything --
global.dyworld.players[id].alive = false
global.dyworld.players[id].sandbox = false
global.dyworld.players[id].editor = false
end
end
-- Return the check --
if player.alive and player.joined and not player.editor and not player.sandbox then
return true
else
Expand Down

0 comments on commit 0f4f9ab

Please sign in to comment.