Moderators Citizen Posted March 8, 2014 Moderators Share Posted March 8, 2014 Thanks man its working Alright, nice to see I didn't make mistake in that system. Please read the code and try to understand what's going on there. If there is something that you aren't really sure about what is it for, please ask here. Link to comment
Anubhav Posted March 8, 2014 Share Posted March 8, 2014 addEventHandler ( "onResourceStart", resourceRoot, function ( ) for _, player in ipairs ( getElementsByType ( "player" ) ) do -- Loop all the players. bindKey ( player, "U", "down", "chatbox", "gangChat" ) -- Bind the key "U" to the "GangChat" command. end end ) addEventHandler ( "onPlayerJoin", root, function ( ) bindKey ( source, "U", "down", "chatbox", "gangChat" ) -- Bind the key "U" to the "GangChat" command. end ) function gangChat ( thePlayer, _, ... ) local isInvited = getElementData ( thePlayer, "invited" ) or false if ( isInvited ) then local text = table.concat ( { ... }, " " ) if ( #text > 0 ) then outputChatBox ("#FF32AA (GANG) "..getPlayerName(thePlayer)..": #FFFFFF" ..text, thePlayer, 255, 255, 255, true ) end end end addCommandHandler ( "gangChat", gangChat ) function invitePlayer ( thePlayer, _, playerName ) if not playerName then return end local playerToInvite = getPlayerFromName(playerName) if ( isElement ( playerToInvite ) ) and getElementType( argument ) == "player" then setElementData ( playerToInvite, "invited", true ) outputChatBox ( "You have been invited to the chat.", playerToInvite) else outputChatBox ( "There is no such a player!", thePlayer ) end end addCommandHandler ( "invite", invitePlayer ) If he would type any element then it will accept it. It must be player. Link to comment
-.Paradox.- Posted March 10, 2014 Author Share Posted March 10, 2014 Sorry, one thing, is there a way to make this? When i invite a player to gang Chat it automatically add me and him in the chat, thanks. Link to comment
Moderators Citizen Posted March 10, 2014 Moderators Share Posted March 10, 2014 Which script are you using ? Link to comment
-.Paradox.- Posted March 10, 2014 Author Share Posted March 10, 2014 You don't want to use other resources but you can't do it yourself either even after we told you the main idea and the functions you would have to use.Learn to script simple stuff first. Check the Introduction to Scripting available on the wiki main page. function createGang( thePlayer, cmd, gngName ) if not thePlayer or not cmd then return end if not gngName then return outputChatBox("SYNTAX: /createGang ") end if getElementData(thePlayer, "gang") then return outputChatBox("You are already in a gang. Do /leaveGang to leave it.", thePlayer) end if isGangAlreadyExist(gngName) then return outputChatBox("The gang "..gngName.." already exist !", thePlayer) end local newGang = createElement("gang") setElementData(newGang, "name", gngName) setElementData(newGang, "leader", gngName) setElementData(newGang, "members", {}) outputChatBox("You successfully created the "..gngName.." gang and you are the leader !", thePlayer) end addCommandHandler("createGang", createGang, false, false) function inviteInGang( thePlayer, cmd, playerName ) if not thePlayer or not cmd then return end if not playerName then return outputChatBox("SYNTAX: /invite ", thePlayer) end local gang = getElementData(thePlayer, "gang") if not gang then return outputChatBox("You must be part of a gang first. Do /createGang to create your own.", thePlayer) end local newMember = getPlayerFromName(playerName) if not newMember then return outputChatBox("Player "..playerName.." not found !", thePlayer) end if newMember == thePlayer then return outputChatBox("You can't invite your self into a gang !", thePlayer) if getElementData(newMember, "gang") then return outputChatBox("The player "..playerName.." is already in a gang. Ask him to leave first.", thePlayer) end if addNewMemberToGang(gang, newMember) then local gangName = getElementData(gang, "name") or "" outputChatBox("Congrats ! You are now part of the "..tostring(gangName).." gang !", newMember) outputChatBox(playerName.." is now a member of your gang !", thePlayer) else outputChatBox("An error has occured. Please contact an administrator.", thePlayer) end end addCommandHandler("invite", inviteInGang, false, false) function leaveGang( thePlayer ) if not thePlayer then return end local gang = getElementData(thePlayer, "gang") if not gang then return outputChatBox("You already aren't in a gang !", thePlayer) end if removeMemberFromGang( gang, thePlayer ) then local gangName = getElementData(gang, "name") or "" local leader = getElementData(gang, "leader") outputChatBox("You successfully left the "..tostring(gangName).." gang !", thePlayer) if leader and isElement(leader) then outputChatBox(playerName.." left your gang !", leader) end else outputChatBox("An error has occured. Please contact an administrator.", thePlayer) end end addCommandHandler("leaveGang", leaveGang, false, false) function addNewMemberToGang( theGang, thePlayer ) if not theGang or not thePlayer then return end local members = getElementData(theGang, "members") table.insert(members, thePlayer) return (setElementData(newMember, "gang", theGang) and setElementData(theGang "members", members)) end function removeMemberFromGang( theGang, thePlayer ) if not theGang or nor thePlayer then return end local tmp = getElementData(theGang, "members") or {} local members = {} for k, member in ipairs(members) do if member ~= thePlayer then table.insert(members, member) end end return (removeElementData(thePlayer, "gang") and setElementData(theGang, "members", members)) end function isGangAlreadyExist( gngName ) for k, theGang in ipairs (getElementsByType("gang")) do local name = getElementData(theGang, "name") or "" if name == gngName then return true end end return false end function gangChat ( thePlayer, _, ... ) local text = table.concat ( { ... }, " " ) local theGang = getElementData(thePlayer, "gang") if #text == 0 or not theGang then return end local members = getElementData(theGang, "members") or {} local playerName = getPlayerName(thePlayer) for k, member in ipairs (members) do outputChatBox ("#FF32AA (GANG) "..playerName..": #FFFFFF"..text, member, 255, 255, 255, true ) end end addCommandHandler ( "gangChat", gangChat ) addCommandHandler ( "gc", gangChat ) This script may have bugs since I didn't test it. This one but i don't want to create a gang for each gang chat, only when i invite player, automatically add me and him to the gang chat without creating a gang or something like that, thanks for help! Link to comment
Moderators Citizen Posted March 12, 2014 Moderators Share Posted March 12, 2014 try to modify my code then. Link to comment
-.Paradox.- Posted March 12, 2014 Author Share Posted March 12, 2014 If i knew how, i would do it without asking you, so please can you help me? Link to comment
Moderators Citizen Posted March 13, 2014 Moderators Share Posted March 13, 2014 Because you didn't read the code. Read it carefully with the wiki and try to modify it. We aren't here to script your server. At least try. 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