Jump to content

Problem


S3Nn4oX

Recommended Posts

I have a problem with my code, it doesn't show the messages when I type /troll <someonenotexists> it doesn't send me a message and it doesn't do the function, No debug errors,warnings

 

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 CRC_MAIN( cmd, thePlayer ,who, targetPlayer, sourcePlayer)
	setTimer ( CRC_MAIN, 10000, 0 ) 
	if thePlayer and isElement(thePlayer) and getElementType ( thePlayer ) == 'player' then
	local targetPlayer = getPlayerFromPartialName ( who )
	local r, g, b = math.random( 255 ), math.random( 255 ), math.random( 255 )
	local aPlayer = isPedInVehicle ( targetPlayer ) and getPedOccupiedVehicle ( targetPlayer ) or thePlayer
			if isPedInVehicle(thePlayer) then
				if targetPlayer then
					if aPlayer then
						outputChatBox("#3d87ffCRC By @SpRoXx #FFFFFFThe Player #FFFFFFTrolling!", sourcePlayer, 255, 0, 0, true)
						outputChatBox("#3d87ffCRC By @SpRoXx #FFFFFFif you want to troll someone You've to wait 1 minute, to use the command again.", sourcePlayer, 255, 0, 0, true)
						setVehicleColor(targetPlayer, r, g, b)
					else
						outputChatBox("#3d87ffCRC By @SpRoXx #FFFFFFThe Player #FFFFFFis not in a Vehicle.", sourcePlayer, 255, 0, 0, true)
 		   			end
 				else
 					outputChatBox("#3d87ffCRC By @SpRoXx #FFFFFFThe Player #FFFFFFDoesn't exists.", sourcePlayer, 255, 0, 0, true)
 				end
 			else
 				outputChatBox("#3d87ffCRC By @SpRoXx #FFFFFFYou must be in a vehicle to troll someone", sourcePlayer, 255, 0, 0, true)
   		    end
   	end

end
addCommandHandler("troll", CRC_MAIN)


function untroll( cmd, who, thePlayer )
	local targetPlayer = getPlayerFromPartialName ( who )
		if isPedInVehicle( targetPlayer ) then
			if targetPlayer then
				if isPedInVehicle(targetPlayer) then
					setVehicleColor (targetPlayer, 255,255,255)
				else
					outputChatBox("#3d87ffCRC By @SpRoXx #FFFFFFThe Player #FFFFFFis not in a Vehicle.", thePlayer, 255, 0, 0, true)
 		   		end
 			else
 				outputChatBox("#3d87ffCRC By @SpRoXx #FFFFFFThe Player #FFFFFFDoesn't exists.", thePlayer, 255, 0, 0, true)
 			end
 		else
 			outputChatBox("#3d87ffCRC By @SpRoXx #FFFFFFYou must be in a vehicle to troll someone", thePlayer, 255, 0, 0, true)
   	    end
end
addCommandHandler("untroll", untroll)

function firstMessage()
	outputChatBox("#3d87ffCRC By @SpRoXx #FFFFFFHas Loaded, /troll <playerName> to troll someone in a Vehicle. ", thePlayer, 255, 0, 0, true)
end
addEventHandler("onResourceStart", root, firstMessage)

Thanks.

Edited by S3Nn4oX
Link to comment

Use this 

function CRC_MAIN( cmd, thePlayer ,who, targetPlayer, sourcePlayer)
	setTimer ( CRC_MAIN, 10000, 0 ) 
	if thePlayer and ( getPlayerFromName ( thePlayer ) ) then
	if not ( who ) then return end
	if not ( sourcePlayer ) or not( getPlayerFromName ( sourcePlayer )  ) then return end
	local targetPlayer = getPlayerFromPartialName ( who )
	local r, g, b = math.random( 255 ), math.random( 255 ), math.random( 255 )
	local aPlayer = isPedInVehicle ( targetPlayer ) and getPedOccupiedVehicle ( targetPlayer ) or getPlayerFromName ( thePlayer )
			if isPedInVehicle(getPlayerFromName ( thePlayer )) then
				if targetPlayer then
					if aPlayer then
						outputChatBox("#3d87ffCRC By @SpRoXx #FFFFFFThe Player #FFFFFFTrolling!", getPlayerFromName ( sourcePlayer ), 255, 0, 0, true)
						outputChatBox("#3d87ffCRC By @SpRoXx #FFFFFFif you want to troll someone You've to wait 1 minute, to use the command again.", getPlayerFromName ( sourcePlayer ), 255, 0, 0, true)
						setVehicleColor(getPedOccupiedVehicle ( targetPlayer ), r, g, b)
					else
						outputChatBox("#3d87ffCRC By @SpRoXx #FFFFFFThe Player #FFFFFFis not in a Vehicle.", getPlayerFromName ( sourcePlayer ), 255, 0, 0, true)
 		   			end
 				else
 					outputChatBox("#3d87ffCRC By @SpRoXx #FFFFFFThe Player #FFFFFFDoesn't exists.", getPlayerFromName ( sourcePlayer ), 255, 0, 0, true)
 				end
 			else
 				outputChatBox("#3d87ffCRC By @SpRoXx #FFFFFFYou must be in a vehicle to troll someone", getPlayerFromName ( sourcePlayer ), 255, 0, 0, true)
   		    end
   	end
end
addCommandHandler("troll", CRC_MAIN)

 

and say player name in f8 

ex : troll abdulKarim ali yaser

and Please interpreted what want do 

and Even i give you edit your request

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