• Triggering a pay-day with an entity.
    5 replies, posted
I hate money printers. I'm trying to replace them on my server with a drug that causes an increased pay-day rate, so that people actually use drugs, but I'm having some trouble because I don't know too much about lua. I'm modifying the "Aspirin" drug from Durgz Mod to do this, renamed to "Prestige". When a player takes the drug, pl.durgz_prestige_used returns true for five minutes. During this time, I'm trying to get a timer to run my "DrugPayDay" function every minute. Here's how I tried to do that: [lua]function PayDayHigh() for id,pl in pairs(player.GetAll())do if not pl.durgz_prestige_used then return end if pl.durgz_prestige_used then timer.simple( 5, Self:DrugPayDay(), Self ) return end end end[/lua] The only part I'm fuzzy about is getting the actual DrugPayDay to work, because I don't know why I'm getting the below error: [ERROR] gamemodes/darkrp/entities/entities/durgz_prestige/init.lua:34: attempt to index global 'Self' (a nil value) 1. fn - gamemodes/darkrp/entities/entities/durgz_prestige/init.lua:34 2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183 I'm sure it's something obvious that I just don't understand, but I don't why the self global isn't working.
Replace [lua]Self[/lua] with [lua]pl[/lua] You only use self in [URL="http://nova-fusion.com/2011/06/30/lua-metatables-tutorial/"]metatables[/URL], you can see a more related example [URL="https://github.com/FPtje/DarkRP/blob/master/gamemode/shared/entity.lua"]here[/URL].
[QUOTE=KillerLUA;41762272]Replace [lua]Self[/lua] with [lua]pl[/lua] You only use self in [URL="http://nova-fusion.com/2011/06/30/lua-metatables-tutorial/"]metatables[/URL], you can see a more related example [URL="https://github.com/FPtje/DarkRP/blob/master/gamemode/shared/entity.lua"]here[/URL].[/QUOTE] That's wrong, you can use "self" everywhere, but if the function is declared as a method (using a colon) then it'll automatically assign "self" to the 1st argument (which means if you want to call said function you also need to either use the method operator (colon) or do something like "tbl.Function( tbl, arg1, arg2 )" )
May not technically be correct - but it's still useless outside of metatables.
You've clearly never heard of a singleton. [editline]8th August 2013[/editline] And you're still wrong, methods are useful on any kind of class whether it's done using metatables or not. Metatables are most commonly used though, but the are several other ways.
That all worked, thanks for the help.
Sorry, you need to Log In to post a reply to this thread.