Skip to content

Commit

Permalink
Add rupee drop features
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 5 deletions.
15 changes: 15 additions & 0 deletions lua/autorun/client/cl_functional_rupees.lua
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 )
106 changes: 106 additions & 0 deletions lua/autorun/functional_rupees.lua
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 )
4 changes: 4 additions & 0 deletions lua/autorun/server/sv_functional_rupees.lua
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")
1 change: 0 additions & 1 deletion materials/models/blue_rupee/blue_rupee.vmt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ VertexlitGeneric
$basetexture models/blue_rupee/blue_rupee.vtf
$surfaceprop glassbottle
$model 1
$alphatest 1
}
1 change: 0 additions & 1 deletion materials/models/gold_rupee/gold_rupee.vmt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ VertexlitGeneric
$basetexture models/gold_rupee/gold_rupee.vtf
$surfaceprop glassbottle
$model 1
$alphatest 1
}
1 change: 0 additions & 1 deletion materials/models/green_rupee/green_rupee.vmt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ VertexlitGeneric
$basetexture models/green_rupee/green_rupee.vtf
$surfaceprop glassbottle
$model 1
$alphatest 1
}
1 change: 0 additions & 1 deletion materials/models/red_rupee/red_rupee.vmt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ VertexlitGeneric
$basetexture models/red_rupee/red_rupee.vtf
$surfaceprop glassbottle
$model 1
$alphatest 1
}
1 change: 0 additions & 1 deletion materials/models/silver_rupee/silver_rupee.vmt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ VertexlitGeneric
$basetexture models/silver_rupee/silver_rupee.vtf
$surfaceprop glassbottle
$model 1
$alphatest 1
}
Binary file added sound/rupeespawn1.wav
Binary file not shown.
Binary file added sound/rupeespawn2.wav
Binary file not shown.
Binary file added sound/rupeespawn3.wav
Binary file not shown.
Binary file added sound/rupeespawn4.wav
Binary file not shown.
Binary file added sound/rupeespawn5.wav
Binary file not shown.

0 comments on commit fe49112

Please sign in to comment.