Mikhail Posted October 10, 2018 Share Posted October 10, 2018 Hello , i have this command Spoiler barrafc = createObject ( 968, -215.89999, 1008, 19.5, 0, 269.5, 358 ) gateOpen = false -- gate is closed by default addCommandHandler("abrirfcpd", function (theplayer,command) if gateOpen ~= true then moveObject ( barrafc, 1000, -215.89999, 1008, 19.5, 0, 90, 0 ) outputChatBox("Entrada abierta",theplayer,255,255,0) gateOpen = true elseif gateOpen == true then end end) addCommandHandler("cerrarfcpd", function (player,command) if gateOpen == true then moveObject ( barrafc, 1000, -215.89999, 1008, 19.5, 0, -90, 0 ) outputChatBox("Entrada cerrada",player,255,0,0) gateOpen = false else end end) Now the problem is, I want to be used by only one faction (fcpd fort carson police dept)the issue is that I have an external data base but very simple, it is the Paradise gamemode sure you know what I talking.How do I check from the database if the character is in "FCPD" (this is how the group is written) because I have no idea how to check with an external database ITS ALL ON PARADISE RP. this is the entire script of mysql.lua if u need it Spoiler local connection = nil local connection = nil local null = nil local results = { } local max_results = 128 -- connection functions local function connect( ) -- retrieve the settings local server = get( "server" ) or "" local user = get( "user" ) or "" local password = get( "password" ) or "" local db = get( "database" ) or "" local port = get( "port" ) or 3306 local socket = get( "socket" ) or nil -- connect connection = mysql_connect ( server, user, password, db, port, socket ) if connection then if user == "root" then setTimer( outputDebugString, 100, 1, "Connecting to your MySQL as 'root' is strongly discouraged.", 2 ) end return true else outputDebugString ( "Connection to MySQL Failed.", 1 ) return false end end local function disconnect( ) if connection and mysql_ping( connection ) then mysql_close( connection ) end end local function checkConnection( ) if not connection or not mysql_ping( connection ) then return connect( ) end return true end addEventHandler( "onResourceStart", resourceRoot, function( ) if not mysql_connect then if hasObjectPermissionTo( resource, "function.shutdown" ) then shutdown( "MySQL module missing." ) end cancelEvent( true, "MySQL module missing." ) elseif not hasObjectPermissionTo( resource, "function.mysql_connect" ) then if hasObjectPermissionTo( resource, "function.shutdown" ) then shutdown( "Insufficient ACL rights for mysql resource." ) end cancelEvent( true, "Insufficient ACL rights for mysql resource." ) elseif not connect( ) then if connection then outputDebugString( mysql_error( connection ), 1 ) end if hasObjectPermissionTo( resource, "function.shutdown" ) then shutdown( "MySQL failed to connect." ) end cancelEvent( true, "MySQL failed to connect." ) else null = mysql_null( ) end end ) addEventHandler( "onResourceStop", resourceRoot, function( ) for key, value in pairs( results ) do mysql_free_result( value.r ) outputDebugString( "Query not free()'d: " .. value.q, 2 ) end disconnect( ) end ) -- function escape_string( str ) if type( str ) == "string" then return mysql_escape_string( connection, str ) elseif type( str ) == "number" then return tostring( str ) end end local function query( str, ... ) checkConnection( ) if ( ... ) then local t = { ... } for k, v in ipairs( t ) do t[ k ] = escape_string( tostring( v ) ) or "" end str = str:format( unpack( t ) ) end local result = mysql_query( connection, str ) if result then for num = 1, max_results do if not results[ num ] then results[ num ] = { r = result, q = str } return num end end mysql_free_result( result ) return false, "Unable to allocate result in pool" end return false, mysql_error( connection ) end function query_free( str, ... ) if sourceResource == getResourceFromName( "runcode" ) then return false end checkConnection( ) if ( ... ) then local t = { ... } for k, v in ipairs( t ) do t[ k ] = escape_string( tostring( v ) ) or "" end str = str:format( unpack( t ) ) end local result = mysql_query( connection, str ) if result then mysql_free_result( result ) return true end return false, mysql_error( connection ) end function free_result( result ) if results[ result ] then mysql_free_result( results[ result ].r ) results[ result ] = nil end end function query_assoc( str, ... ) if sourceResource == getResourceFromName( "runcode" ) then return false end local t = { } local result, error = query( str, ... ) if result then for result, row in mysql_rows_assoc( results[ result ].r ) do local num = #t + 1 t[ num ] = { } for key, value in pairs( row ) do if value ~= null then t[ num ][ key ] = tonumber( value ) or value end end end free_result( result ) return t end return false, error end function query_assoc_single( str, ... ) if sourceResource == getResourceFromName( "runcode" ) then return false end local t = { } local result, error = query( str, ... ) if result then local row = mysql_fetch_assoc( results[ result ].r ) if row then for key, value in pairs( row ) do if value ~= null then t[ key ] = tonumber( value ) or value end end free_result( result ) return t end free_result( result ) return false end return false, error end function query_insertid( str, ... ) if sourceResource == getResourceFromName( "runcode" ) then return false end local result, error = query( str, ... ) if result then local id = mysql_insert_id( connection ) free_result( result ) return id end return false, error end function query_affected_rows( str, ... ) if sourceResource == getResourceFromName( "runcode" ) then return false end local result, error = query( str, ... ) if result then local rows = mysql_affected_rows( connection ) free_result( result ) return rows end return false, error end Link to comment
LyricalMM Posted October 10, 2018 Share Posted October 10, 2018 put the meta.xml of the factions resource Link to comment
LilDawage Posted October 10, 2018 Share Posted October 10, 2018 (edited) 13 hours ago, Mikhail said: Hello , i have this command Hide contents barrafc = createObject ( 968, -215.89999, 1008, 19.5, 0, 269.5, 358 ) gateOpen = false -- gate is closed by default addCommandHandler("abrirfcpd", function (theplayer,command) if gateOpen ~= true then moveObject ( barrafc, 1000, -215.89999, 1008, 19.5, 0, 90, 0 ) outputChatBox("Entrada abierta",theplayer,255,255,0) gateOpen = true elseif gateOpen == true then end end) addCommandHandler("cerrarfcpd", function (player,command) if gateOpen == true then moveObject ( barrafc, 1000, -215.89999, 1008, 19.5, 0, -90, 0 ) outputChatBox("Entrada cerrada",player,255,0,0) gateOpen = false else end end) Now the problem is, I want to be used by only one faction (fcpd fort carson police dept)the issue is that I have an external data base but very simple, it is the Paradise gamemode sure you know what I talking.How do I check from the database if the character is in "FCPD" (this is how the group is written) because I have no idea how to check with an external database ITS ALL ON PARADISE RP. this is the entire script of mysql.lua if u need it Hide contents local connection = nil local connection = nil local null = nil local results = { } local max_results = 128 -- connection functions local function connect( ) -- retrieve the settings local server = get( "server" ) or "" local user = get( "user" ) or "" local password = get( "password" ) or "" local db = get( "database" ) or "" local port = get( "port" ) or 3306 local socket = get( "socket" ) or nil -- connect connection = mysql_connect ( server, user, password, db, port, socket ) if connection then if user == "root" then setTimer( outputDebugString, 100, 1, "Connecting to your MySQL as 'root' is strongly discouraged.", 2 ) end return true else outputDebugString ( "Connection to MySQL Failed.", 1 ) return false end end local function disconnect( ) if connection and mysql_ping( connection ) then mysql_close( connection ) end end local function checkConnection( ) if not connection or not mysql_ping( connection ) then return connect( ) end return true end addEventHandler( "onResourceStart", resourceRoot, function( ) if not mysql_connect then if hasObjectPermissionTo( resource, "function.shutdown" ) then shutdown( "MySQL module missing." ) end cancelEvent( true, "MySQL module missing." ) elseif not hasObjectPermissionTo( resource, "function.mysql_connect" ) then if hasObjectPermissionTo( resource, "function.shutdown" ) then shutdown( "Insufficient ACL rights for mysql resource." ) end cancelEvent( true, "Insufficient ACL rights for mysql resource." ) elseif not connect( ) then if connection then outputDebugString( mysql_error( connection ), 1 ) end if hasObjectPermissionTo( resource, "function.shutdown" ) then shutdown( "MySQL failed to connect." ) end cancelEvent( true, "MySQL failed to connect." ) else null = mysql_null( ) end end ) addEventHandler( "onResourceStop", resourceRoot, function( ) for key, value in pairs( results ) do mysql_free_result( value.r ) outputDebugString( "Query not free()'d: " .. value.q, 2 ) end disconnect( ) end ) -- function escape_string( str ) if type( str ) == "string" then return mysql_escape_string( connection, str ) elseif type( str ) == "number" then return tostring( str ) end end local function query( str, ... ) checkConnection( ) if ( ... ) then local t = { ... } for k, v in ipairs( t ) do t[ k ] = escape_string( tostring( v ) ) or "" end str = str:format( unpack( t ) ) end local result = mysql_query( connection, str ) if result then for num = 1, max_results do if not results[ num ] then results[ num ] = { r = result, q = str } return num end end mysql_free_result( result ) return false, "Unable to allocate result in pool" end return false, mysql_error( connection ) end function query_free( str, ... ) if sourceResource == getResourceFromName( "runcode" ) then return false end checkConnection( ) if ( ... ) then local t = { ... } for k, v in ipairs( t ) do t[ k ] = escape_string( tostring( v ) ) or "" end str = str:format( unpack( t ) ) end local result = mysql_query( connection, str ) if result then mysql_free_result( result ) return true end return false, mysql_error( connection ) end function free_result( result ) if results[ result ] then mysql_free_result( results[ result ].r ) results[ result ] = nil end end function query_assoc( str, ... ) if sourceResource == getResourceFromName( "runcode" ) then return false end local t = { } local result, error = query( str, ... ) if result then for result, row in mysql_rows_assoc( results[ result ].r ) do local num = #t + 1 t[ num ] = { } for key, value in pairs( row ) do if value ~= null then t[ num ][ key ] = tonumber( value ) or value end end end free_result( result ) return t end return false, error end function query_assoc_single( str, ... ) if sourceResource == getResourceFromName( "runcode" ) then return false end local t = { } local result, error = query( str, ... ) if result then local row = mysql_fetch_assoc( results[ result ].r ) if row then for key, value in pairs( row ) do if value ~= null then t[ key ] = tonumber( value ) or value end end free_result( result ) return t end free_result( result ) return false end return false, error end function query_insertid( str, ... ) if sourceResource == getResourceFromName( "runcode" ) then return false end local result, error = query( str, ... ) if result then local id = mysql_insert_id( connection ) free_result( result ) return id end return false, error end function query_affected_rows( str, ... ) if sourceResource == getResourceFromName( "runcode" ) then return false end local result, error = query( str, ... ) if result then local rows = mysql_affected_rows( connection ) free_result( result ) return rows end return false, error end to know Gropup name From database you should Create a table for it (CREATE TABLE IF NOT EXIST .. and get player Group from table using Database function Edited October 10, 2018 by LilDawage Link to comment
LyricalMM Posted October 10, 2018 Share Posted October 10, 2018 use: player = getLocalPlayer() team = getPlayerTeam(player) teamName = getTeamName(team) if (teamName == "FCPD") then --Your code end Link to comment
Mikhail Posted October 10, 2018 Author Share Posted October 10, 2018 (edited) @LyricalMM @LilDawage i do it : Spoiler commandTimer = {abrirfcpd} function abierta1(player, commandName) if isElementWithinColShape( player, EntradaFCPD ) then if exports.factions:isPlayerInFaction( player, 1, 2 ) then if gateOpen ~= true then if isTimer(commandTimer[player]) then return end moveObject ( barrafc, 1000, -215.89999, 1008, 19.5, 0, 90, 0 ) outputChatBox("Entrada abierta",player,255,255,0) gateOpen = true commandTimer[player] = setTimer(function () end, 1500, 1) else if gateOpen == true then end end else outputChatBox("No eres de la faccion",player,255,0,0) end else outputChatBox ("No estas en la zona!!",player,255,0,0) end end addCommandHandler("abrirfcpd", abierta1) it is worked its right?? Edited October 10, 2018 by Mikhail Link to comment
LyricalMM Posted October 11, 2018 Share Posted October 11, 2018 7 hours ago, Mikhail said: @LyricalMM @LilDawage i do it : Reveal hidden contents commandTimer = {abrirfcpd}function abierta1(player, commandName) if isElementWithinColShape( player, EntradaFCPD ) then if exports.factions:isPlayerInFaction( player, 1, 2 ) then if gateOpen ~= true then if isTimer(commandTimer[player]) then return end moveObject ( barrafc, 1000, -215.89999, 1008, 19.5, 0, 90, 0 ) outputChatBox("Entrada abierta",player,255,255,0) gateOpen = true commandTimer[player] = setTimer(function () end, 1500, 1) else if gateOpen == true then end end else outputChatBox("No eres de la faccion",player,255,0,0) end else outputChatBox ("No estas en la zona!!",player,255,0,0) endendaddCommandHandler("abrirfcpd", abierta1) it is worked its right?? Yeah 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