So I am working on a pickpocket swep right now for a dark rp server, and I am having trouble figuring out how to make it so it REFUNDS the money to the players that I stole, when I die, whether that be suicide or that player killing me. Also how would I make it so that would only be true for lets say 1 minute then if they kill me after 1 minute, they don't get a refund. Of course I need it so I can keep pickpocketing money from people and they only have a minute to get it back or else its mine forever. here is the pastebin to the script, note I don't want it to refund weapons if stolen, that is also part of the swep that I have disabled. [URL="http://pastebin.com/GaUEJU2u"]http://pastebin.com/GaUEJU2u[/URL]
Bumpperoni pizza
[url]http://wiki.garrysmod.com/page/GM/PlayerDeath[/url]
[code]
target:addMoney( -money )
self.Owner:addMoney( money )
[/code]
[url]http://wiki.garrysmod.com/page/timer/Create[/url]
[url]http://wiki.garrysmod.com/page/timer/Exists[/url]
Everything you need right there
[QUOTE=dankthetank;51099926]So I am working on a pickpocket swep right now for a dark rp server[/QUOTE]
I'm pretty sure that's [URL="https://scriptfodder.com/scripts/view/17/money-weapon-pickpocket-swep"]scriptfodder script[/URL].
[QUOTE=Blinkenn;51102349][url]http://wiki.garrysmod.com/page/GM/PlayerDeath[/url]
[code]
target:addMoney( -money )
self.Owner:addMoney( money )
[/code]
[url]http://wiki.garrysmod.com/page/timer/Create[/url]
[url]http://wiki.garrysmod.com/page/timer/Exists[/url]
Everything you need right there[/QUOTE]
I still have no idea what to do, I feel like ive tried everything
Create a function and connect it to a gm playerdeath hook
after pickpocket create a minute timer on the player
if the player's timer still exists on death, give back the money
try that.
[QUOTE=Blinkenn;51116223]Create a function and connect it to a gm playerdeath hook
after pickpocket create a minute timer on the player
if the player's timer still exists on death, give back the money
try that.[/QUOTE]
I made this code but it isnt working right, please tell me if somethings wrong
function Refund()
local refundMoney = hook.Call( "PlayerDeath" )
if refundMoney then
target:addMoney( money )
self.Owner:addMoney( -money )
else
target:AddMoney( money )
self.Owner:AddMoney( -money )
end
end
function playerDies( victim, inflictor, killer )
if ( victim == killer ) then
killer:MultiversionNotify(NOTIFY_ERROR, "Your money was refunded!")
end
end
hook.Add( "PlayerDeath", "Death Test", playerDies )
Refund()
[QUOTE=dankthetank;51120080]I made this code but it isnt working right, please tell me if somethings wrong
function Refund()
local refundMoney = hook.Call( "PlayerDeath" )
if refundMoney then
target:addMoney( money )
self.Owner:addMoney( -money )
else
target:AddMoney( money )
self.Owner:AddMoney( -money )
end
end
function playerDies( victim, inflictor, killer )
if ( victim == killer ) then
killer:MultiversionNotify(NOTIFY_ERROR, "Your money was refunded!")
end
end
hook.Add( "PlayerDeath", "Death Test", playerDies )
Refund()[/QUOTE]
Are there any errors?
[QUOTE=Fresh~;51120167]Are there any errors?[/QUOTE]
[ERROR] lua/ulx/modules/sh/fun.lua:160: attempt to index local 'ply' (a nil value)
1. fn - lua/ulx/modules/sh/fun.lua:160
2. Call - lua/ulib/shared/hook.lua:110
3. Refund - addons/pickpocket swep/lua/weapons/swep_pickpocket.lua:246
4. unknown - addons/pickpocket swep/lua/weapons/swep_pickpocket.lua:265
but when I remove the code i made that error goes away
Of course because ply isnt defined
[QUOTE=Keosan;51120313]Of course because ply isnt defined[/QUOTE]
where would I define ply ?
--snip--
Woo just got on my computer sorry, dont use that.
[QUOTE=Fresh~;51120364][code]
function deathTimer( victim, killer )
if ( victim != killer ) then
timer.Create( "MoneyTimer", 64, 1, function(target, killer) if killer:Alive() then target:addMoney( money ) end end )
end
end
hook.Add( "PlayerDeath", "MoneyRefund", deathTimer )
[/code]
Try that
--edit--
im on my phone[/QUOTE]
ok thank you! where would I put this in regards to my actual code, right now its at very bottom and I get no errors but nothing really happens, and do I use my code from above? sorry for me being so difficult
[QUOTE=dankthetank;51120424]ok thank you! where would I put this in regards to my actual code, right now its at very bottom and I get no errors but nothing really happens, and do I use my code from above? sorry for me being so difficult[/QUOTE]
didnt realise what i wrote yeah dont use my code.. just got on my computer ill test something now
[QUOTE=Fresh~;51120454]didnt realise what i wrote yeah dont use my code.. just got on my computer ill test something now[/QUOTE]
add my steam if u want it might make things easier to send me [URL="http://steamcommunity.com/profiles/76561198041387148/"]http://steamcommunity.com/profiles/76561198041387148/[/URL]
Sorry, you need to Log In to post a reply to this thread.