Jump to content

[HELP] gang invites


Dziugasc

Recommended Posts

So I got code  but  it doesn't work and when I  tested with  other player  it  didn't invited him.

Server:

Spoiler

function Invite(id)
	local team = getPlayerTeam ( source )
	local id = getElementData(source,"id")
	local player = (tonumber(id))
    	if team and player then
    		triggerClientEvent( player, "gang.invite", source, team )
    	end
end
addEvent( "onPlayerInvite", true )
addEventHandler( "onPlayerInvite", root, Invite )

 function InviteToGang( wasAccepted, inviter, team )
    	-- If we have a team element
    	if isElement( team ) then
    		-- If the invitation was accepted
    		if wasAccepted then
    			-- Set the player's team
    			setPlayerTeam( team )

    			-- Let the player know
    			outputChatBox( "You accepted the gang invitation.", client, 0, 255, 0 )

    		-- If the invitation was not accepted
    		else
    			-- Let the player know
    			outputChatBox( "You ignored the gang invitation.", client, 255, 0, 0 )
    		end
    	elseif wasAccepted then -- If the invite was accepted but we had no team element, let's say we don't have that team anymore
    		outputChatBox( "This gang does not exist.", client, 255, 0, 0 )
    	end
    end
addEvent( "onPlayerRespondedToInvite", true )
addEventHandler( "onPlayerRespondedToInvite", resourceRoot, InviteToGang )

Client:

Spoiler

addEvent( "gang.invite", true )
addEventHandler( "gang.invite", root, function( team )
    		if isElement( gangs.window["invite"] ) or not isElement( team ) then
    			return
    		end
			
    		gangs.inviter = source
    		gangs.team = team

    		gangs.window["invite"] = guiCreateWindow( 540, 636, 285, 91, "GANG INVITE", false )
    		guiWindowSetSizable( gangs.window["invite"], false )
    		guiSetAlpha( gangs.window["invite"], 0.72 )

    		gangs.label["invite"] = guiCreateLabel( 176, 64, 101, 18, "Press 'N' to reject", false, gangs.window["invite"] )
    		guiLabelSetHorizontalAlign( gangs.label["invite"], "center", false )

    		gangs.label["invite1"] = guiCreateLabel( 10, 17, 267, 21, getPlayerName ( gangs.inviter ) .. " has invited you to the gang '" .. getTeamName(gangs.team) .. "'", false, gangs.window["invite"] )
    		guiLabelSetHorizontalAlign( gangs.label["invite1"], "center", false )

    		gangs.label["invite2"] = guiCreateLabel( 10, 64, 113, 18, "Press 'J' to accept", false, gangs.window["invite"] )
    		guiLabelSetHorizontalAlign( gangs.label["invite2"], "center", false )
			
			addEventHandler("onClientKey", root, respondInvite)
end)

function cleanUp()
	if isElement( gangs.window["invite"] ) then
    	destroyElement(gangs.window["invite"])
    end
	gangs.inviter = nil
    gangs.team = nil
	removeEventHandler("onClientKey", root, respondInvite)
end

function respondInvite( key )
    if key == "j" then
    	triggerServerEvent( "onPlayerRespondedToInvite", localPlayer, true, gangs.inviter, gangs.team )
		cleanUp()
    elseif key == "n" then
    	triggerServerEvent( "onPlayerRespondedToInvite", localPlayer, false, gangs.inviter, gangs.team )
		cleanUp()
	end
end

 

Link to comment
37 minutes ago, TheMOG said:

debug?

no debugerror it just doesnt invite

GUIEditor.window[2] = guiCreateWindow(0.43, 0.39, 0.15, 0.11, "INVITE", true)
        guiWindowSetSizable(GUIEditor.window[2], false)
		guiSetVisible(GUIEditor.window[2],false)

        GUIEditor.button[10] = guiCreateButton(10, 59, 81, 18, "Invite", false, GUIEditor.window[2])
        GUIEditor.button[20] = guiCreateButton(112, 59, 80, 18, "Cancel", false, GUIEditor.window[2])
        GUIEditor.edit[10] = guiCreateEdit(94, 26, 98, 23, "11", false, GUIEditor.window[2])
        GUIEditor.label[10] = guiCreateLabel(66, 30, 18, 14, "ID:", false, GUIEditor.window[2])
        guiSetFont(GUIEditor.label[10], "default-bold-small")   
	elseif (source == GUIEditor.button[10]) then
					local id = guiGetText(GUIEditor.edit[10])
						if id ~= "" then
							triggerServerEvent( "onPlayerInvite", localPlayer, id)	
							guiSetVisible (GUIEditor.window[2], not guiGetVisible ( GUIEditor.window[2]	) )
							showCursor(false)
						end

 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...