Jump to content

I need some help with a few lines


FlorjanMTARP

Recommended Posts

Posted

Alright,I'm planning to code the line which will open a GUI on a location. I've set this:

local g_Distance = getDistanceBetweenPoints3D 
  
if ( g_Distance <= 5 ) then 

So,The distance is 5. Now the whole script:

function drink () 
outputChatBox("true") 
showCursor( false ) 
  
local g_Distance = getDistanceBetweenPoints3D 
  
if ( g_Distance <= 5 ) then 
  
outputChatBox ("Welcome to the Bar!", 255,255,0, true ) 
  
end  
  
-- DESIGN -- 
bg = guiCreateStaticImage(0.32, 0.14, 0.35, 0.68, "img/bg.png", true, border) 
border = guiCreateStaticImage(0.36, 0.18, 0.27, 0.0015, "img/border.png", true) 
drinks = guiCreateLabel(0.445, 0.15, 0.19, 0.03, "DRINKS & FOOD", true) 
  
-- FOOD -- 
salad_meal = guiCreateStaticImage(0.34, 0.21, 0.06, 0.09, "img/salad_meal.png", true)     
sm_n = guiCreateLabel(0.41, 0.21, 0.14, 0.03, "Cold Salad Meal", true) 
sm_t = guiCreateLabel(0.41, 0.24, 0.19, 0.05, "Salad Meal is most healthy of all.", true) 
sm_t2 = guiCreateLabel(0.41, 0.26, 0.19, 0.05, "Price: $15", true)   
buySM = guiCreateStaticImage(0.61, 0.27, 0.05, 0.03, "img/buy.png", true)   
  
guiSetEnabled( bg, false ) 
guiSetEnabled( border, false ) 
guiSetEnabled( drinks, false ) 
guiSetEnabled( salad_meal, false ) 
guiSetEnabled( sm_t, false ) 
guiSetEnabled( sm_t2, false ) 
guiSetEnabled( sm_n, false ) 
  
  
  
-- Nadpis jidelnicku -- 
WalkWay = guiCreateFont( "ww.ttf", 20 ) 
guiSetFont( drinks, WalkWay )  
  
  
-- Nadpis jidel -- 
WalkWay2 = guiCreateFont( "ww.ttf", 15 ) 
guiSetFont( sm_n, WalkWay2 ) 
  
  
-- Text jidel -- 
WalkWay3 = guiCreateFont( "ww.ttf", 11 ) 
guiSetFont( sm_t, WalkWay3 ) 
guiSetFont( sm_t2, WalkWay3 ) 
  
  
addEventHandler ( "onClientGUIClick", buySM, boughtSM, false) 
end 
  
  
-- CLICK -- 
-- SALAD MEAL -- 
  
function boughtSM ( button ) 
    if button == "left" then 
    local g_Money = getPlayerMoney() -- define it inside the function. 
    if ( g_Money >= 15 ) then -- >= greater than or equal to. 
    outputChatBox ("#ffffffYou bought Salad Meal", 255,255,255, true ) 
    takePlayerMoney (15) 
    else 
    outputChatBox ("#ff0000Sorry, you have not got enough money", 255,255,255, true ) 
     -- takePlayerMoney (0) -- no need for this. 
        end         
    end 
end 

So,All I want to do is. When the player gets closer to Ped,It opens the GUI.

Peace, Florjan

Posted
getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) 

But it wont work, as it will not update the position of the player. I would use col shape instead.

Posted

Where shall I insert it? I ended scripting 2years ago and I lost my skills,now I got invited as a dev + racer at a server and I wanna finish that.

I really need that..

An example please..

Peace,Florjan

Posted
  
setDevelopmentMode(true) 
function createCol() 
local x, y, z, width, depth, height = 0, 0, 0, 10, 5, 10 -- Define its position and size. 
  
tCol = createColCuboid( x, y, z, width, depth, height) 
end 
  
addEventHandler('onClientResourceStart', getResourceRootElement(getThisResource()), createCol) 
  
addEventHandler('onClientColShapeHit', getRootElement(), function() 
    if (source == tCol) then 
        outputChatBox('Hit') -- Put GUI here. 
    end 
end) 
  

Use /showcol to see the colshape.

Posted

Well I have another error. I've inserted the GUI and now it says that:

ERROR: Loading script failed: drink/drink.lua:68: 'end' expected (to close "if" at line 59) near 'eof'

The code:

setDevelopmentMode(true) 
function createCol() 
local x, y, z, width, depth, height = 2184.70, -3279.12, 1684.65, 10, 5, 10 -- Define its position and size. 
  
tCol = createColCuboid( x, y, z, width, depth, height) 
end 
  
addEventHandler('onClientResourceStart', getResourceRootElement(getThisResource()), createCol) 
  
addEventHandler('onClientColShapeHit', getRootElement(), function() 
    if (source == tCol) then 
        outputChatBox('Hit')  
-- DESIGN -- 
bg = guiCreateStaticImage(0.32, 0.14, 0.35, 0.68, "img/bg.png", true, border) 
border = guiCreateStaticImage(0.36, 0.18, 0.27, 0.0015, "img/border.png", true) 
drinks = guiCreateLabel(0.445, 0.15, 0.19, 0.03, "DRINKS & FOOD", true) 
  
-- FOOD -- 
salad_meal = guiCreateStaticImage(0.34, 0.21, 0.06, 0.09, "img/salad_meal.png", true)     
sm_n = guiCreateLabel(0.41, 0.21, 0.14, 0.03, "Cold Salad Meal", true) 
sm_t = guiCreateLabel(0.41, 0.24, 0.19, 0.05, "Salad Meal is most healthy of all.", true) 
sm_t2 = guiCreateLabel(0.41, 0.26, 0.19, 0.05, "Price: $15", true)   
buySM = guiCreateStaticImage(0.61, 0.27, 0.05, 0.03, "img/buy.png", true)   
  
guiSetEnabled( bg, false ) 
guiSetEnabled( border, false ) 
guiSetEnabled( drinks, false ) 
guiSetEnabled( salad_meal, false ) 
guiSetEnabled( sm_t, false ) 
guiSetEnabled( sm_t2, false ) 
guiSetEnabled( sm_n, false ) 
  
  
  
-- Nadpis jidelnicku -- 
WalkWay = guiCreateFont( "ww.ttf", 20 ) 
guiSetFont( drinks, WalkWay )  
  
  
-- Nadpis jidel -- 
WalkWay2 = guiCreateFont( "ww.ttf", 15 ) 
guiSetFont( sm_n, WalkWay2 ) 
  
  
-- Text jidel -- 
WalkWay3 = guiCreateFont( "ww.ttf", 11 ) 
guiSetFont( sm_t, WalkWay3 ) 
guiSetFont( sm_t2, WalkWay3 ) 
  
  
addEventHandler ( "onClientGUIClick", buySM, boughtSM, false) 
end 
  
  
-- CLICK -- 
-- SALAD MEAL -- 
  
function boughtSM ( button ) 
    if button == "left" then 
    local g_Money = getPlayerMoney() -- define it inside the function. 
    if ( g_Money >= 15 ) then -- >= greater than or equal to. 
    outputChatBox ("#ffffffYou bought Salad Meal", 255,255,255, true ) 
    takePlayerMoney (15) 
    else 
    outputChatBox ("#ff0000Sorry, you have not got enough money", 255,255,255, true ) 
     -- takePlayerMoney (0) -- no need for this. 
    end 
end) 
  

Damn.. I tried so many ways to fix it but none comes out good.

Posted

The error points out what is wrong and where. Read it, and you'll be able to fix it.

You forgot to end the last function. I'd suggest you use a program such as Notepad++ as it will display the connections.

Posted
The error points out what is wrong and where. Read it, and you'll be able to fix it.

You forgot to end the last function. I'd suggest you use a program such as Notepad++ as it will display the connections.

That's what I did.

I wrote end in all possible ways but none worked.

Posted
setDevelopmentMode(true) 
function createCol() 
local x, y, z, width, depth, height = 2184.70, -3279.12, 1684.65, 10, 5, 10 -- Define its position and size. 
  
tCol = createColCuboid( x, y, z, width, depth, height) 
end 
  
addEventHandler('onClientResourceStart', getResourceRootElement(getThisResource()), createCol) 
  
addEventHandler('onClientColShapeHit', getRootElement(), function() 
    if (source == tCol) then 
        outputChatBox('Hit') 
-- DESIGN -- 
bg = guiCreateStaticImage(0.32, 0.14, 0.35, 0.68, "img/bg.png", true, border) 
border = guiCreateStaticImage(0.36, 0.18, 0.27, 0.0015, "img/border.png", true) 
drinks = guiCreateLabel(0.445, 0.15, 0.19, 0.03, "DRINKS & FOOD", true) 
  
-- FOOD -- 
salad_meal = guiCreateStaticImage(0.34, 0.21, 0.06, 0.09, "img/salad_meal.png", true)     
sm_n = guiCreateLabel(0.41, 0.21, 0.14, 0.03, "Cold Salad Meal", true) 
sm_t = guiCreateLabel(0.41, 0.24, 0.19, 0.05, "Salad Meal is most healthy of all.", true) 
sm_t2 = guiCreateLabel(0.41, 0.26, 0.19, 0.05, "Price: $15", true)   
buySM = guiCreateStaticImage(0.61, 0.27, 0.05, 0.03, "img/buy.png", true)   
  
guiSetEnabled( bg, false ) 
guiSetEnabled( border, false ) 
guiSetEnabled( drinks, false ) 
guiSetEnabled( salad_meal, false ) 
guiSetEnabled( sm_t, false ) 
guiSetEnabled( sm_t2, false ) 
guiSetEnabled( sm_n, false ) 
  
  
  
-- Nadpis jidelnicku -- 
WalkWay = guiCreateFont( "ww.ttf", 20 ) 
guiSetFont( drinks, WalkWay ) 
  
  
-- Nadpis jidel -- 
WalkWay2 = guiCreateFont( "ww.ttf", 15 ) 
guiSetFont( sm_n, WalkWay2 ) 
  
  
-- Text jidel -- 
WalkWay3 = guiCreateFont( "ww.ttf", 11 ) 
guiSetFont( sm_t, WalkWay3 ) 
guiSetFont( sm_t2, WalkWay3 ) 
  
  
addEventHandler ( "onClientGUIClick", buySM, boughtSM, false) 
end 
  
  
-- CLICK -- 
-- SALAD MEAL -- 
  
function boughtSM ( button ) 
    if ( button == "left" ) then 
        local g_Money = getPlayerMoney ( ) -- define it inside the function. 
        if ( g_Money >= 15 ) then -- >= greater than or equal to. 
            outputChatBox ( "#ffffffYou bought Salad Meal", 255, 255, 255, true ) 
            takePlayerMoney ( 15 ) 
        else 
            outputChatBox ( "#ff0000Sorry, you have not got enough money", 255, 255, 255, true ) 
        end 
    end 
end 

P.S: If you take the money client side, it won't be synced with the server, so you have to take it server side.

Posted
setDevelopmentMode(true) 
function createCol() 
local x, y, z, width, depth, height = 2184.70, -3279.12, 1684.65, 10, 5, 10 -- Define its position and size. 
  
tCol = createColCuboid( x, y, z, width, depth, height) 
end 
  
addEventHandler('onClientResourceStart', getResourceRootElement(getThisResource()), createCol) 
  
addEventHandler('onClientColShapeHit', getRootElement(), function() 
    if (source == tCol) then 
        outputChatBox('Hit') 
-- DESIGN -- 
bg = guiCreateStaticImage(0.32, 0.14, 0.35, 0.68, "img/bg.png", true, border) 
border = guiCreateStaticImage(0.36, 0.18, 0.27, 0.0015, "img/border.png", true) 
drinks = guiCreateLabel(0.445, 0.15, 0.19, 0.03, "DRINKS & FOOD", true) 
  
-- FOOD -- 
salad_meal = guiCreateStaticImage(0.34, 0.21, 0.06, 0.09, "img/salad_meal.png", true)     
sm_n = guiCreateLabel(0.41, 0.21, 0.14, 0.03, "Cold Salad Meal", true) 
sm_t = guiCreateLabel(0.41, 0.24, 0.19, 0.05, "Salad Meal is most healthy of all.", true) 
sm_t2 = guiCreateLabel(0.41, 0.26, 0.19, 0.05, "Price: $15", true)   
buySM = guiCreateStaticImage(0.61, 0.27, 0.05, 0.03, "img/buy.png", true)   
  
guiSetEnabled( bg, false ) 
guiSetEnabled( border, false ) 
guiSetEnabled( drinks, false ) 
guiSetEnabled( salad_meal, false ) 
guiSetEnabled( sm_t, false ) 
guiSetEnabled( sm_t2, false ) 
guiSetEnabled( sm_n, false ) 
  
  
  
-- Nadpis jidelnicku -- 
WalkWay = guiCreateFont( "ww.ttf", 20 ) 
guiSetFont( drinks, WalkWay ) 
  
  
-- Nadpis jidel -- 
WalkWay2 = guiCreateFont( "ww.ttf", 15 ) 
guiSetFont( sm_n, WalkWay2 ) 
  
  
-- Text jidel -- 
WalkWay3 = guiCreateFont( "ww.ttf", 11 ) 
guiSetFont( sm_t, WalkWay3 ) 
guiSetFont( sm_t2, WalkWay3 ) 
  
  
addEventHandler ( "onClientGUIClick", buySM, boughtSM, false) 
end 
  
  
-- CLICK -- 
-- SALAD MEAL -- 
  
function boughtSM ( button ) 
    if ( button == "left" ) then 
        local g_Money = getPlayerMoney ( ) -- define it inside the function. 
        if ( g_Money >= 15 ) then -- >= greater than or equal to. 
            outputChatBox ( "#ffffffYou bought Salad Meal", 255, 255, 255, true ) 
            takePlayerMoney ( 15 ) 
        else 
            outputChatBox ( "#ff0000Sorry, you have not got enough money", 255, 255, 255, true ) 
        end 
    end 
end 

P.S: If you take the money client side, it won't be synced with the server, so you have to take it server side.

Thanks,I appreciate your hard work and your contributing towards MTA.

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