Automatically give $50 RP cash when you kill someone
15 replies, posted
I had a go my self... but i'm shit at lua, so I gave up... Is there anyone who can do this? It sounds pretty simple... but is it? :O
(running DarkRP 2.5)
You're right, it's incredibly simple:
[lua]hook.Add( "PlayerDeath", "GiveMoney", function( vic, inf, att )
if not att:IsPlayer() or att == vic then return end -- if the attacker isn't a player or the attacker is also the victim we don't want to do this
att:addMoney( 50 ) -- Otherwise continue and give them $50
end )[/lua]
[editline]18th April 2014[/editline]
Oh, I forgot to mention, drop this in lua/autorun/server
I don't know the method to give money, so just edit the code and put it in the if statement.
[code]function MoneyDeath( victim, inflictor, attacker )
if ( victim ~= attacker and attacker:IsPlayer() ) then
-- give 50 attacker
end
end
hook.Add( "PlayerDeath", "MoneyDeath", MoneyDeath )
[/code]
[QUOTE=Internet1001;44579148]You're right, it's incredibly simple:
[lua]hook.Add( "PlayerDeath", "GiveMoney", function( vic, inf, att )
if not att:IsPlayer() and not att == vic then return end -- if the attacker isn't a player or the attacker is also the victim we don't want to do this
att:addMoney( 50 ) -- Otherwise continue and give them $50
end )[/lua]
[editline]18th April 2014[/editline]
Oh, I forgot to mention, drop this in lua/autorun/server[/QUOTE]
So will this one not give you money if you kill yourself?
both have the killing yourself exception.
[QUOTE=WolfNinja2;44579202]both have the killing yourself exception.[/QUOTE]
I just tested them out D: Evertime that I kill myself or generally die, I get $50... :(
Bugger it's meant to be [b]or[/b]. Corrected.
-snip, I should go to sleep-
thanks!
To add in code to ensure that you can't just jump off a roof, etc:
When we add a hook, we only want to return when we want to cancel out other hooks. When specifying some behavior to happen, we use an if then end, don't return and don't do anything outside of the if.
[lua]hook.Add( "PlayerDeath", "PlayerDeath:RewardKill", function( _victim, _inflictor, _attacker )
// Make sure victim and attacker are both valid entities
// Make sure both victim and attacker are players
// and make sure that the victim and attacker are not the same person
// If we didn't check that both entities were player, we'd need to do something like && _attacker != game.GetWorld( ) && _inflictor != game.GetWorld( ) to ensure that it isn't a world entity that is doing damage..
if ( IsValid( _victim ) && IsValid( _attacker ) && _victim:IsPlayer( ) && _attacker:IsPlayer( ) && _victim != _attacker ) then
// Give money
_attacker:GiveMoney( 50 ); -- Your function may be different...
end
end );[/lua]
[QUOTE=Acecool;44594998]To add in code to ensure that you can't just jump off a roof, etc:
When we add a hook, we only want to return when we want to cancel out other hooks. When specifying some behavior to happen, we use an if then end, don't return and don't do anything outside of the if.
[lua]hook.Add( "PlayerDeath", "PlayerDeath:RewardKill", function( _victim, _inflictor, _attacker )
// Make sure victim and attacker are both valid entities
// Make sure both victim and attacker are players
// and make sure that the victim and attacker are not the same person
// If we didn't check that both entities were player, we'd need to do something like && _attacker != game.GetWorld( ) && _inflictor != game.GetWorld( ) to ensure that it isn't a world entity that is doing damage..
if ( IsValid( _victim ) && IsValid( _attacker ) && _victim:IsPlayer( ) && _attacker:IsPlayer( ) && _victim != _attacker ) then
// Give money
_attacker:GiveMoney( 50 ); -- Your function may be different...
end
end );[/lua][/QUOTE]
Didn't bitwise operators get removed?
[QUOTE=Coffeee;44595122]Didn't bitwise operators get removed?[/QUOTE]
They were replaced with bit.* And besides, those aren't bitwise operators.
[QUOTE=Coffeee;44595122]Didn't bitwise operators get removed?[/QUOTE]
Eh?? Garry extended the BNF to add certain C style operators such as !, !=, &&, ||, continue, etc...
[QUOTE=Acecool;44595714]Eh?? Garry extended the BNF to add certain C style operators such as !, !=, &&, ||, continue, etc...[/QUOTE]
There were some bitwise operators, like | and &, but they were removed when we got useless LuaJIT.
Oh good, add a feature that makes DarkRP even worse than it already is.
rdm.Start()
Sorry, you need to Log In to post a reply to this thread.