DriFtyZ

[QUESTION] what are Useful functions for?

Recommended Posts

Hello people, i noticed on the wiki there are some function called Useful functions, how can i use them? what are they exactly?

Share this post


Link to post

They are functions / code snippets developed by individuals like you, me or any other developer that think their code would help others. For example there's a function called IsMouseInPosition which is not implemented in MTA, you have to code it yourself, but somebody else already did and put it up there. If I was to use it, all I had to do is copy the whole function, paste it in your script and use it as you would use any other functions like:

-- My code


addEventHandler("onClientResourceStart", resourceRoot, function()

    if isMouseInPosition ( some X, some Y, some Width, some Height) then
      -- code
    end
    
end)



-- Useful functions
function isMouseInPosition ( x, y, width, height )
	if ( not isCursorShowing( ) ) then
		return false
	end
    local sx, sy = guiGetScreenSize ( )
    local cx, cy = getCursorPosition ( )
    local cx, cy = ( cx * sx ), ( cy * sy )
    if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then
        return true
    else
        return false
    end
end

 

  • Like 1

Share this post


Link to post

damn @pa3ck you beat me to it :D Just had to erase 20 lines of writing because you said them :v

  • Like 1

Share this post


Link to post
2 minutes ago, koragg said:

damn @pa3ck you beat me to it :D Just had to erase 20 lines of writing because you said them :v

Ah, sorry man, there should be a feature that shows "Somebody else is writing a post.." or something, didn't realize you were about to send a reply. :)

Share this post


Link to post

thank you, i was so dumb that just tried to use only a useful function without copying the code below 

Share this post


Link to post

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.