Jump to content

Kenix

Retired Staff
  • Posts

    4,121
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by Kenix

  1. function findPlayer( namepart ) -- 1 argument is string local player = getPlayerFromName( namepart ) if player then -- if player found return player -- return player element end -- So if not found with getPlayerFromName then find player with loop. for _,player in pairs( getElementsByType 'player' ) do -- loop table players if string.find( string.gsub( getPlayerName( player ):lower( ),"#%x%x%x%x%x%x", "" ), namepart:lower( ), 1, true ) then -- find player by pattern return player -- return player element end end return false -- return false if not found end addCommandHandler( 'givemoney', -- add command handler function( source,_,player,amount ) -- 1 argument is source ( element player ) ( who use type this command ) , 2 argument is command name but we not need use this and we create 'upvalue' ( frozen variable that will not be used ) , 3 argument is player nick name ( string ) , 4 argument is amount local find = findPlayer( player ) -- So call function findPlayer in argument use nick name ( string ) if find then -- If player founded then if amount then -- If player type amount ( full command /givemoney [nickname][amount] ) givePlayerMoney( find,tonumber( amount ) ) -- give money for player outputChatBox( '[givemoney]:You transfer $'..amount..' to '..getPlayerName( find ),source,255,0,0 ) -- write in chat box else -- player not type full command ( /givemoney [nickname][amount] ) outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 ) -- write in chat box end else -- player not found outputChatBox( '[givemoney]:Player not found!',source,255,0,0 ) -- write in chat box end end ) Updated again.
  2. So it command give money player. You type command /givemoney [ nickname ][ amount ] Example:/givemoney Kenix 1000 Or i not understand you,
  3. Server. function findPlayer( namepart ) local player = getPlayerFromName( namepart ) if player then return player end for _,player in pairs( getElementsByType 'player' ) do if string.find( string.gsub( getPlayerName( player ):lower( ),"#%x%x%x%x%x%x", "" ), namepart:lower( ), 1, true ) then return player end end return false end addCommandHandler( 'givemoney', function( source,_,player,amount ) local find = findPlayer( player ) if find then if amount then givePlayerMoney( find,tonumber( amount ) ) outputChatBox( '[givemoney]:You transfer $'..amount..' to '..getPlayerName( find ),source,255,0,0 ) else outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 ) end else outputChatBox( '[givemoney]:Player not found!',source,255,0,0 ) end end ) Updated.
  4. Kenix

    help

    Not work if use test cmd. But another name for cmd work
  5. Kenix

    help

    No problem. This is strange rly.
  6. Kenix

    help

    I tested it now and it working only if rename cmd. local uTimers = { } function Chopper ( player ) local Account = getAccountName ( getPlayerAccount ( player ) ) if isObjectInACLGroup ("user."..Account, aclGetGroup ( "Admin" ) ) then local Px, Py, Pz = getElementPosition ( player ) local Rx, Ry, Rz = getElementRotation ( player ) if isPedInVehicle( player ) then local vehicle = getPedOccupiedVehicle ( player ) destroyElement ( vehicle ) end local vehicle2 = createVehicle ( 497, Px, Py, Pz, Rx, Ry, Rz ) if isTimer( uTimers[ player ] ) then killTimer( uTimers[ player ] ) end uTimers[ player ] = setTimer( function( player,vehicle ) warpPedIntoVehicle ( player, vehicle ) end, 100, 1,player,vehicle2 ) else outputChatBox ( "You can not execute this command!", player ) end end addCommandHandler ( "_test", Chopper ) addEventHandler( 'onPlayerQuit',root, function( ) uTimers[ source ] = nil end ) cmd:/_test
  7. Kenix

    help

    Show meta.xml
  8. Kenix

    help

    Ah yes,my bad local uTimers = { } function Chopper ( player ) local Account = getAccountName ( getPlayerAccount ( player ) ) if isObjectInACLGroup ("user."..Account, aclGetGroup ( "Admin" ) ) then local Px, Py, Pz = getElementPosition ( player ) local Rx, Ry, Rz = getElementRotation ( player ) if isPedInVehicle( player ) then local vehicle = getPedOccupiedVehicle ( player ) destroyElement ( vehicle ) end local vehicle2 = createVehicle ( 497, Px, Py, Pz, Rx, Ry, Rz ) if isTimer( uTimers[ player ] ) then killTimer( uTimers[ player ] ) end uTimers[ player ] = setTimer( function( player,vehicle ) warpPedIntoVehicle ( player, vehicle ) end, 100, 1,player,vehicle2 ) else outputChatBox ( "You can not execute this command!", player ) end end addCommandHandler ( "test", Chopper ) addEventHandler( 'onPlayerQuit',root, function( ) uTimers[ source ] = nil end ) uTimers is table stored timers. As an index, we use the userdata Player. If player quit remove index from table. It is very convenient we can remove the timer current ( which we need ) player and not a all players.
  9. Take my code again. I fix small problem
  10. local state = { } function hideMe( source ) local account = getAccountName( getPlayerAccount( source ) ) if isObjectInACLGroup( "user." .. account, aclGetGroup( "Admin" ) ) or isObjectInACLGroup( "user." .. account, aclGetGroup( "SuperModerator" ) ) or isObjectInACLGroup( "user." .. account, aclGetGroup( "Moderator" ) ) then state[ source ] = not state[ source ] if state[ source ] then setElementAlpha( source,0 ) outputChatBox( 'invisible' ) else setElementAlpha( source,255 ) outputChatBox( 'visible' ) end else outputChatBox( 'Access denied for this command.' ) end end addCommandHandler( "hide", hideMe ) addEventHandler( 'onPlayerQuit',root, function( ) state[ source ] = nil end ) ??
  11. Server addEvent( "truck_finish",true ) local trucks = { [403] = true, [514] = true, [515] = true } local truckTable = { [1] ={ 1812.65198, -1889.86047, 13.41406 }, [2] ={ 1825.22791, -1635.03711, 13.38281 }, [3] ={ 1855.01685, -1430.47449, 13.39063 }, [4] ={ 1732.81580, -1296.87122, 13.44294 }, [5] ={ 1473.19226, -1295.77124, 13.48315 }, [6] ={ 1443.60376, -1498.26660, 13.37650 }, [7] ={ 1426.37280, -1716.12439, 13.38281 }, [8] ={ 1315.06909, -1656.43799, 13.38281 }, [9] ={ 1359.06250, -1432.39734, 13.38281 }, [10] ={ 1169.82983, -1392.34473, 13.41728 }, [11] ={ 930.76508, -1392.92627, 13.26561 }, [12] ={ 815.24756, -1317.91345, 13.44460 }, [13] ={ 585.04199, -1320.53748, 13.40609 }, [14] ={ 526.99365, -1624.20361, 16.63225 } } function getNewTruckLocation( thePlayer, ID ) local x, y, z = truckTable[ ID ][1], truckTable[ ID ][2], truckTable[ ID ][3] triggerClientEvent( thePlayer,"truck_set_location",thePlayer,x,y,z ) end function onVehicleEnter( thePlayer ) if not trucks[ getElementModel( source ) ] or getPlayerTeam( thePlayer ) then return end if getTeamName( getPlayerTeam( thePlayer ) ) == "Truckers" then getNewTruckLocation( thePlayer, 1 ) setElementData( thePlayer,"truckData",1 ) end end addEventHandler( "onVehicleEnter",root,onVehicleEnter ) addEventHandler( "truck_finish",root, function ( ) if not isPedInVehicle( source ) or not trucks[ getElementModel( getPedOccupiedVehicle( source ) ) ] then return end end givePlayerMoney( source, 100 ) if #truckTable == tonumber( getElementData( source,"truckData" ) ) then setElementData( source,"truckData",1 ) else setElementData( source,"truckData",tonumber( getElementData( source,"truckData" ) ) +1 ) end getNewTruckLocation( source, tonumber( getElementData( source,"truckData" ) ) ) end ) Client local truckmarker,truckblip addEvent( "truck_set_location",true ) addEventHandler( "truck_set_location",root, function ( x, y, z ) truckmarker = createMarker( x ,y,z-1, "cylinder", 10, 184, 57, 14, 170 ) truckblip = createBlipAttachedTo( truckmarker, 19 ) addEventHandler( "onClientMarkerHit",truckmarker,onTruckStopHit ) end ) function onTruckStopHit( hitPlayer ) if not hitPlayer == localPlayer then return end triggerServerEvent( "truck_finish",localPlayer ) if isElement( truckblip ) then destroyElement( truckblip ) end if isElement( truckmarker ) then removeEventHandler( "onClientMarkerHit",truckmarker,onTruckStopHit ) destroyElement( truckmarker ) end end addEventHandler( "onClientVehicleExit",root, function ( ) if isElement( truckmarker ) then removeEventHandler( "onClientMarkerHit",truckmarker,onTruckStopHit ) destroyElement( truckmarker ) end if isElement( truckblip ) then destroyElement( truckblip ) end end ) Try this , but i not understand what you mean Write steps.
  12. function hideMe( source ) local account = getAccountName( getPlayerAccount( source ) ) if getElementAlpha( source ) == 255 and isPlayerNametagShowing( source ) then if isObjectInACLGroup( "user." .. account, aclGetGroup( "Admin" ) ) then setPlayerNametagShowing( source, false ) setElementAlpha( source, 0 ) elseif isObjectInACLGroup( "user." .. account, aclGetGroup( "SuperModerator" ) ) then setPlayerNametagShowing( source, false ) setElementAlpha( source, 0 ) elseif isObjectInACLGroup( "user." .. account, aclGetGroup( "Moderator" ) ) then setPlayerNametagShowing( source, false ) setElementAlpha( source, 0 ) else outputChatBox( "You are not allowed to use this command!", source, 255, 0, 0 ) end else setElementAlpha( source, 255 ) setPlayerNametagShowing( source, true ) end end addCommandHandler( "hide", hideMe ) https://wiki.multitheftauto.com/wiki/Scr ... troduction http://www.lua.org/manual/5.1/
  13. No problem No , because maybe someguy have the same problem.
  14. Remember lua is case sensitive. Example var = 5 print( var ) -- 5 print( Var ) -- nil So your code: function playerDataLoading(thePlayer, username) -- in argument thePlayer local result = mysql_query(mysqldb, "Select * From players where username='"..username.."'") if not result then outputDebugString( "EVENT:playerDataLoading mysql_query failed: (" .. tostring( mysql_errno( mysqldb ) ).. ") " ..tostring( mysql_error( mysqldb ) ) ) mysql_free_result(result) return end local field = mysql_fetch_field(result) setElementData(thePlayer, "playerUsername", username) spawnPlayer(theplayer, 0, 0, 3) -- theplayer is nil mysql_free_result(result) end Events: I always see how scripters triggered some event Example: -- wrong code -- Server addCommandHandler( 'some', function( player ) triggerClientEvent( 'some',root,player ) --[[ So it triggered base element root ( instead of source player ) ( see on wiki ) then player element Why? If 2 argument is base element and not need triggered next optional arguments. ]] end ) -- Client addEvent( 'some',true ) addEventHandler( 'some',root, function( player ) -- why need use player? If you trigger source event ( not root ) you can use source in event. local x,y,z = getElementPosition( player ) createExplosion( x,y,z,4 ) end ) -- correct -- Server addCommandHandler( 'some', function( player ) triggerClientEvent( 'some',player ) end ) -- Client addEvent( 'some',true ) addEventHandler( 'some',root, function( ) local x,y,z = getElementPosition( source ) createExplosion( x,y,z,4 ) end ) --[[ This examples triggered for all elements( root ) ]] Your code triggerEvent("playerDataLoad", resourceRoot, source, username) You triggered base element resource root and then source and then username , but why? You can trigger base element source ( source player ) and then username. https://wiki.multitheftauto.com/wiki/Pre ... ables_list https://wiki.multitheftauto.com/wiki/Event_system
  15. https://wiki.multitheftauto.com/wiki/Mapmanager ?
  16. function currentMapName( ) return getResourceName( exports[ 'mapmanager']:getRunningGamemodeMap( ) ) end
  17. Kenix

    Hunter target

    Client local attacker,player addEventHandler( "onClientProjectileCreation", root, function( creator ) local target = getProjectileTarget( source ) if isElement( target ) and getElementType( target ) == 'vehicle' and isElement( creator ) and getElementType( creator ) == 'vehicle' then outputChatBox 'target == vehicle and creator == vehicle' attacker = getVehicleController( creator ) player = getVehicleController( target ) if isElement( attacker ) and isElement( player ) then outputChatBox 'trigger server event onVehicleExploded' triggerServerEvent( 'onVehicleExploded',player,attacker ) end else outputChatBox 'target ~= vehicle or creator ~= vehicle' outputChatBox( ' target = '..tostring( getElementType( target ) )..'\n\ creator = '..tostring( getElementType( creator ) )..'\n'.. 'attacker = '..tostring( getVehicleController( creator ) )..'\n'.. 'player = '..tostring( getVehicleController( target ) )..'' ) end end ) Server addEvent( 'onVehicleExploded',true ) addEventHandler( 'onVehicleExploded',root, function( attacker ) outputChatBox ( getPlayerName( attacker )..' has killed '..getPlayerName( source )..' with his hunter.',root,255,0,0 ) end )
  18. Try Server addEvent( "playerDataLoad", true ) function playerDataLoading( username ) local result = mysql_query( mysqldb, "Select * From players where username = '"..username.."'" ) if not result then outputDebugString( "EVENT:playerDataLoading mysql_query failed: (" .. tostring( mysql_errno( mysqldb ) ).. ") " ..tostring( mysql_error( mysqldb ) ) ) return end setElementData( source, "playerUsername", username ) spawnPlayer( source, 0, 0, 3) mysql_free_result( result ) end function playerDataSaving( ) if get "AutoSaveOnQuit" then local posX, posY, posZ = getElementPosition( source ) mysql_query( mysqldb, "Update players Set pos_X = "..posX..", pos_Y = "..posY..",\ pos_Z = "..posZ.." Where username = '"..tostring( getElementData( source, "playerUsername" ) ).."'" ) end end addEventHandler( "onPlayerQuit", root, playerDataSaving ) addEventHandler( "playerDataLoad", root, playerDataLoading ) Login local spawnX, spawnY, spawnZ = 1959.55, -1714.46, 20 addEvent( "submitLogin", true ) addEvent( "submitRegister", true) function loginHandler(username, password ) local password2 = whirlpool( password ) local result = mysql_query( mysqldb, "SELECT * FROM players WHERE username = '"..username.. "' AND pass = '"..password2.. "'" ) if not result then outputDebugString( "EVENT:submitLogin mysql_query failed: (" .. tostring( mysql_errno( mysqldb ) ).. ") " ..tostring( mysql_error( mysqldb ) ) ) else if mysql_num_rows( result ) > 0 then fadeCamera( source, true ) setCameraTarget( source, source ) outputChatBox( "Welcome to My Server.", source ) triggerEvent( "playerDataLoad", source, username ) else outputChatBox( "Invalid username and password. Please try again.",source, 255, 0, 0) triggerClientEvent ( "falseLogin", root ) end mysql_free_result( result ) end end function registerHandler(user, pass, repass ) local result = mysql_query( mysqldb, "SELECT * FROM players WHERE username = '"..user.."'" ) if not result then outputDebugString( "EVENT:submitRegister mysql_query failed: (" .. tostring( mysql_errno( mysqldb ) ).. ") " ..tostring( mysql_error( mysqldb ) ) ) else if mysql_num_rows( result ) > 0 then outputChatBox( "Username which you selected already exists!",source, 255, 0, 0 ) else if pass == repass then local pass2 = whirlpool( pass ) local Result = mysql_query( mysqldb, "INSERT INTO players (username, pass) VALUES ('"..user.."', '"..pass2.."')" ) if Result then mysql_free_result( Result ) fadeCamera( source, true ) setCameraTarget( source, source ) spawnPlayer( source, spawnX, spwanY, spawnZ ) setElementData( source, "pMoney", get( "PlayerStartingMoney" ) ) givePlayerMoney( source, get( "PlayerStartingMoney" ) ) triggerClientEvent( source, "succesRegister", root, pass ) else outputDebugString( "Register not succes: mysql_query failed: (" .. tostring( mysql_errno( mysqldb ) ).. ") " ..tostring( mysql_error( mysqldb ) ) ) end else outputChatBox( "Passwords dosen't match. Please re-enter passwords!",source, 255, 0, 0 ) end end mysql_free_result( result ) end end addEventHandler( "submitRegister", root, registerHandler ) addEventHandler( "submitLogin", root, loginHandler )
  19. Kenix

    help

    Server side. local uTimers = { } function Chopper ( player ) local Account = getAccountName ( getPlayerAccount ( player ) ) if isObjectInACLGroup ("user."..Account, aclGetGroup ( "Admin" ) ) then local Px, Py, Pz = getElementPosition ( player ) local Rx, Ry, Rz = getElementRotation ( player ) if isPedInVehicle( player ) then local vehicle = getPedOccupiedVehicle ( player ) destroyElement ( vehicle ) end local vehicle2 = createVehicle ( 497, Px, Py, Pz, Rx, Ry, Rz ) if isTimer( uTimers[ player ] ) then killTimer( uTimers[ player ] ) end uTimers[ player ] = setTimer( function( player,vehicle ) warpPedIntoVehicle ( player, vehicle ) end, 100, 1,player,vehicle2 ) else outputChatBox ( "You can not execute this command!", player ) end end addCommandHandler ( "test", Chopper ) addEventHandler( 'onPlayerQuit',root, function( ) uTimers[ source ] = nil end ) Updated again. You can't use function getLocalPlayer in server side.
  20. Ага. Песня классная, но я рок не очень люблю.
×
×
  • Create New...