diff options
Diffstat (limited to 'Northstar.Custom/mod/scripts/vscripts/weapons')
5 files changed, 451 insertions, 0 deletions
diff --git a/Northstar.Custom/mod/scripts/vscripts/weapons/mp_weapon_peacekraber.nut b/Northstar.Custom/mod/scripts/vscripts/weapons/mp_weapon_peacekraber.nut new file mode 100644 index 00000000..a9da541f --- /dev/null +++ b/Northstar.Custom/mod/scripts/vscripts/weapons/mp_weapon_peacekraber.nut @@ -0,0 +1,162 @@ +untyped + +// created by JustANormalUser#0001 on discord + +global function OnWeaponPrimaryAttack_peacekraber; +global function OnWeaponDeactivate_peacekraber +global function OnWeaponActivate_peacekraber + +#if SERVER +global function OnWeaponNpcPrimaryAttack_peacekraber +#endif // #if SERVER + + +const PEACEKRABER_MAX_BOLTS = 11 // this is the code limit for bolts per frame... do not increase. +bool isWeaponActive = false; +entity clientWeapon = null; + +struct +{ + float[2][PEACEKRABER_MAX_BOLTS] boltOffsets = [ + [0.0, 0.0], // center + [0.0, 1.0], // top + [-0.683, 0.327], + [0.683, 0.327], + [-0.636, -0.683], + [0.636, -0.683], + [0.0, 0.5], + [-0.342, 0.174], + [0.342, 0.174], + [-0.318, -0.342], + [0.318, -0.342], + ] + + int maxAmmo + float ammoRegenTime +} file +// "OnWeaponActivate" "OnWeaponActivate_peacekraber" +// "OnWeaponDeactivate" "OnWeaponDeactivate_peacekraber" +void function OnWeaponActivate_peacekraber (entity weapon) { + #if CLIENT + if (!weapon.GetWeaponOwner().IsPlayer() || weapon.GetWeaponOwner() != GetLocalViewPlayer()) return; + isWeaponActive = true; + clientWeapon = weapon; + thread CrosshairCycle(); + #endif +} + +void function OnWeaponDeactivate_peacekraber (entity weapon) { + #if CLIENT + if (!weapon.GetWeaponOwner().IsPlayer() || weapon.GetWeaponOwner() != GetLocalViewPlayer()) return; + isWeaponActive = false; + #endif +} +#if CLIENT +void function CrosshairCycle() { + var rui = RuiCreate( $"ui/crosshair_shotgun.rpak", clGlobal.topoCockpitHudPermanent, RUI_DRAW_COCKPIT, 0 ) + RuiSetFloat(rui, "adjustedSpread", 0.1) + array<int> spreadFrac = [1, 0.65, 0.45, 0.2] + array<vector> colors = [<1, 1, 1>, <0.666, 1, 1>, <0.333, 1, 1>, <0, 1, 1>] + int chargeLevel; + float chargeFrac; + while (isWeaponActive) { + WaitFrame() + chargeLevel = clientWeapon.GetWeaponChargeLevel(); + chargeFrac = clientWeapon.GetWeaponChargeFraction(); + RuiSetFloat3(rui, "teamColor", colors[chargeLevel]); + switch (chargeLevel) { + case 0: + if (chargeFrac > 0.266) { + RuiSetFloat(rui, "adjustedSpread", Graph(chargeFrac, 0.266, 0.333, 0.1, 0.065)) + } + else RuiSetFloat(rui, "adjustedSpread", 0.1) + break; + case 1: + if (chargeFrac > 0.6) { + RuiSetFloat(rui, "adjustedSpread", Graph(chargeFrac, 0.6, 0.666, 0.065, 0.045)) + } + else RuiSetFloat(rui, "adjustedSpread", 0.065) + break; + case 2: + if (chargeFrac > 0.933) { + RuiSetFloat(rui, "adjustedSpread", Graph(chargeFrac, 0.933, 1, 0.045, 0.02)) + } + else RuiSetFloat(rui, "adjustedSpread", 0.045) + break; + case 3: + RuiSetFloat(rui, "adjustedSpread", 0.025) + break; + default: + break; + } + } + + RuiDestroy(rui); + clientWeapon = null; +} +#endif + +var function OnWeaponPrimaryAttack_peacekraber( entity weapon, WeaponPrimaryAttackParams attackParams ) +{ + #if CLIENT + weapon.EmitWeaponSound( "Weapon_Titan_Sniper_LevelTick_2" ) + #endif + + return FireWeaponPlayerAndNPC( attackParams, true, weapon ) +} + +#if SERVER +var function OnWeaponNpcPrimaryAttack_peacekraber( entity weapon, WeaponPrimaryAttackParams attackParams ) +{ + return FireWeaponPlayerAndNPC( attackParams, false, weapon ) +} +#endif // #if SERVER + +function FireWeaponPlayerAndNPC( WeaponPrimaryAttackParams attackParams, bool playerFired, entity weapon ) +{ + entity owner = weapon.GetWeaponOwner() + bool shouldCreateProjectile = false + if ( IsServer() || weapon.ShouldPredictProjectiles() ) + shouldCreateProjectile = true + #if CLIENT + if ( !playerFired ) + shouldCreateProjectile = false + #endif + + vector attackAngles = VectorToAngles( attackParams.dir ) + vector baseUpVec = AnglesToUp( attackAngles ) + vector baseRightVec = AnglesToRight( attackAngles ) + + if ( shouldCreateProjectile ) + { + weapon.EmitWeaponNpcSound( LOUD_WEAPON_AI_SOUND_RADIUS_MP, 0.2 ) + array<int> spreadFrac = [1, 0.65, 0.45, 0.2] + + for ( int index = 0; index < PEACEKRABER_MAX_BOLTS; index++ ) + { + vector upVec = baseUpVec * file.boltOffsets[index][1] * 0.05 * spreadFrac[weapon.GetWeaponChargeLevel()] + vector rightVec = baseRightVec * file.boltOffsets[index][0] * 0.05 * spreadFrac[weapon.GetWeaponChargeLevel()] + + vector attackDir = attackParams.dir + upVec + rightVec + float projectileSpeed = 2800 + + if ( weapon.GetWeaponClassName() == "mp_weapon_peacekraber" ) + { + projectileSpeed = 6400 + } + + entity bolt = weapon.FireWeaponBolt( attackParams.pos, attackDir, projectileSpeed, damageTypes.largeCaliber | DF_SHOTGUN, damageTypes.largeCaliber | DF_SHOTGUN, playerFired, index ) + if ( bolt ) + { + bolt.kv.gravity = 0.4 // 0.09 + + if ( weapon.GetWeaponClassName() == "mp_weapon_peacekraber" ) + bolt.SetProjectileLifetime( RandomFloatRange( 1.0, 1.3 ) ) + else + bolt.SetProjectileLifetime( RandomFloatRange( 0.50, 0.65 ) ) + } + } + } + + return 1 +}
\ No newline at end of file diff --git a/Northstar.Custom/mod/scripts/vscripts/weapons/mp_weapon_toolgun.nut b/Northstar.Custom/mod/scripts/vscripts/weapons/mp_weapon_toolgun.nut new file mode 100644 index 00000000..94bd7429 --- /dev/null +++ b/Northstar.Custom/mod/scripts/vscripts/weapons/mp_weapon_toolgun.nut @@ -0,0 +1,39 @@ +untyped +global function OnWeaponActivate_weapon_toolgun +global function OnWeaponDeactivate_weapon_toolgun +global function OnWeaponPrimaryAttack_weapon_toolgun +global function OnWeaponStartZoomIn_weapon_toolgun +global function OnWeaponStartZoomOut_weapon_toolgun +#if SERVER +global function OnWeaponNpcPrimaryAttack_weapon_toolgun +#endif + +void function OnWeaponActivate_weapon_toolgun( entity weapon ) +{ + CallToolOnEquipped( weapon.GetOwner(), weapon ) +} + +void function OnWeaponDeactivate_weapon_toolgun( entity weapon ) +{ + CallToolOnUnequipped( weapon.GetOwner(), weapon ) +} + +var function OnWeaponPrimaryAttack_weapon_toolgun( entity weapon, WeaponPrimaryAttackParams attackParams ) +{ + CallToolOnFired( weapon.GetOwner(), weapon, attackParams ) +} + +void function OnWeaponStartZoomIn_weapon_toolgun( entity weapon ) +{ + CallToolOnAds( weapon.GetOwner(), weapon ) +} + +void function OnWeaponStartZoomOut_weapon_toolgun( entity weapon ) +{ + CallToolOnUnAds( weapon.GetOwner(), weapon ) +} + +var function OnWeaponNpcPrimaryAttack_weapon_toolgun( entity weapon, WeaponPrimaryAttackParams attackParams ) +{ + // do nothing for now, maybe make it launch nukes or something later that could be funny +}
\ No newline at end of file diff --git a/Northstar.Custom/mod/scripts/vscripts/weapons/toolgun/sh_toolgun_tool_explode.nut b/Northstar.Custom/mod/scripts/vscripts/weapons/toolgun/sh_toolgun_tool_explode.nut new file mode 100644 index 00000000..512c538c --- /dev/null +++ b/Northstar.Custom/mod/scripts/vscripts/weapons/toolgun/sh_toolgun_tool_explode.nut @@ -0,0 +1,30 @@ +global function ToolgunToolCreateExplosion_Init + +void function ToolgunToolCreateExplosion_Init() +{ + AddCallback_OnToolgunToolsInit( CreateToolgunToolCreateExplosion ) +} + +void function CreateToolgunToolCreateExplosion() +{ + ToolgunTool createExplosionTool + createExplosionTool.toolName = "Create explosion" + createExplosionTool.toolDescription = "Creates an explosion" + + createExplosionTool.onFired = ToolgunToolCreateExplosion_Fire + + RegisterTool( createExplosionTool ) +} + +void function ToolgunToolCreateExplosion_Fire( entity player, entity weapon, WeaponPrimaryAttackParams attackParams ) +{ + #if SERVER + int dist = 55555 // should hit edge of map at all times ideally + vector forward = AnglesToForward( player.EyeAngles() ) + + // raycast to explosion position + TraceResults trace = TraceLine( player.EyePosition(), player.EyePosition() + ( dist * forward ), null, TRACE_MASK_NPCSOLID ) + // make explosion + Explosion( trace.endPos, player, player, 90, 90, 100, 100, 0, trace.endPos, 5000, damageTypes.explosive, eDamageSourceId.burn, "exp_small" ) + #endif +}
\ No newline at end of file diff --git a/Northstar.Custom/mod/scripts/vscripts/weapons/toolgun/sh_toolgun_tool_throw.nut b/Northstar.Custom/mod/scripts/vscripts/weapons/toolgun/sh_toolgun_tool_throw.nut new file mode 100644 index 00000000..d6975c6d --- /dev/null +++ b/Northstar.Custom/mod/scripts/vscripts/weapons/toolgun/sh_toolgun_tool_throw.nut @@ -0,0 +1,24 @@ +global function ToolgunToolThrowEntity_Init + +void function ToolgunToolThrowEntity_Init() +{ + AddCallback_OnToolgunToolsInit( CreateToolgunToolThrow ) +} + +void function CreateToolgunToolThrow() +{ + ToolgunTool throwTool + throwTool.toolName = "Throw entity" + throwTool.toolDescription = "Spawns and throws the currently selected entity type" + + throwTool.onFired = ToolgunToolThrow_OnFired + + RegisterTool( throwTool ) +} + +void function ToolgunToolThrow_OnFired( entity player, entity weapon, WeaponPrimaryAttackParams attackParams ) +{ + #if SERVER + ClientCommand( player, "ent_throw npc_frag_drone" ) + #endif +}
\ No newline at end of file diff --git a/Northstar.Custom/mod/scripts/vscripts/weapons/toolgun/sh_toolgun_tools.gnut b/Northstar.Custom/mod/scripts/vscripts/weapons/toolgun/sh_toolgun_tools.gnut new file mode 100644 index 00000000..4d7e9d89 --- /dev/null +++ b/Northstar.Custom/mod/scripts/vscripts/weapons/toolgun/sh_toolgun_tools.gnut @@ -0,0 +1,196 @@ +untyped +global function ToolgunTools_Init +global function AddCallback_OnToolgunToolsInit + +global function RegisterTool +global function CallToolOnEquipped +global function CallToolOnUnequipped +global function CallToolOnFired +global function CallToolOnAds +global function CallToolOnUnAds + +#if SERVER +global function SetToolgunAmmoCount +global function SetToolgunProscreen +#endif // #if SERVER + +global struct ToolgunTool +{ + string toolName = "" + string toolDescription = "" + + void functionref( entity, entity ) onEquipped + void functionref( entity, entity ) onUnequipped + void functionref( entity, entity, WeaponPrimaryAttackParams ) onFired + void functionref( entity, entity ) onAds + void functionref( entity, entity ) onUnAds +} + +struct ToolgunPlayerSettings +{ + int selectedToolIndex + int ammoCount + int proscreenNumber +} + +// doing preprocessor defs inside the struct seemed to cause compiler errors so we define them separately +#if CLIENT +struct { + array<void functionref()> onToolgunToolsInitCallbacks + + array<ToolgunTool> tools + ToolgunPlayerSettings clientPlayerSettings +} file +#endif // #if CLIENT + +#if SERVER +struct { + array<void functionref()> onToolgunToolsInitCallbacks + + array<ToolgunTool> tools + // serverside playersettings + table<int, ToolgunPlayerSettings> playerSettings +} file +#endif // #if SERVER + +void function AddCallback_OnToolgunToolsInit( void functionref() callback ) +{ + file.onToolgunToolsInitCallbacks.append( callback ) +} + +void function ToolgunTools_Init() +{ + //#if SERVER + //AddCallback_OnClientConnecting( InitialiseToolgunSettings ) + //AddCallback_OnClientDisconnected( DestroyToolgunSettings ) + //#endif // #if SERVER + // + //// need this threaded so we can wait a frame + //thread ToolgunTools_InitThreaded() +} + +void function ToolgunTools_InitThreaded() +{ + // wait a frame for tools to all init and add their callbacks + WaitFrame() + + // call callbacks + foreach ( void functionref() callback in file.onToolgunToolsInitCallbacks ) + callback() +} + +void function RegisterTool( ToolgunTool toolStruct ) +{ + file.tools.append( toolStruct ) +} + +void function CallToolOnEquipped( entity player, entity weapon ) +{ + #if CLIENT + if ( file.tools[ file.clientPlayerSettings.selectedToolIndex ].onEquipped != null ) + file.tools[ file.clientPlayerSettings.selectedToolIndex ].onEquipped( player, weapon ) + #endif // #if CLIENT + + #if SERVER + // set ammo and proscreen numbers when equipped + weapon.SetProScreenIntValForIndex( PRO_SCREEN_INT_LIFETIME_KILLS, file.playerSettings[ player.GetPlayerIndex() ].proscreenNumber ) + weapon.SetWeaponPrimaryClipCount( file.playerSettings[ player.GetPlayerIndex() ].ammoCount ) + + if ( file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onEquipped != null ) + file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onEquipped( player, weapon ) + #endif // #if SERVER +} + +void function CallToolOnUnequipped( entity player, entity weapon ) +{ + #if CLIENT + if ( file.tools[ file.clientPlayerSettings.selectedToolIndex ].onUnequipped != null ) + file.tools[ file.clientPlayerSettings.selectedToolIndex ].onUnequipped( player, weapon ) + #endif // #if CLIENT + + #if SERVER + if ( file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onUnequipped != null ) + file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onUnequipped( player, weapon ) + #endif // #if SERVER +} + +void function CallToolOnFired( entity player, entity weapon, WeaponPrimaryAttackParams attackParams ) +{ + #if CLIENT + if ( file.tools[ file.clientPlayerSettings.selectedToolIndex ].onFired != null ) + file.tools[ file.clientPlayerSettings.selectedToolIndex ].onFired( player, weapon, attackParams ) + #endif // #if CLIENT + + #if SERVER + // ammocount needs to be +1 because we lose 1 ammo immediately after this function is run + weapon.SetWeaponPrimaryClipCount( file.playerSettings[ player.GetPlayerIndex() ].ammoCount + 1 ) + + if ( file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onFired != null ) + file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onFired( player, weapon, attackParams ) + #endif // #if SERVER +} + +void function CallToolOnAds( entity player, entity weapon ) +{ + #if CLIENT + if ( file.tools[ file.clientPlayerSettings.selectedToolIndex ].onAds != null ) + file.tools[ file.clientPlayerSettings.selectedToolIndex ].onAds( player, weapon ) + #endif // #if CLIENT + + #if SERVER + if ( file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onUnequipped != null ) + file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onUnequipped( player, weapon ) + #endif // #if SERVER +} + +void function CallToolOnUnAds( entity player, entity weapon ) +{ + #if CLIENT + if ( file.tools[ file.clientPlayerSettings.selectedToolIndex ].onUnAds != null ) + file.tools[ file.clientPlayerSettings.selectedToolIndex ].onUnAds( player, weapon ) + #endif // #if CLIENT + + #if SERVER + if ( file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onUnequipped != null ) + file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onUnequipped( player, weapon ) + #endif // #if SERVER +} + +#if SERVER +void function InitialiseToolgunSettings( entity player ) +{ + print( "initialising toolgun settings for player " + player ) + + ToolgunPlayerSettings playerSettings + playerSettings.selectedToolIndex = 0 + + file.playerSettings[ player.GetPlayerIndex() ] <- playerSettings +} + +void function DestroyToolgunSettings( entity player ) +{ + delete file.playerSettings[ player.GetPlayerIndex() ] +} + +void function SetToolgunAmmoCount( entity player, int ammoCount ) +{ + entity currentWeapon = player.GetActiveWeapon() + if ( ammoCount > currentWeapon.GetWeaponPrimaryClipCountMax() ) // setting clipcount to over max clipcount crashes so we need to prevent that + return + + ToolgunPlayerSettings playerSettings = file.playerSettings[ player.GetPlayerIndex() ] + playerSettings.ammoCount = ammoCount + + if ( currentWeapon.GetWeaponClassName() == "mp_weapon_toolgun" ) // set ammocount immediately if we've got toolgun equipped already + currentWeapon.SetWeaponPrimaryClipCount( ammoCount ) +} + +void function SetToolgunProscreen( entity player, int proscreenNumber ) +{ + ToolgunPlayerSettings playerSettings = file.playerSettings[ player.GetPlayerIndex() ] + playerSettings.proscreenNumber = proscreenNumber + + if ( player.GetActiveWeapon().GetWeaponClassName() == "mp_weapon_toolgun" ) // set proscreen number immediately if we've got toolgun equipped already + player.GetActiveWeapon().SetProScreenIntValForIndex( PRO_SCREEN_INT_LIFETIME_KILLS, proscreenNumber ) +} +#endif // #if SERVER
\ No newline at end of file |