MTA.Castiel Posted March 23, 2023 Share Posted March 23, 2023 Hi there, I'm trying to trigger a client side event for every team player but excluding myself, within the team. I've tried a bunch of things, can't seem to figure it out at this point. The code we're using today is only intended for test purposes. Our client event "runOurClientEvent" is currently being triggered for everyone in the team, including myself. function teamChatZm( message, messageType ) local thePlayer = getPlayerName( source ) if messageType == 2 then -- Teamsay local playerTeam = getPlayerTeam( source ) if ( playerTeam ) then local teamPlayers = getPlayersInTeam( playerTeam ) cancelEvent() outputChatBox( "*Message type: " .. messageType .. " from: " .. thePlayer ) outputChatBox( "Castiel has triggered a client side event.", teamPlayers, 0, 255, 0, true ) -- trigger an event for the other team players only if ( teamPlayers[source] == source ) then return else triggerClientEvent ( "runOurClientEvent", root ) end end end end addEventHandler("onPlayerChat", root, teamChatZm) Link to comment
Moderators IIYAMA Posted March 23, 2023 Moderators Share Posted March 23, 2023 2 hours ago, MTA.Castiel said: Our client event "runOurClientEvent" is currently being triggered for everyone in the team, including myself. Try this: triggerClientEvent ( (function () local players = getElementsByType("player") for i=1, #players do if players[i] == source then table.remove(players, i) break end end return players end)(), -- IIFE (Immediately Invoked Function Expression) "runOurClientEvent", root ) 1 Link to comment
AngelAlpha Posted March 24, 2023 Share Posted March 24, 2023 function teamChatZm( message, messageType ) local thePlayer = getPlayerName( source ) if messageType == 2 then -- Teamsay local playerTeam = getPlayerTeam( source ) if ( playerTeam ) then local teamPlayers = getPlayersInTeam( playerTeam ) cancelEvent() outputChatBox( "*Message type: " .. messageType .. " from: " .. thePlayer ) outputChatBox( "Castiel has triggered a client side event.", teamPlayers, 0, 255, 0, true ) for i, v in ipairs (teamPlayers) do if v ~= source then triggerClientEvent (v, "runOurClientEvent", root ) end end end end end addEventHandler("onPlayerChat", root, teamChatZm) try this code Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now