Page 1 of 1

[PRISM3D] Traffic mod based on in-game time

Posted: Tue Mar 14, 2023 4:22 pm
by J1327


In order to use, first attach to process.
Backup your local save. This script directly modifies config/save files...
Lua code in Auto Assembler setup.

[ENABLE]
{$lua}
Time ='[amtrucks.exe+1C1AC08]+13C' -- get (total) in-game time as minutes (4 Bytes Address (from save))
gettraffic='amtrucks.exe+19c2710'  -- get an effective address to modify, then A or B Time point was reached (Float Address (from config))
PRINT_TXT = 0					   -- Show debug messages

-- 1 Minute ingame time = 1 tick to total in-game time
day=1440 -- 24 Hours (Day)

if (PRINT_TXT==1) then print('ENABLED') end
TrafficChangeTimer = createTimer()
TrafficChangeTimer.Enabled = true
TrafficChangeTimer.Interval = 10000 -- How often check (10000 == 10 seconds)
TrafficChangeTimer.OnTimer = function(TrafficChangeTimer)

ReadTime = readInteger(Time)	   -- read in game time (4 Bytes Address)

-- first time dividing in lua, outputs local float value..
GetInGameTimeAsFloat=(ReadTime/day)

-- removes everything except after dot(eg. 1327.1327 so makes into 0.1327)
FixedInGameFloatTime=math.fmod(GetInGameTimeAsFloat,1)

if (PRINT_TXT==1) then print(FixedInGameFloatTime) end

if (FixedInGameFloatTime>0.5)
   then      -- during 12:00 till 00:00
       if (PRINT_TXT==1) then print('Extreme Traffic') end
       writeFloat(gettraffic,'9') -- spawns more AI cars
   else     -- during 00:00 till 12:00
       if (PRINT_TXT==1) then print('Normal Traffic') end
       writeFloat(gettraffic,'1')
end

end
{$asm}
[DISABLE]
{$lua}
if (PRINT_TXT==1) then print('DISABLED') end
TrafficChangeTimer.Enabled = false
TrafficChangeTimer.destroy()
Spoiler


based on http://lua-users.org/wiki/MathLibraryTutorial math.*
note : as for PRISM3D engine games, some values has their limits such as g_traffic, setting value to 10+ or higher will reset g_traffic to 1 (on config/save write).. ..then this script changes g_traffic value it directly writes into config/save files)..