Exp received

well i made an EXP system and i have to make a function were , when a person gets a kill they get some exp around 50 any help

I’d try **[Gamemode.PlayerDeath


[lua]function playerDies( victim, weapon, killer )

//Some code here to give the killer the Exp.


hook.Add( “PlayerDeath”, “playerDeathTest”, playerDies )[/lua]

“ExpGive” isn’t a valid hook name, **[Gamemode.PlayerDeath

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.PlayerDeath)** is the one you need, as Entoros has already said.

Better, I don’t have a clue why I did that :S.

ok so the code should be like this then

  1. function playerDies( victim, weapon, killer )
  2. ply:Add_PlayerExp(50)
  3. end
  4. hook.Add( “PlayerDeath”, “playerDeathTest”, playerDies )

Nope its.
[lua]function playerDies( victim, weapon, killer )


hook.Add( “PlayerDeath”, “playerDeathTest”, playerDies )[/lua]

snip - nvm

yes it is if you have the right codes for the exp


ummm im gettig an error when i try to get exp

Hook ‘playerDeathTest’ Failed: CODMW2/gamemode/init.lua:187: attempt to call method ‘Add_PlayerExp’ (a nil value)

ofcourse, you need to replace the add_playerexp function with the function that adds exp, i mean making code isnt copy/pasting what someone has proposed, but actually understanding it and being able to change it and debug it properly and fixing any bugs that might appear. i am not having a go at you, but it anoys me when someone wants somebody else to do something for them when its in newbie ** QUESTIONS ** otherwise just go ask in requests

Calm down dude. At least he’s trying to make an attempt to do it himself rather than going ‘give me code plzktxh’.

Maple, in Lua there’s a thing called metatables. Metatables allow you to make functions like add_playerexp that you can use on a player. Do do this, you would do something like this:

[lua]local meta = FindMetaTable( “Player” )

function meta:Add_PlayerExp( exp )
if not self.Exp then self.Exp = 0 end

self.Exp = self.Exp + exp


function meta:Get_PlayerExp( )
return self.Exp

“self” is the player object in the meta table. You can store variables on the player like that - it’s probably the best way to do an experience system or a money system.

i know im using it , just can’t figure out how to give exp to players when they get a kill

Your original code was right, but you never defined the Add_PlayerExp function. It should work now.