• Running a command when a player Changes team.
    17 replies, posted
I'm editing DarkRp cause I'm bored right now and I've run into a bit on trouble. I want a menu to popup when the player becomes a Mayor. This is what I have so far [LUA] function GM:OnPlayerChangedTeam( ply, oldteam, newteam ) if ( newteam == TEAM_MAYOR ) then print("ItWorked") end end [/LUA] I didn't really change anything from the function from the wiki and ItWorkd doesn't show up and console and I am not getting any errors. Any help would be appreciated.
[lua]function TeamChanges( ply, oldteam, newteam ) if ( newteam == TEAM_MAYOR ) then print("ItWorked") end end hook.Add("OnPlayerChangedTeams", "TeamChangeHook", TeamChanges)[/lua] Top of my head.. sorry, Im still hungover from last night :b
Hmmm, ItWorked still doesn't show up in Console.
Have you enabled respawning on team change?
I've tried it with and without re-spawning on team change and it still doesn't work.
try this: [lua] function GM:OnPlayerChangedTeam( ply, oldteam, newteam ) print(TEAM_MAYOR, newteam) end [/lua] It will print 2 numbers to console, check if they are the same.
if you use GM:<Hookname> you will override the default gamemode hook and probably break a lot of things [lua] function fpopup(ply, oldteam, newteam) if newteam == TEAM_MAYOR then print("It fucking worked") end end hook.Add( "OnPlayerChangedTeam", "ShowPopup", fpopup ).[/lua] Your try and _nonsense try's are wrong because they used the GM table, rather then an hook Freze his try is wrong because he used OnPlayerChangedTeam[b]s[/b] instead of OnPlayerChangedTeam
[QUOTE] try this: function GM:OnPlayerChangedTeam( ply, oldteam, newteam ) print(TEAM_MAYOR, newteam) end It will print 2 numbers to console, check if they are the same. [/QUOTE] Didn't print anything.
[QUOTE=ColdFusion;27127055]if you use GM:<Hookname> you will override the default gamemode hook and probably break a lot of things [lua] function fpopup(ply, oldteam, newteam) if newteam == TEAM_MAYOR then <YOUR POPUP CODE HERE> end end hook.Add( "OnPlayerChangedTeam", "ShowPopup", fpopup ).[/lua][/QUOTE] If you are worried about overriding base gamemode functions it is better to just call the base function in your function, like so: [lua]function GM:OnPlayerChangedTeam(ply, oldteam, newteam) if newteam == TEAM_MAYOR then -- Do something end self.BaseClass.OnPlayerChangedTeam(self, ply, oldteam, newteam) end[/lua]
[QUOTE=ColdFusion;27127055]if you use GM:<Hookname> you will override the default gamemode hook and probably break a lot of things [lua] function fpopup(ply, oldteam, newteam) if newteam == TEAM_MAYOR then print("It fucking worked") end end hook.Add( "OnPlayerChangedTeam", "ShowPopup", fpopup ).[/lua] Your try and _nonsense try's are wrong because they used the GM table, rather then an hook Freze his try is wrong because he used OnPlayerChangedTeam[b]s[/b] instead of OnPlayerChangedTeam[/QUOTE] Doesn't seem to work.
With change team respawning enabled [lua] function StuffOnChangeTeam(ply) if ply:Team() == TEAM_MAYOR then print("itWorks") end end hook.Add("PlayerSpawn", "stuff", StuffOnChangeTeam) [/lua]
[QUOTE=MakeR;27127212] [lua]function GM:OnPlayerChangedTeam(ply, oldteam, newteam) if newteam == TEAM_MAYOR then -- Do something end self.BaseClass.OnPlayerChangedTeam(self, ply, oldteam, newteam) end[/lua][/QUOTE] I tried yours and it doesn't break the game mode, but it doesn't print anything when I change do something to print("test")
[QUOTE=Lua Noob;27127548]I tried yours and it doesn't break the game mode, but it doesn't print anything when I change do something to print("test")[/QUOTE] Try printing something outside of the if statement to check if the function is actually being called, if it is then print(newteam == TEAM_MAJOR) to see if they are actually changing to the major team.
[QUOTE=MakeR;27127596]Try printing something outside of the if statement to check if the function is actually being called, if it is then print(newteam == TEAM_MAJOR) to see if they are actually changing to the major team.[/QUOTE] I tried to print something before and after the If statement and I got nothing.
Then the function isn't even being called, have you got any addons that use the OnPlayerChangedTeam hook and is returning a value? Any return value will prevent any other OnPlayerChangedTeam hook and the gamemode function from running.
[QUOTE=MakeR;27129114]Then the function isn't even being called, have you got any addons that use the OnPlayerChangedTeam hook and is returning a value? Any return value will prevent any other OnPlayerChangedTeam hook and the gamemode function from running.[/QUOTE] No sir, the only addon I have is Luapad.
Does the gamemode you are editing have a GM.PlayerJoinTeam function? If so, can you paste the code here?
I did searched all the files and I couldn't find anything like that. And the Game mode I'm editing is DarkRp
Sorry, you need to Log In to post a reply to this thread.