Anubhav Posted March 4, 2014 Share Posted March 4, 2014 function bri (client,command) local accName = getAccountName ( getPlayerAccount ( client ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) or isObjectInACLGroup ("user."..accName, aclGetGroup ( "Moderator" ) ) or isObjectInACLGroup ("user."..accName, aclGetGroup ( "Super Moderator" ) ) then setPlayerTeam(client,"Staff") setElementModel ( client, 217 ) outputChatBox("[sTAFF TOOLS] Welcome to the Staff Team!",client,255,0,0) else outputChatBox("[sTAFF TOOLS] You are not a staff.",client,255,0,0) end end end addCommandHandler("gostaff", bri ) It got error that: Bad Argument @ 'addCommandHandler' [Expected function at argument 2, got nil] Please fix it i need it a lot! Link to comment
myonlake Posted March 4, 2014 Share Posted March 4, 2014 Remove an "end" from your code. There's one too much. Link to comment
Anubhav Posted March 4, 2014 Author Share Posted March 4, 2014 Its not much. There must 3 or it will give error. 1 for if. 1 for else. 1 for function. Link to comment
Karuzo Posted March 4, 2014 Share Posted March 4, 2014 no. You don't need an end for an else. Just put an end away. Link to comment
Anubhav Posted March 4, 2014 Author Share Posted March 4, 2014 Realy LOL? It gives me 1 more error. Link to comment
iPrestege Posted March 4, 2014 Share Posted March 4, 2014 Yep that's right because 'setPlayerTeam' Function you can't set the player in team using string like that. Get the team from the team name then set the player to the team. setPlayerTeam ( client,getTeamFromName ( 'Staff' ) ) Link to comment
Anubhav Posted March 4, 2014 Author Share Posted March 4, 2014 Same error. Bad Argument @ 'addCommandHandler' [Expected function at argument 2, got nil] Link to comment
myonlake Posted March 4, 2014 Share Posted March 4, 2014 Is that so? Your code just made no sense so I went and fixed everything for you. Hopefully you learnt something from this. Server-side local teams = { } function addTeam( parameter ) -- Check if the parameter is a player or a resource if ( parameter ~= resource ) and ( getElementType( parameter ) == "player" ) then -- Get the player's account local account = ( getPlayerAccount( parameter ) and ( not isGuestAccount( getPlayerAccount( parameter ) ) ) and getPlayerAccount( parameter ) or nil ) if ( account ) then -- If the player has an account, get the name of the account local account_name = getAccountName( account ) -- Check if the account is within the admin group if ( isObjectInACLGroup( "user." .. account_name, aclGetGroup( "Admin" ) ) ) then local team = getTeamFromName( "Staff" ) -- If there is no team with the name of "Staff" if ( not team ) then -- Create a new team with that name teams[ "staff" ] = createTeam( "Staff", 255, 255, 255 ) outputChatBox( "[sTAFF TOOLS] Staff team " .. ( ( teams[ "staff" ] and isElement( teams[ "staff" ] ) ) and "added" or "could not be added" ) .. ".", parameter, 255, 0, 0, false ) else outputChatBox( "[sTAFF TOOLS] Staff team already exists.", parameter, 255, 0, 0, false ) end end end -- If the parameter is a resource, then create the team elseif ( parameter == resource ) then teams[ "staff" ] = createTeam( "Staff", 255, 255, 255 ) end end addEventHandler( "onResourceStart", resourceRoot, addTeam ) addCommandHandler( "readd", addTeam ) -- You had a typo here "addTeaM" instead of "addTeam"; Lua is case-sensitive addEventHandler( "onPlayerLogin", root, function( _, account ) -- Get the account name of the account the player logged on to local account_name = getAccountName( account ) -- If the account is within the admin group if ( isObjectInACLGroup( "user." .. account_name, aclGetGroup( "Admin" ) ) ) then setElementData( source, "Staff", true, true ) end end ) addCommandHandler( "gostaff", function( player, cmd ) -- Get the player's account if any local account = ( getPlayerAccount( player ) and ( not isGuestAccount( getPlayerAccount( player ) ) ) and getPlayerAccount( player ) or nil ) if ( account ) then -- Get the account name of this account local account_name = getAccountName( account ) -- If the account is within the admin, moderator or super moderator group if ( isObjectInACLGroup( "user." .. account_name, aclGetGroup( "Admin" ) ) or isObjectInACLGroup( "user." .. account_name, aclGetGroup( "Moderator" ) ) or isObjectInACLGroup( "user." .. account_name, aclGetGroup( "Super Moderator" ) ) ) then -- Get the admin team local team = getTeamFromName( "Staff" ) -- If there is an admin team, then proceed if ( team ) then -- Set the player to the staff team and set the player model to 217 setPlayerTeam( player, getTeamFromName( "Staff" ) ) setElementModel( player, 217 ) outputChatBox( "[sTAFF TOOLS] Welcome to the staff team!", player, 255, 0, 0, false ) else outputChatBox( "[sTAFF TOOLS] Seems like the staff team is missing.", player, 255, 0, 0, false ) end -- End the function so that the error message below won't show up return end end outputChatBox( "[sTAFF TOOLS] You are not a staff.", player, 255, 0, 0, false ) end ) function isPlayerInStaffTeam( player ) -- If the player is not an actual player, then return false if ( not player ) or ( getElementType( player ) ~= "player" ) then return false end -- Get the staff team local team = getTeamFromName( "Staff" ) -- If that staff team exists, then proceed if ( team ) then -- If the player is in the staff team and their skin is 217, then return true if ( getPlayerTeam( player ) == team ) and ( getElementModel( player ) == 217 ) then return true end end return false end function toggleDamageProof( player ) -- If the player is not an actual player, then return false if ( not player ) or ( getElementType( player ) ~= "player" ) then return false end -- Get the occupied vehicle of the player local vehicle = getPedOccupiedVehicle( player ) if ( getElementData( player, "Staff" ) ) and ( vehicle ) then setVehicleDamageProof( vehicle, not isVehicleDamageProof( vehicle ) ) return true end return false end addEvent( getResourceName( resource ) .. ":sync.attack", true ) addEventHandler( getResourceName( resource ) .. ":sync.attack", root, function( target ) -- Set the health so that it's synchronized setElementHealth( target, 200 ) setElementHealth( source, getElementHealth( source ) - 10 ) -- Warn the attacker outputChatBox( "[sTAFF TOOLS] Stop shooting staff members or you will be killed.", source, 255, 0, 0, false ) end ) Client-side addEventHandler( "onClientPlayerDamage", root, function( attacker ) -- If the attacker is not in the staff team if ( not getElementData( attacker, "Staff" ) ) then -- Cancel the event and set the health of both cancelEvent( ) -- Send a request to the server to synchronize stuff triggerServerEvent( getResourceName( resource ) .. ":sync.attack", attacker, source ) outputChatBox( "[sTAFF TOOLS] " .. getPlayerName( attacker ) .. " just attacked you.", 255, 0, 0, false ) end end ) I will edit this post in a moment with some comments in the code, make sure to read those when I get to it. 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