Trying to figure out one thing, for 2.5.1 server. Not going as good as i'd hoped. :c

So, i’m still learning code, and how to open and close, but i’m still fairly new to DARKRP 2.5.1 in general.

The idea is to create a TEAM_ in darkRP that is the sole benefit to one simple thing.
Each time they kill someone with a knife, they get payed 50 bucks RP money.

First off.



wep:GetClass() == "weapon_Knife"


,

GM:PLAYERDEATH



function GM:PlayerDeath( victim, inflictor, attacker )
if ( victim == attacker ) then
PrintMessage( HUD_PRINTTALK, victim:Name() .. " committed suicide." )
else
PrintMessage( HUD_PRINTTALK, victim:Name() .. " was killed by " .. attacker:Name() .. "." )
end
end


and


Player:addMoney( number amount )

Again I have two problems.
I’m not sure how to throw the code together to make it work.
I run a 2.5.1 server…

and the second problem is which .lua to edit.
as … again… I run a 2.5.1 server…

Its a lot different then 2.4.3 and i don’t want to downgrade. I’d like to face the issue. I think a lot of people duck and hide,
and well… i just want to find an answer to one thing.

If you use hook.Add() instead of overriding the hook in general, you can make a totally separate file for it, thus making it still SVN-updatable.

  1. How would i Piece it all together? The PlayerDeath that i posted isn’t what i plan to use, but its the correct format in how it is used. I just posted it as an exaple. I just don’t know how to modify the example to bend towards what it is I’d like to achieve. 2. where would i store the .lua when i find these answers?

[editline]20th March 2014[/editline]

I’ve been trying to figure it out for 5 days. :c

  1. When solving a problem, you’ll want to establish exactly what the problem is and how you want to tackle it, in a step by step fashion. In this case you’ll want;

Listen for when a player dies (using a hook look at the second example)
If the player that killed(killer), was on the team you want to reward AND the weapon’s class (inflictor) is equal to the weapon_knife then (If statment)
Reward the killer $50 ( killer:addMoney( 50) )

  1. For this kinda thing, put it in lua/autorun/server and name it whatever you like .lua, because this is server side code.

Hope this helps.

O.O This is a huge help, but how would would i imply “and” to include Team, with knife. would i just assume to use a comma? and if so, seing as it’d involve to If’s would it be within {} brackets?

I also like that ElseIf, i assume i’d use that say… if i wanted it to work for more then one type of weapon use scenario, eh?

You can literally use the word and. For example:
[lua]
if true and true then
print(“Both True!”)
end
[/lua]

Also judging by your questions, I don’t think you know enough lua syntax yet. You should probably read up on it.

I own a server, and am stubborn but very intelligent. I messed a little with LUA code awhile back and understand i’m a huge novice, but i retain what i learn. You already have given me great tools in understanding what i’m looking to achieve, i’m not just copying it down, i’m… trying to learn. I know the above example may not be correct exaxtly, but i am reading what your explaining. I know first instinct is for you to likely tell me “go away noob” but… if i learn this, it brings me a step closer to learning faster.

You definitely don’t know enough syntax. Please read up on the wiki.

I think I will, later… for now, i’m trying to solve ONE thing, while i learn. You’ve been very helpful.
I’ll take all this information I’ve learned, and go elsewhere to find the last of this answer.
while i wait for a reply elsewhere, i’ll be sure to look up on wiki like you suggested, but know that for now, my big concern is just this one thing.

I’m sure i’m much too inexperienced for you to bother, thanks for showing me the door.


function GM:PlayerDeath( victim, inflictor, attacker )
if ( inflictor = Weapon_Knife, attacker = TEAM_SNEAKSIN ) then
PrintMessage( HUD_PRINTTALK, victim:Name() .. " has died, mysteriously!" ),
killer:addMoney( 50)
else
PrintMessage( HUD_PRINTTALK, victim:Name() .. " was killed by " .. attacker:Name() .. "." )
end
end

or is this what i was supposed to put. shit, all i want to do is understand man. Force me to go read or tell me now, i think the ladder would teach me, and when i go read, i’ll have twice the understanding. I can be like “oh… wow, now wonder.”

If you don’t know how to walk, how do you expect to run? You need to understand the basics. Read this helpful post by Code_Gs.

As for the code, its horribly wrong. This is how it should look:

[lua]
–Using a hook so you don’t override default functions
hook.Add(“PlayerDeath”,“reward_team_sneaksin”,function(victim, inflictor, killer)
–If the class of the weapon is equal to “Weapon_knife” AND the killer’s team is equal to the team we want to reward AND the killer is valid then…
if inflictor:GetClass() == “WEAPON_KNIFE” and killer:Team() == TEAM_SNEAKSIN and killer:IsValid() then
PrintMessage( HUD_PRINTTALK, victim:Name() … " has died, mysteriously!" ),
killer:addMoney( 50 )
else
–This line isn’t really needed.
–PrintMessage( HUD_PRINTTALK, victim:Name() … " was killed by " … killer:Name() … “.” )
end
end)
[/lua]

I’m a stubborn learner! lol. But thank you. Also, you’ve provided me with a lot of homework. I can tell there’s a lot I didn’t understand before from reading this, and i know what it is i’ll be reading up on today.
I do appreciate your patience. thank you for the – lines, they help me gain a bit of perspective, and i can’t say I regret coming here first. yes i know… that makes me annoying. :stuck_out_tongue: