General > Developers Corner

Hook giving winning team points

(1/2) > >>

Zmaster:
I found a Deathrun gamemode on Facepunch and I want to make a script that gives every player on the winning team of a round a certain amount of points for PointShop

I have the hook ready, I'm just not sure how to give the points to everyone on the team

Here's the function for giving points ply:PS_GivePoints(10)

And here's what I have so far

--- Code: ---if SERVER then
AddCSLuaFile() -- Send the file to the client.

hook.Add( "OnRoundSet", "DR Money", function( round, winner )

if round == ROUND_ENDING then

end

end )
end
--- End code ---

I would imagine that winner:PS_GivePoints(10) wouldn't work since winner would be a team and not the players on the team

Decicus:
OnRoundSet is a serverside hook. No need to do "AddCSLuaFile".

You could loop through players table using a "for" loop (with "player.GetAll()"), and then check if ply:Team() is the same as the "winner"-team.
Then after that, you can give the points using Player:PS_GivePoints(10).

I have the code ready which should work (I haven't played or done any deathrun stuff, so I'm not 100% sure), but if you'd like to give it a go yourself then you should try to use some of my tips (hope I didn't forget anything).

The code can be found here if you aren't able to do it yourself (I couldn't hide it in a spoiler or anything).

Zmaster:
Okay I'll try to figure it out using the info you gave me, thanks!

Zmaster:
Alright, here's the code I ended up using (thanks to Decicus)

--- Code: ---if SERVER then
        hook.Add( "OnRoundSet", "DR Money", function( round, winner )
                if round == ROUND_ENDING then
                        for _, ply in ipairs( player.GetAll() ) do
                                if ply:Team() == winner then   
                                        ply:PS_GivePoints( 25 )
                                end
if winner == TEAM_DEATH then
for k, ply in pairs( player.GetAll() ) do
ply:ChatPrint( "The Death team has been given 25 points for winning!" )
end
else
for k, ply in pairs( player.GetAll() ) do
ply:ChatPrint( "The Runner team has been given 25 points for winning!" )
end
end
                        end
                end
        end )
end
--- End code ---

And it works fine
However, when the round ends and it puts one of those messages in chat, it'll usually put it in twice (and sometimes three times) instead of just once
How would I make it put in that message only once?


Edit: The code shown in this post isn't making "The 2 team" anymore, that screenshot was made before I changed it to say Runner or Death

Decicus:
You included your if/else statement inside the first for loop. Thus it printed to everyone, then looped again to print another time.
It's a bit difficult to explain, so I'll just do this:

--- Code: ---if SERVER then
        hook.Add( "OnRoundSet", "DR Money", function( round, winner )
                if round == ROUND_ENDING then
                        for _, ply in ipairs( player.GetAll() ) do
                                if ply:Team() == winner then   
                                        ply:PS_GivePoints( 25 )
                                end
                                -- Your print code is here.
                        end
                        -- It should be here
                end
        end )
end

--- End code ---

Also, I don't know if it was just the code tags, but you should probably work on your tabs/spaces for each line. The chatprinting code was a bit hard to read for me without putting it into Notepad++.

Navigation

[0] Message Index

[#] Next page

Go to full version