Jump to content

check this code


Samking

Recommended Posts

 

function enterVehicle (player, seat, jacked)
	local accName = getAccountName (getPlayerAccount (player) 
	if not isObjectInACLGroup("user."..accName, aclGetGroup ( "VIP" )) and getElementModel(source) == 412 then
	    cancelEvent()
		outputChatBox ( "you must be VIP to use this vehicle", player)
	end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle )

help me in this

 

Link to comment
local isPlayerInGroup, givemoney
     
local function givemoneycommand (player)
    if isPlayerInGroup (player, "VIP") then
        giveCash (player)
    else
        outputChatBox ("You must be VIP to use this command.", player,255,0, 0,true)
    end 
end
addCommandHandler("givemoney", givemoneycommand) 


     function findPlayer( namepart ) 
     local targetPlayer = getPlayerFromName ( who )               
    if ( targetPlayer ) 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 -- 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 ) 
            else -- player not type full command ( /givemoney [nickname][amount] )  
                outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 ) 
            end  
        else 
            outputChatBox( '[givemoney]:Player not found!',source,255,0,0 ) 
        end 
    end 
)

function isPlayerInGroup (player, group)
    local playerAccount = getPlayerAccount ( player )
    if playerAccount then
        local accName = getAccountName ( playerAccount ) 
        if isObjectInACLGroup ("user."..accName, aclGetGroup ( group ) ) then 
            return true
        end
    end
    return false
end

And this 

Link to comment
27 minutes ago, JeViCo said:

could you explain more? What problems do you have in your code?

In this code

  1. local isPlayerInGroup, givemoney
  2.  
  3. local function givemoneycommand (player)
  4. if isPlayerInGroup (player, "VIP") then
  5. giveCash (player)
  6. else
  7. outputChatBox ("You must be VIP to use this command.", player,255,0, 0,true)
  8. end
  9. end
  10. addCommandHandler("givemoney", givemoneycommand)
  11.  
  12.  
  13. function findPlayer( namepart )
  14. local targetPlayer = getPlayerFromName ( who )
  15. if ( targetPlayer ) then
  16. return player
  17. end
  18. for _,player in pairs( getElementsByType 'player' ) do
  19. if string.find( string.gsub( getPlayerName( player ):lower( ),"#%x%x%x%x%x%x", "" ), namepart:lower( ), 1, true ) then
  20. return player
  21. end
  22. end
  23. return false
  24. end
  25.  
  26. addCommandHandler( 'givemoney',
  27. function( source,_,player,amount )
  28. local find = findPlayer( player )
  29. if find then
  30. if amount then -- If player type amount ( full command /givemoney [nickname][amount] )
  31. givePlayerMoney( find,tonumber( amount ) ) -- give money for player
  32. outputChatBox( '[givemoney]:You transfer $'..amount..' to '..getPlayerName( find ),source,255,0,0 )
  33. else -- player not type full command ( /givemoney [nickname][amount] )
  34. outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 )
  35. end
  36. else
  37. outputChatBox( '[givemoney]:Player not found!',source,255,0,0 )
  38. end
  39. end
  40. )
  41.  
  42. function isPlayerInGroup (player, group)
  43. local playerAccount = getPlayerAccount ( player )
  44. if playerAccount then
  45. local accName = getAccountName ( playerAccount )
  46. if isObjectInACLGroup ("user."..accName, aclGetGroup ( group ) ) then
  47. return true
  48. end
  49. end
  50. return false
  51. end

Bad srgument @'getPlayerFromName [Expected  string at argument 1 , got nill]

 

and this code

  1. function enterVehicle (player, seat, jacked)
  2. local accName = getAccountName (getPlayerAccount (player)
  3. if not isObjectInACLGroup("user."..accName, aclGetGroup ( "VIP" )) and getElementModel(source) == 412 then
  4. cancelEvent()
  5. outputChatBox ( "you must be VIP to use this vehicle", player)
  6. end
  7. end
  8. addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle )

and this code is not working this spawn only car and give this car to those who is not VIP

Link to comment
local isPlayerInGroup, givemoney
     
local function givemoneycommand (player)
    if isPlayerInGroup (player, "VIP") then
        giveCash (player)
    else
        outputChatBox ("You must be VIP to use this command.", player,255,0, 0,true)
    end 
end
addCommandHandler("givemoney", givemoneycommand) 


  function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end
  
addCommandHandler( 'givemoney', 
    function( source,_,player,amount ) 
        local find = getPlayerFromPatrialName( player ) 
        if find 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 ) 
            else -- player not type full command ( /givemoney [nickname][amount] )  
                outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 ) 
            end  
        else 
            outputChatBox( '[givemoney]:Player not found!',source,255,0,0 ) 
        end 
    end 
)

function isPlayerInGroup (player, group)
    local playerAccount = getPlayerAccount ( player )
    if playerAccount then
        local accName = getAccountName ( playerAccount ) 
        if isObjectInACLGroup ("user."..accName, aclGetGroup ( group ) ) then 
            return true
        end
    end
    return false
end

try that

Link to comment
1 hour ago, Dimos7 said:

local isPlayerInGroup, givemoney
     
local function givemoneycommand (player)
    if isPlayerInGroup (player, "VIP") then
        giveCash (player)
    else
        outputChatBox ("You must be VIP to use this command.", player,255,0, 0,true)
    end 
end
addCommandHandler("givemoney", givemoneycommand) 


  function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end
  
addCommandHandler( 'givemoney', 
    function( source,_,player,amount ) 
        local find = getPlayerFromPatrialName( player ) 
        if find 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 ) 
            else -- player not type full command ( /givemoney [nickname][amount] )  
                outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 ) 
            end  
        else 
            outputChatBox( '[givemoney]:Player not found!',source,255,0,0 ) 
        end 
    end 
)

function isPlayerInGroup (player, group)
    local playerAccount = getPlayerAccount ( player )
    if playerAccount then
        local accName = getAccountName ( playerAccount ) 
        if isObjectInACLGroup ("user."..accName, aclGetGroup ( group ) ) then 
            return true
        end
    end
    return false
end

try that

error attempt to call global 'getPlayerFromPartialName' <a nil value>

 

Link to comment

local isPlayerInGroup, givemoney
     
local function givemoneycommand (player)
    if isPlayerInGroup (player, "VIP") then
        giveCash (player)
    else
        outputChatBox ("You must be VIP to use this command.", player,255,0, 0,true)
    end 
end
addCommandHandler("givemoney", givemoneycommand) 


  function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end
  
addCommandHandler( 'givemoney', 
    function( source,_,giveTo,amount ) 
        local find = getPlayerFromPatrialName( giveTo) 
        if find 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 ) 
            else -- player not type full command ( /givemoney [nickname][amount] )  
                outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 ) 
            end  
        else 
            outputChatBox( '[givemoney]:Player not found!',source,255,0,0 ) 
        end 
    end 
)

function isPlayerInGroup (player, group)
    local playerAccount = getPlayerAccount ( player )
    if playerAccount then
        local accName = getAccountName ( playerAccount ) 
        if isObjectInACLGroup ("user."..accName, aclGetGroup ( group ) ) then 
            return true
        end
    end
    return false
end

 

Link to comment
6 minutes ago, Dimos7 said:

local isPlayerInGroup, givemoney
     
local function givemoneycommand (player)
    if isPlayerInGroup (player, "VIP") then
        giveCash (player)
    else
        outputChatBox ("You must be VIP to use this command.", player,255,0, 0,true)
    end 
end
addCommandHandler("givemoney", givemoneycommand) 


  function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end
  
addCommandHandler( 'givemoney', 
    function( source,_,giveTo,amount ) 
        local find = getPlayerFromPatrialName( giveTo) 
        if find 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 ) 
            else -- player not type full command ( /givemoney [nickname][amount] )  
                outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 ) 
            end  
        else 
            outputChatBox( '[givemoney]:Player not found!',source,255,0,0 ) 
        end 
    end 
)

function isPlayerInGroup (player, group)
    local playerAccount = getPlayerAccount ( player )
    if playerAccount then
        local accName = getAccountName ( playerAccount ) 
        if isObjectInACLGroup ("user."..accName, aclGetGroup ( group ) ) then 
            return true
        end
    end
    return false
end

 

sorry, but the error is still same.

Link to comment
function enterVehicle (player, seat)
	if getElementModel(source) == 412 and seat == 0 then
		local accName = getAccountName(getPlayerAccount (player))
		if not isPlayerInGroup (player, "VIP") then
			cancelEvent()
			outputChatBox ( "you must be VIP to use this vehicle", player)
		end
	end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle )

---------
  
addCommandHandler( 'givemoney', 
    function( source,_,player,amount )
		if amount then
			if isPlayerInGroup(source,"Admin") then
				local find = findPlayer( player ) 
				if find 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 ) 
					else -- player not type full command ( /givemoney [nickname][amount] )  
						outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 ) 
					end  
				else 
					outputChatBox( '[givemoney]:Player not found!',source,255,0,0 ) 
				end 
			end
		else
			if isPlayerInGroup (source, "VIP") then
				giveCash (source)
			else
				outputChatBox ("You must be VIP to use this command.", source,255,0, 0,true)
			end
		end
    end
)

-- useful functions

function findPlayer(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

function isPlayerInGroup (player, group)
    local playerAccount = getPlayerAccount ( player )
    if playerAccount then
        local accName = getAccountName ( playerAccount ) 
        if isObjectInACLGroup ("user."..accName, aclGetGroup ( group ) ) then 
            return true
        end
    end
    return false
end

@Samking

Link to comment
function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end
  
     
function givemoneycommand (player, cmd, giveTo, amount)
     local find = getPlayerFromPartialName(giveTo)
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("VIP"))  then
        if find then
		    if amount then
               if getPlayerMoney(player) >= tonumber(amount) then
                   takePlayerMoney(player, tonumber(amount))
		           givePlayerMoney(find, tonumber(amount))
			       outputChatBox( '[givemoney]:You transfer $'..amount..' to '..getPlayerName( find ),player,0,255,0 ) 
              else
                  outputChatBox('[givemoney]:You don't have that amount!', player, 255, 0, 0)
              end
			else
			   outputChatBox( '[givemoney]:/'..cmd..'[playername][amount]!',player,255,0,0 ) 
			end
			 outputChatBox( '[givemoney]:Player not found!',player,255,0,0 ) 
	    end
    else
        outputChatBox ("You must be VIP to use this command.", player,255,0, 0,true)
    end 
end
addCommandHandler("givemoney", givemoneycommand) 

 

Edited by Dimos7
Link to comment
function enterVehicle (player, seat)
	if getElementModel(source) == 412 and seat == 0 then
		local accName = getAccountName(getPlayerAccount (player))
		if not isPlayerInGroup (player, "VIP") then
			cancelEvent()
			outputChatBox ( "you must be VIP to use this vehicle", player)
		end
	end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle )

---------
  
addCommandHandler( 'givemoney', 
    function( source,_,player,amount )
		if amount then
			if isPlayerInGroup(source,"Admin") then
				local find = findPlayer( player ) 
				if find 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 ) 
					else -- player not type full command ( /givemoney [nickname][amount] )  
						outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 ) 
					end  
				else 
					outputChatBox( '[givemoney]:Player not found!',source,255,0,0 ) 
				end 
			end
		else
			if isPlayerInGroup (player, "VIP") then
				giveCash (player)
			else
				outputChatBox ("You must be VIP to use this command.", source,255,0, 0,true)
			end
		end
    end
)

-- useful functions

function findPlayer(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

function isPlayerInGroup (player, group)
    local playerAccount = getPlayerAccount ( player )
    if playerAccount then
        local accName = getAccountName ( playerAccount ) 
        if isObjectInACLGroup ("user."..accName, aclGetGroup ( group ) ) then 
            return true
        end
    end
    return false
end

 

Link to comment
1 hour ago, JeViCo said:

function enterVehicle (player, seat)
	if getElementModel(source) == 412 and seat == 0 then
		local accName = getAccountName(getPlayerAccount (player))
		if not isPlayerInGroup (player, "VIP") then
			cancelEvent()
			outputChatBox ( "you must be VIP to use this vehicle", player)
		end
	end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle )

---------
  
addCommandHandler( 'givemoney', 
    function( source,_,player,amount )
		if amount then
			if isPlayerInGroup(source,"Admin") then
				local find = findPlayer( player ) 
				if find 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 ) 
					else -- player not type full command ( /givemoney [nickname][amount] )  
						outputChatBox( '[givemoney]:/givemoney [playername][amount]!',source,255,0,0 ) 
					end  
				else 
					outputChatBox( '[givemoney]:Player not found!',source,255,0,0 ) 
				end 
			end
		else
			if isPlayerInGroup (source, "VIP") then
				giveCash (source)
			else
				outputChatBox ("You must be VIP to use this command.", source,255,0, 0,true)
			end
		end
    end
)

-- useful functions

function findPlayer(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

function isPlayerInGroup (player, group)
    local playerAccount = getPlayerAccount ( player )
    if playerAccount then
        local accName = getAccountName ( playerAccount ) 
        if isObjectInACLGroup ("user."..accName, aclGetGroup ( group ) ) then 
            return true
        end
    end
    return false
end

@Samking

Thanks :D 

  • Like 1
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...