-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NPCs and players can now drop rupees on death (configurable) Original release date: 18 December 2017
- Loading branch information
LeoLuxo
authored
Apr 27, 2020
1 parent
787aac7
commit fe49112
Showing
13 changed files
with
125 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
hook.Add( "PopulateToolMenu", "CustomMenuSettings", function() | ||
spawnmenu.AddToolMenuOption( "Options", "Stuff", "functional_rupees", "Functional Rupees", "", "", function( panel ) | ||
panel:CheckBox( "Spawn rupees on NPC death", "gmod_functional_rupees_spawn_npc" ) | ||
panel:CheckBox( "Spawn rupees on player death", "gmod_functional_rupees_spawn_player" ) | ||
|
||
panel:Help( "" ) | ||
|
||
panel:NumSlider( "Despawn time in secs", "gmod_functional_rupees_despawn", 0, 60, 0 ) | ||
panel:Help( "(set to 0 to never despawn)" ) | ||
|
||
panel:Help( "" ) | ||
|
||
panel:NumSlider( "Rupee value multiplier", "gmod_functional_rupees_value_mul", 0, 10 ) | ||
end ) | ||
end ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
local function NPCDeath( npc, attacker, inflictor ) | ||
if ( GetConVar( "gmod_functional_rupees_spawn_npc" ):GetBool() ) then | ||
SpawnRupees( npc:GetPos(), npc:GetMaxHealth() ) | ||
end | ||
end | ||
|
||
local function PlayerDeath( player, attacker, inflictor) | ||
if ( GetConVar( "gmod_functional_rupees_spawn_player" ):GetBool() ) then | ||
SpawnRupees( player:GetPos(), player:GetMaxHealth() ) | ||
end | ||
end | ||
|
||
function SpawnRupees( pos, value ) | ||
pos.z = pos.z + 20 | ||
|
||
local valuemul = GetConVar( "gmod_functional_rupees_value_mul" ):GetFloat() | ||
|
||
value = math.floor(value * valuemul) | ||
|
||
gre = (((value % 300) % 100) % 20) % 5 | ||
blu = ((((value - gre) % 300) % 100) % 20) / 5 | ||
red = (((value - (blu * 5) - gre) % 300) % 100) / 20 | ||
sil = ((value - (red * 20) - (blu * 5) - gre) % 300) / 100 | ||
gol = (value - (sil * 100) - (red * 20) - (blu * 5) - gre) / 300 | ||
|
||
for i=1,gre do | ||
SpawnSingleRupee( 1, pos ) | ||
end | ||
for i=1,blu do | ||
SpawnSingleRupee( 2, pos ) | ||
end | ||
for i=1,red do | ||
SpawnSingleRupee( 3, pos ) | ||
end | ||
for i=1,sil do | ||
SpawnSingleRupee( 4, pos ) | ||
end | ||
for i=1,gol do | ||
SpawnSingleRupee( 5, pos ) | ||
end | ||
end | ||
|
||
function SpawnSingleRupee( rupeetype, pos ) | ||
pos.x = pos.x + math.random( -20, 20) | ||
pos.y = pos.y + math.random( -20, 20) | ||
|
||
typestring = "" | ||
|
||
if rupeetype == 1 then | ||
typestring = "green_rupee" | ||
elseif rupeetype == 2 then | ||
typestring = "blue_rupee" | ||
elseif rupeetype == 3 then | ||
typestring = "red_rupee" | ||
elseif rupeetype == 4 then | ||
typestring = "silver_rupee" | ||
elseif rupeetype == 5 then | ||
typestring = "gold_rupee" | ||
else | ||
return | ||
end | ||
|
||
local rupee = ents.Create( typestring ) | ||
|
||
if ( IsValid( rupee ) ) then | ||
rupee:SetPos( pos ) | ||
rupee:SetAngles( Angle( math.random( 360 ), math.random( 360 ), math.random( 360 ) ) ) | ||
rupee:Spawn() | ||
rupee:PhysWake() | ||
rupee:EmitSound( "rupeespawn" .. math.random( 1, 5 ) .. ".wav") | ||
|
||
local despawntime = GetConVar( "gmod_functional_rupees_despawn" ):GetFloat() | ||
|
||
if (despawntime > 0) then | ||
timer.Simple( despawntime, function() | ||
if ( IsValid( rupee ) ) then | ||
FadeOutRupee( rupee, 50, 0.08 ) | ||
end | ||
end ) | ||
end | ||
end | ||
end | ||
|
||
function FadeOutRupee( rupee, retry, speed ) | ||
c = rupee:GetColor() | ||
rupee:SetRenderMode( RENDERMODE_TRANSALPHA ) | ||
|
||
rupee:SetColor( Color( c.r, c.g, c.b, (retry % 2) * 255 ) ) | ||
|
||
timer.Simple( speed, function() | ||
if ( IsValid( rupee ) ) then | ||
if ( retry > 0 ) then | ||
if ( speed > 0.02 ) then | ||
FadeOutRupee( rupee, retry - 1, speed - 0.002 ) | ||
else | ||
FadeOutRupee( rupee, retry - 1, 0.02 ) | ||
end | ||
else | ||
rupee:Remove() | ||
end | ||
end | ||
end ) | ||
end | ||
|
||
hook.Add( "OnNPCKilled", "functional_rupees_npc", NPCDeath ) | ||
hook.Add( "PlayerDeath", "functional_rupees_player", PlayerDeath ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CreateConVar( "gmod_functional_rupees_spawn_npc", "0", FCVAR_ARCHIVE, "Defines if rupees spawn when an npc dies") | ||
CreateConVar( "gmod_functional_rupees_spawn_player", "0", FCVAR_ARCHIVE, "Defines if rupees spawn when a player dies") | ||
CreateConVar( "gmod_functional_rupees_despawn", "10", FCVAR_ARCHIVE, "Defines after how much time a spawned rupee will despawn") | ||
CreateConVar( "gmod_functional_rupees_value_mul", "1", FCVAR_ARCHIVE, "Defines how many rupees will spawn depending on the NPC/player's max health") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ VertexlitGeneric | |
$basetexture models/blue_rupee/blue_rupee.vtf | ||
$surfaceprop glassbottle | ||
$model 1 | ||
$alphatest 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ VertexlitGeneric | |
$basetexture models/gold_rupee/gold_rupee.vtf | ||
$surfaceprop glassbottle | ||
$model 1 | ||
$alphatest 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ VertexlitGeneric | |
$basetexture models/green_rupee/green_rupee.vtf | ||
$surfaceprop glassbottle | ||
$model 1 | ||
$alphatest 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ VertexlitGeneric | |
$basetexture models/red_rupee/red_rupee.vtf | ||
$surfaceprop glassbottle | ||
$model 1 | ||
$alphatest 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.