Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local npcTable
- --condition minimum and maximum (respectively) per faction (0 to 100); if absent, assumes 40-80
- local factionCond = {
- [ "stalker" ] = { 40, 80 },
- [ "bandit" ] = { 20, 70 },
- [ "military" ] = { 40, 70 },
- [ "dolg" ] = { 70, 90 },
- [ "freedom" ] = { 50, 100 },
- [ "killer" ] = { 70, 80 },
- [ "ecolog" ] = { 60, 80 },
- [ "zombie" ] = { 0, 60 },
- }
- local rankZero = 400 --rank below this point subtracts condition
- local rankFactor = 0.001 --how much rank affects condition
- --sets condition and attachments if applicable
- function customData( target, character )
- local weaponData = packet_utils.get_object_data( target )
- if weaponData then
- local minCond = 40
- local maxCond = 80
- if factionCond[ character:character_community() ] then
- minCond = factionCond[ character:character_community() ][ 1 ]
- maxCond = factionCond[ character:character_community() ][ 2 ]
- end
- local condition = ( math.random( minCond, maxCond ) / 100 ) + ( ( character:rank() - rankZero ) * rankFactor )
- if condition > 1 then
- condition = 1
- elseif condition < 0 then
- condition = 0
- end
- tkgp_utils.debugMessage( "zoa_npc_items.customData | Attempting to set condition to "..condition, "console" )
- weaponData.upd_condition = condition
- if npcTable[ "addons" ] then
- local addonFlags = 0
- local scopeVal = tkgp_utils.getLtxValue( target:section_name(), "scope_status", "float" )
- local launcherVal = tkgp_utils.getLtxValue( target:section_name(), "grenade_launcher_status", "float" )
- local suppressorVal = tkgp_utils.getLtxValue( target:section_name(), "silencer_status", "float" )
- if math.random( 100 ) <= npcTable[ "addons" ][ 1 ] and scopeVal and scopeVal == 2 then
- addonFlags = addonFlags + 1
- end
- if math.random( 100 ) <= npcTable[ "addons" ][ 2 ] and launcherVal and launcherVal == 2 then
- addonFlags = addonFlags + 2
- end
- if math.random( 100 ) <= npcTable[ "addons" ][ 3 ] and suppressorVal and suppressorVal == 2 then
- addonFlags = addonFlags + 4
- end
- tkgp_utils.debugMessage( "zoa_npc_items.customData | Attempting to set addon flags to "..addonFlags, "console" )
- weaponData.upd_addon_flags = addonFlags
- end
- if not packet_utils.set_object_data( target, weaponData ) then
- tkgp_utils.debugMessage( "zoa_npc_items.customData | Failed to set object data", "console" )
- else
- local testData = packet_utils.get_object_data( target )
- tkgp_utils.debugMessage( "zoa_npc_items.customData | condition: "..testData.condition, "console" )
- tkgp_utils.debugMessage( "zoa_npc_items.customData | upd_addon_flags: "..testData.upd_addon_flags, "console" )
- end
- else
- tkgp_utils.debugMessage( "zoa_npc_items.customData | Failed to get weaponData", "console" )
- end
- end
- --choose a weapon from the appropriate table and spawn it
- function pickWeapon( target, options )
- local totalProb = 0
- for section, chance in pairs( options ) do
- totalProb = totalProb + chance
- end
- local roll = math.random( totalProb )
- local currentChance = 0
- for section, chance in pairs( options ) do
- currentChance = currentChance + chance
- if roll <= currentChance then
- if section ~= "empty" then
- customData( alife():create( section, target:position(), target:level_vertex_id(), target:game_vertex_id() ), target )
- end
- return
- end
- end
- end
- --on every NPC's creation, attempt to give them appropriate weapons
- function firstUpdate( levelObj )
- local tableKey = levelObj:profile_name()
- if zoa_item_tables.weaponTables[ tableKey ] then
- tkgp_utils.debugMessage( "zoa_npc_items.onInit | Processing "..tableKey, "console" )
- npcTable = zoa_item_tables.weaponTables[ tableKey ]
- if npcTable[ "primary" ] then
- pickWeapon( levelObj, npcTable[ "primary" ] )
- else
- tkgp_utils.debugMessage( "zoa_npc_items.onInit | No primary table found for "..tableKey, "console" )
- end
- if npcTable[ "secondary" ] then
- pickWeapon( levelObj, npcTable[ "secondary" ] )
- else
- tkgp_utils.debugMessage( "zoa_npc_items.onInit | No secondary table found for "..tableKey, "console" )
- end
- else
- tkgp_utils.debugMessage( "zoa_npc_items.onInit | No weapon tables found for "..tableKey, "console" )
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement