My real example how to create a Cyberpunk 2077 mod with Cyberpunk Engine Tweaks
First : sorry my english it's not my native language
I created this to to inspire others to create own mod with lua scripts
my mode link on Nexus : https://www.nexusmod...k2077/mods/1423
Source code: (lua script)
Init chapter
registerForEvent("onInit", function() isVisible = true counter = 0 speed = 1 pos = Game.GetPlayer():GetWorldPosition() math.randomseed(os.time()) random_posx=math.random(-5,5) random_posy=math.random(10,20) random_npctype=math.random(0,11)
function despawnAll() Game.GetPreventionSpawnSystem():RequestDespawnPreventionLevel(-1) Game.GetPreventionSpawnSystem():RequestDespawnPreventionLevel(-2) end
Generate NPC
Based on parameters the script is generating NPC around player
function generateNPC(valtozo) local player = Game.GetPlayer() local heading = player:GetWorldForward() local offsetDir = Vector3.new(heading.x, heading.y, heading.z) local spawnTransform = player:GetWorldTransform() local spawnPosition = spawnTransform.Position:ToVector4(spawnTransform.Position) spawnTransform:SetPosition(spawnTransform, Vector4.new(spawnPosition.x - random_posx , spawnPosition.y - random_posy, spawnPosition.z, spawnPosition.w)) --local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(chara), -2, spawnTransform) if valtozo==1 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0x00875bac, 0x2f), -2, spawnTransform) end if valtozo==2 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0x01585495, 0x33), -2, spawnTransform) end if valtozo==3 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0x01543324, 0x33), -2, spawnTransform) end if valtozo==4 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0x087C1A17, 0x28), -2, spawnTransform) end if valtozo==5 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0x0bf796c3, 0x2b), -2, spawnTransform) end if valtozo==6 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0x699055d3, 0x2a), -2, spawnTransform) end if valtozo==7 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0x08812649, 0x1f), -2, spawnTransform) end if valtozo==8 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0x6b1a1c88, 0x1e), -2, spawnTransform) end if valtozo==9 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0xc95bf1c0, 0x27), -2, spawnTransform) end if valtozo==10 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0x97f248d6, 0x3b), -2, spawnTransform) end if valtozo==12 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0xA0C49CE5, 0x1C), -2, spawnTransform) end if valtozo==13 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0x6F510015, 0x20), -2, spawnTransform) end if valtozo==14 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0x01428b52, 0x1f), -2, spawnTransform) end if valtozo==15 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0x00b00d2c, 0x2b), -2, spawnTransform) end if valtozo==16 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0x00a1d567, 0x40), -2, spawnTransform) end if valtozo==17 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0x00d4f601, 0x38), -2, spawnTransform) end if valtozo==18 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new("Character.cpz_maelstrom_grunt1_ranged1_copperhead_ma"), -2, spawnTransform) end if valtozo==19 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new("Character.mq008_6th_street_male"), -2, spawnTransform) end if valtozo==20 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new("Character.tyger_claws_gangster1_ranged1_copperhead_ma"), -2, spawnTransform) end if valtozo==21 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new("Character.voodooboys_grunt1_ranged2_saratoga_ma"), -2, spawnTransform) end if valtozo==22 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new("Character.kab_the_mox_1_ranged1_lexington_wa"), -2, spawnTransform) end if valtozo==23 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new("Character.gle_valentinos_grunt1_ranged1_nova_ma"), -2, spawnTransform) end if valtozo==24 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new("Character.animals_bouncer1_melee1_fists_mb"), -2, spawnTransform) end if valtozo==25 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0xC2E9DE21, 0x29), -2, spawnTransform) end if valtozo==26 then local npc = Game.GetPreventionSpawnSystem():RequestSpawn(TweakDBID.new(0XEB5308C5, 0x1B), -2, spawnTransform) end print(npc) end end)
OnDraw function
Draw a text box with coordinates
registerForEvent("onDraw", function() if (isVisible) then ImGui.SetNextWindowSize(150,150) if (ImGui.Begin("NPC Spawn")) then ImGui.Text(string.format("Please set Hotkeys!")) ImGui.Text(string.format("X:: %.1f", pos.x)) ImGui.Text(string.format("Y:: %.1f", pos.y)) ImGui.Text(string.format("Z:: %.1f", pos.z)) ImGui.Text(string.format("NPC_shift_x:: %.1f", random_posx)) ImGui.Text(string.format("NPC_shift_y:: %.1f", random_posy)) ImGui.Text(string.format("NPCType:: %.1f", random_npctype)) end end ImGui.End() end)
Hotkey functions
create 4 hotkeys function
registerHotkey("npcspawnPlaceRandomNPC", "PlaceRandomNPCKey", function() move = not move moveDirection = "forward" pos = Game.GetPlayer():GetWorldPosition() random_posx=math.random(-5,5) random_posy=math.random(10,20) random_npctype=math.random(1,24) generateNPC(random_npctype) end) registerHotkey("npcspawnPlace_boss_smasherNPC", "Place_boss_smasherNPCKey", function() move = not move moveDirection = "forward" pos = Game.GetPlayer():GetWorldPosition() random_posx=math.random(-5,5) random_posy=math.random(10,20) generateNPC(26) end) registerHotkey("npcspawnPlacecyberpsychoNPC", "PlacecyberpsychoNPCKey", function() move = not move moveDirection = "forward" pos = Game.GetPlayer():GetWorldPosition() random_posx=math.random(-5,5) random_posy=math.random(10,20) random_npctype=math.random(1,25) generateNPC(25) end) registerHotkey("npcspawnDespawnAllNPC", "DespawnAllNPCKey", function() despawnAll() end)
Edited by cybercom, 02 February 2021 - 09:30 pm.