Give player money when cross finish line

How would I give the player money when they cross a finish line I put in a map? Would I make an entity or what? If you need any more info, tell me.

I’m not sure what the best way to do it is, but look at my hilarious way to solve this problem:

A box that hurts your player by 1. Name it something.

Then in your gamemode you hook PlayerHurt to check the name of the attacker, and if it was that hurting box from the map.

It would work. Though it doesn’t look nice.

You could also try to trigger a lua_run in the map and call a hook.

If I did a lua_run in the map, how would I call the hook in the gamemode? Is there a certain hook to use? Or…

This exactly. Either call a hook in lua_run or trigger a SENT which you will define in lua.

Just hook.Call.

Is there a certain hook I would use? If so, what is it?

Like thejjokerr said call a custom hook using hook.Call. You can name if “PlayerCrossedFinishLine” if you want. Make sure to supply the player as an argument. In your gamemode you would use hook.Add to access it, or GM: if you called the hook as part of the gamemode table.

and this:

http://www.facepunch.com/showpost.php?p=21613144&postcount=2

The last link will answer all your questions.

So, tell me if this is right:

I create a hook in init that gives the player money. Then I create a lua.run in the map and do hook.Call( “Hook name” )?

Yes.

  • Here’s an example:

Put this in your lua_run:
[lua]if ValidEntity(TRIGGER_PLAYER) then hook.Call( “PlayerCrossFinishLine”, nil, TRIGGER_PLAYER) end[/lua]

Then go to your “init.lua” or another server side file and enter this:
[lua]hook.Add(“PlaerCrossFinishLine”, function(player)
player:GiveMoney( 1000000 )
end)[/lua]

All you have to do now is make a GiveMoney function :stuck_out_tongue_winking_eye:

EDIT: Before I forget, you can trigger the lua_run using logic and trigger entities, so put that on your finish line.

Thanks thejjoker, I will try that when it comes time.