wiremod / advduplicator

Garry's Mod add-on that allows a player to save and load contraptions
http://www.wiremod.com
Apache License 2.0
67 stars 43 forks source link

Suggestion: Hook when player is pasting a dupe #57

Closed d-kuen closed 10 years ago

d-kuen commented 10 years ago

Hey guys!

I searched for a way how to change a variable when a player is pasting a dupe. I looked into the code and searched for hooks or tried to replace functions and then the old function again, but nothing of that really worked. Also I don't like to replace existing functions.

I saw that there is already a hook when a player pasted a dupe, but not if a player started to paste one.

It would be awesome if you can add a little hook after the left-click to paste a dupe or whereever you want to run it.

Thank you!

d-kuen commented 10 years ago

I don't know how you're thinking about it but I would appreciate that very much.

Do you prefer that I make a pullrequest or not?

Divran commented 10 years ago

Well technically you could do this

local old = AdvDupe.OverTimePasteStart
function AdvDupe.OverTimePasteStart( ... )
    -- stuff
    old( ... )
end

and the same for AdvDupe.Paste

d-kuen commented 10 years ago

Hmm, as I said in my first comment, replacing functions didn't work very well, but I will try it again. Thanks!

AbigailBuccaneer commented 10 years ago

@Domii894 a pull request adding a hook would be ideal :)

d-kuen commented 10 years ago

@AbigailBuccaneer Ok, I will do ^^

d-kuen commented 10 years ago

Ok, after some testing I came to that point:

Adding a hook when a player began to paste a dupe is easy, because I can get the player from the arguments.

Adding a hook when a player finished to paste a dupe is a bit harder, because I don't get the player from the arguments or from somewhere else. Anyway I got the player out with:

TimedPasteData[1].Player

But in my opinion this is a bad way to get the player. Do you have a better idea for me?

Divran commented 10 years ago

the finished pasting hook already exists, 2 lines below the line you linked. did you not see it? https://github.com/wiremod/advduplicator/blob/master/lua/autorun/server/advdupe.lua#L2379

d-kuen commented 10 years ago

Yes I noticed this hook, but it doesn't contain the player who pasted the dupe, right? Or how can I get him?

Divran commented 10 years ago

this is how to get the player https://github.com/wiremod/advduplicator/blob/master/lua/autorun/server/advdupe.lua#L2385

d-kuen commented 10 years ago

Oh ok, thank you very much! I will make a pullrequest soon

d-kuen commented 10 years ago

I just made a pull request. I hope that I did a good job with it and also hope that I can use it soon ;)

Thank you guys for helping me!

Here is the link to the pull request: https://github.com/wiremod/advduplicator/pull/58

d-kuen commented 10 years ago

First I want to say thank you again for merging the pull request.

But may I can annoy you for one last time?

Will you update the workshop version too? I saw that the last update was on 18.8.2013, so there are also some other commits (4) which can be patched to the workshop version. Also I can be sure, that everyone has the current version and is able to use this new hook.

AbigailBuccaneer commented 10 years ago

somebody administrate-y needs to do that, I don't think it's automatically built from a workshop branch. @FaronFox @Anticept who is in charge of this, I can never remember

AbigailBuccaneer commented 10 years ago

oh wait there is a workshop branch so presumably it is auto-built from that. #60

d-kuen commented 10 years ago

Ok thank you again for your help!