Jump to content

[HELP] Job


ViRuZGamiing

Recommended Posts

Posted

Hello,

My script doesn't work, no errors but debug says expect "(" at line 9 near jobScreenMenu

-- Locals 
local deliverMarker = createMarker(80.1, -301, 0.6, "cylinder", 3, 0, 225, 0, 0 ) 
local exitMarker = createMarker(89.7, -313.89999, 0.6, "cylinder", 3, 0, 155, 255, 30 ) 
local entranceMarker = createMarker(89.7, -317.5, 0.6, "cylinder", 3, 0, 155, 255, 30 ) 
local startMarker = createMarker(89.9, -323.29999, 0.6, "cylinder", 1, 0, 155, 255, 30 ) 
  
-- Functions 
function jobGui 
     jobScreenMenu = guiCreateWindow ( 0.15, 0.33, 0.7, 0.34, "Forklift Job", true ) 
     jobScreenCloseButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "Close", true, jobScreenMenu ) 
     jobScreenStartButton = guiCreateButton ( 0.4, 0.50, 0.20, 0.15, "Start Job!", true, jobScreenMenu ) 
     guiWindowSetMovable ( jobScreenMenu, false ) 
     guiWindowSetSizable ( jobScreenMenu, false ) 
     guiSetVisible ( jobScreenMenu, false ) 
end 
  
function startJob 
    if getElementType ( hitElement ) == "player" and not isPedInVehicle (hitElement) then 
        local forklifts = math.random(1, 3) 
        if forklifts == 1 then 
            createVehicle (530, 76.0, -329.29999, 1.4)   
        elseif forklifts == 2 then 
            createVehicle (530,  74.0, -329.29999, 1.4)  
        elseif forklifts == 3 then 
            createVehicle (530, 72.0, -329.29999, 1.4)   
        end 
        warpPedIntoVehicle( hitElement, vehicle ) 
        setVehicleLocked ( vehicle, true )   
        local num = math.random(1, 3) 
        if num == 1 then 
            setElementModel(16) 
        elseif num == 2 then 
            setElementModel(71) 
        elseif num == 3 then 
            setElementModel(260) 
        end 
    end 
end 
  
function showGui 
    guiSetVisible ( jobScreenMenu, true ) 
end 
  
function closeButton 
    guiSetVisible ( jobScreenMenu, false ) 
end 
  
-- Test part 
boxCol = createColCircle ( x, y, radius ) 
boxModel = createElement ( 2912, x, y, z ) 
setElementCollisionsEnabled ( boxModel, false ) 
  
function getBox 
    if getElementsWithinColShape ( boxCol, boxModel ) and getElementsWithinColShape ( boxCol, "player" ) then 
    setElementPosition ( boxModel, x, y, z ) 
    end 
end 
  
function boxDeliver 
    if getElementModel == 2912 then 
    destroyElement ( boxModel ) 
    givePlayerMoney ( 50 ) 
    end 
end 
  
--Go Inside / Outside 
function goInside 
    setElementPosition ( "player", 89.8, -321.39999, 1.6 ) 
    setElementRotation ( "player", 180 ) 
end 
  
function goOutside 
    setElementPosition ( "player", 89.8, -308.89999, 1.6 ) 
end 
  
-- DO NOT REMOVE!!  
function authorIs 
    outputChatBox("Hello,") 
    outputChatBox("This script is made by Viruzgamiing!") 
    outputChatBox("Thanks for using my script...") 
    outputChatBox("Please don't steal any credits!") 
    outputChatBox(" ") 
    outputChatBox("Thanks You!") 
end 
  
-- Handlers 
addCommandHandler ("info", authorIs ) 
addEventHandler ("onMarkerHit", exitMarker, goOutside ) 
addEventHandler ("onMarkerHit", entranceMarker, goInside ) 
addEventHandler ( "onMarkerHit", startMarker , showGui ) 
addEventHandler ( "onMarkerHit", deliverMarker , boxDeliver ) 
addEventHandler ( "onClientGUIClick", jobScreenStartButton, startJob ) 
addEventHandler ( "onClientGUIClick", jobScreenStopButton, closeButton ) 
addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), jobGui ) 
  
--TEST 
  
--[[     
     
     
     
     
     
     
     
     
     
     
     
  
]]-- 

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

  • Moderators
Posted
function jobGui  
  
-- to 
  
function jobGui () 

and the same with all other custom functions.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

Still got some problems;

/debugscript 3

debug.png

-- Locals 
-- Functions 
function jobGui () 
     jobScreenMenu = guiCreateWindow ( 0.15, 0.33, 0.7, 0.34, "Forklift Job", true ) 
     jobScreenCloseButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "Close", true, jobScreenMenu ) 
     jobScreenStartButton = guiCreateButton ( 0.4, 0.50, 0.20, 0.15, "Start Job!", true, jobScreenMenu ) 
     guiWindowSetMovable ( jobScreenMenu, false ) 
     guiWindowSetSizable ( jobScreenMenu, false ) 
     guiSetVisible ( jobScreenMenu, false ) 
end 
  
function showGui () 
    guiSetVisible ( jobScreenMenu, true ) 
end 
  
function closeButton () 
    guiSetVisible ( jobScreenMenu, false ) 
end 
  
-- Handlers 
addEvent ( "showGui", showGui ) 
addEventHandler ( "onMarkerHit", deliverMarker , boxDeliver ) 
addEventHandler ( "onClientGUIClick", jobScreenStopButton, closeButton ) 
addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), jobGui ) 
  
--TEST 
  
--[[     
         
         
         
         
         
         
         
         
         
         
         
]]-- 

Server

  
local blipAttach = createBlipAttachedTo(entranceMarker, 11) 
local deliverMarker = createMarker(80.1, -301, 0.6, "cylinder", 3, 0, 225, 0, 0 ) 
local exitMarker = createMarker(89.7, -313.89999, 0.6, "cylinder", 3, 0, 155, 255, 30 ) 
local entranceMarker = createMarker(89.7, -317.5, 0.6, "cylinder", 3, 0, 155, 255, 30 ) 
local startMarker = createMarker(89.9, -323.29999, 0.6, "cylinder", 1, 0, 155, 255, 30 ) 
local boxCol = createColCircle ( bx, by, 2 ) 
local boxModel = createElement ( 2912, x, y, z ) 
local setDamage = setElementCollisionsEnabled ( boxModel, false ) 
local x, y, z = getElementPosition ( forklifts ) 
local bx, by = getElementPosition ( boxModel ) 
  
function authorIs () 
    outputChatBox("Hello,", localPlayer) 
    outputChatBox("This script is made by Viruzgamiing!", localPlayer) 
    outputChatBox("Thanks for using my script...", localPlayer) 
    outputChatBox("Please don't steal any credits!", localPlayer) 
    outputChatBox(" ", localPlayer) 
    outputChatBox("Thanks You!", localPlayer) 
end 
  
function startJob () 
    if getElementType ( hitElement ) == player and not isPedInVehicle (hitElement) then 
        local forklifts = math.random(1, 3) 
        if forklifts == 1 then 
            createVehicle (530, 76.0, -329.29999, 1.4)   
        elseif forklifts == 2 then 
            createVehicle (530,  74.0, -329.29999, 1.4)  
        elseif forklifts == 3 then 
            createVehicle (530, 72.0, -329.29999, 1.4)   
        end 
        warpPedIntoVehicle( hitElement, forklifts ) 
        setVehicleLocked ( forklifts, true )   
        local num = math.random(1, 3) 
        if num == 1 then 
            setElementModel(16) 
        elseif num == 2 then 
            setElementModel(71) 
        elseif num == 3 then 
            setElementModel(260) 
        end 
    end 
end 
) 
  
--Go Inside / Outside 
function goInside () 
    setElementPosition ( localPlayer, 89.8, -321.39999, 1.6 ) 
    setElementRotation ( localPlayer, 180 ) 
end 
  
function goOutside () 
    setElementPosition ( localPlayer, 89.8, -308.89999, 1.6 ) 
end 
  
function showClient () 
    TriggerClientEvent (localPlayer, "showGui", getRootElement() ) 
end 
  
function getBox () 
    if getElementsWithinColShape ( boxCol, boxModel ) and getElementsWithinColShape ( boxCol, localPlayer ) then 
    setElementPosition ( boxModel, x, y, z ) 
    end 
end 
  
function boxDeliver () 
    if getElementModel == 2912 then 
    destroyElement ( boxModel ) 
    givePlayerMoney ( 50 ) 
    end 
end 
  
addCommandHandler ("info", authorIs ) 
addEventHandler ("onMarkerHit", exitMarker, goOutside ) 
addEventHandler ("onMarkerHit", entranceMarker, goInside ) 
addEventHandler ( "onMarkerHit", startMarker , showClient ) 
addEventHandler ( "onClientGUIClick", jobScreenStartButton, startJob) 
  

I've changed my script so I have a server-side too but I did that after I took the screenshot of the debug IDK then new debug

Please tell me whats wrong,

Thanks Viruz

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

The line 19 of the client side script doesn't have anything wrong.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
The line 19 of the client side script doesn't have anything wrong.

Yes I know that the weird thing I will send a new debug

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted
-- Console Errors 
  
[17:55:29] WARNING: Forklift\server.lua:1: Bad argument @ 'createBlipAttachedTo' 
  
[17:55:29] WARNING: Forklift\server.lua:6: Bad argument @ 'createColCircle' 
[17:55:29] WARNING: Forklift\server.lua:9: Bad argument @ 'getElementPosition' [ 
Expected element at argument 1, got nil] 
[17:55:29] WARNING: Forklift\server.lua:75: Bad argument @ 'addEventHandler' [Ex 
pected element at argument 2, got nil] 

debugv5Rsh.png

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

I want the Crates from the bottom lines in Client to spawn 1 random of all and if you drive close to it with the forklift (you enter the Crate's ColCircle) it puts the crate to a new position (on the Forklift) and you drive it to deliverMarker it destroys the Crate and gives you 50$ and spawns a new crate random spot

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

localPlayer is client side only.

hitElement is not defined anywhere.

player is not defined anywhere.

forklifts is a number, not vehicle element.

setElementModel requires 2 arguments.

getElementModel requires 1 argument.

setElementRotation requires 4 arguments.

TriggerClientEvent function does not exists.

givePlayerMoney requires 2 arguments.

onClientGUIClick is client side event only.

CiTLh.png
Posted

Okay i'm going to edit it and post it when it's fixed as far as I get it

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted
-- SERVER 
  
-- Locals 
local deliverMarker = createMarker(80.1, -301, 0.6, "cylinder", 3, 0, 225, 0, 0 ) 
local exitMarker = createMarker(89.7, -313.89999, 0.6, "cylinder", 3, 0, 155, 255, 30 ) 
local entranceMarker = createMarker(89.7, -317.5, 0.6, "cylinder", 3, 0, 155, 255, 30 ) 
local blipAttach = createBlipAttachedTo(entranceMarker, 11) 
local startMarker = createMarker(89.9, -323.29999, 0.6, "cylinder", 1, 0, 155, 255, 30 ) 
  
function authorIs () 
    outputChatBox("Hello,", localPlayer) 
    outputChatBox("This script is made by Viruzgamiing!", thePlayer) 
    outputChatBox("Thanks for using my script...", thePlayer) 
    outputChatBox("Please don't steal any credits!", thePlayer) 
    outputChatBox(" ", thePlayer) 
    outputChatBox("Thanks You!", thePlayer) 
end 
  
function startJob () 
    if getElementType ( hitElement ) == thePlayer and not isPedInVehicle (hitElement) then 
        local forklifts = math.random(1, 3) 
        if forklifts == 1 then 
            createVehicle (530, 76.0, -329.29999, 1.4)  
        elseif forklifts == 2 then 
            createVehicle (530,  74.0, -329.29999, 1.4)  
        elseif forklifts == 3 then 
            createVehicle (530, 72.0, -329.29999, 1.4)  
        end 
        warpPedIntoVehicle( hitElement, forklifts ) 
        setVehicleLocked ( forklifts, true )   
        local num = math.random(1, 3) 
        if num == 1 then 
            setElementModel(thePlayer, 16) 
        elseif num == 2 then 
            setElementModel(thePlayer, 71) 
        elseif num == 3 then 
            setElementModel(thePlayer, 260) 
        end 
            theController = getVehicleController ( thePlayer ) 
            if ( theController ) then 
                local crates = math.random(1, 12) 
                    if crates == 1 then 
                        createObject(2912, 55.1, -302.10001, 0.7) 
                    elseif crates == 2 then 
                        createObject(2912, 46.3, -321, 0.7) 
                    elseif crates == 3 then 
                        createObject(2912, 35.3, -308.29999, 0.7) 
                    elseif crates == 4 then 
                        createObject(2912, 26.9, -321.89999, 0.7) 
                    elseif crates == 5 then 
                        createObject(2912, 39.4, -329.70001, 0.7) 
                    elseif crates == 6 then 
                        createObject(2912, 59.5, -321.60001, 0.7) 
                    elseif crates == 7 then 
                        createObject(2912, 49.1, -312.29999, 0.7) 
                    elseif crates == 8 then 
                        createObject(2912, 63.7, -311.39999, 0.7) 
                    elseif crates == 9 then 
                        createObject(2912, 43.7, -301.70001, 0.7) 
                    elseif crates == 10 then 
                        createObject(2912, 27.7, -298.60001, 0.7) 
                    elseif crates == 11 then 
                        createObject(2912, 21.5, -311.39999, 0.7) 
                    elseif crates == 12 then 
                        createObject(2912, 73.3, -307.60001, 0.7) 
                    end 
            end 
    end 
end 
  
  
-- Extra Locals 
local x,y,z = getElementPosition( forklifts ) 
local boxModel = createElement ( 2912, x, y, z ) 
local bx, by = getElementPosition ( boxModel ) 
local boxCol = createColCircle ( bx, by, 2 ) 
local setDamage = setElementCollisionsEnabled ( boxModel, false ) 
  
--Go Inside / Outside 
function goInside () 
    setElementPosition ( thePlayer,  89.8, -321.39999, 1.6 ) 
    setElementRotation ( thePlayer, 180, 0, 0 ) 
end 
  
function goOutside () 
    setElementPosition ( thePlayer, 89.8, -308.89999, 1.6 ) 
end 
  
function showClient () 
    TriggerClientEvent ( thePlayer, "showGui") 
end 
  
function getBox () 
    if getElementsWithinColShape ( boxCol, boxModel ) and getElementsWithinColShape ( boxCol, thePlayer ) then 
    setElementPosition ( boxModel, x, y, z ) 
    end 
end 
  
function boxDeliver () 
    if getElementModel == 2912 then 
    destroyElement ( boxModel ) 
    givePlayerMoney ( thePlayer, 50 ) 
    end 
end 
  
addCommandHandler ("info", authorIs ) 
addEventHandler ("onMarkerHit", exitMarker, goOutside ) 
addEventHandler ("onMarkerHit", entranceMarker, goInside ) 
addEventHandler ( "onMarkerHit", startMarker , showClient ) 
addEventHandler ( "onClientGUIClick", jobScreenStartButton, startJob) 
  

-- CLIENT 
  
-- Functions 
function jobGui () 
     jobScreenMenu = guiCreateWindow ( 0.15, 0.33, 0.7, 0.34, "Forklift Job", true ) 
     jobScreenCloseButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "Close", true, jobScreenMenu ) 
     jobScreenStartButton = guiCreateButton ( 0.4, 0.50, 0.20, 0.15, "Start Job!", true, jobScreenMenu ) 
     guiWindowSetMovable ( jobScreenMenu, false ) 
     guiWindowSetSizable ( jobScreenMenu, false ) 
     guiSetVisible ( jobScreenMenu, false ) 
end 
  
function showGui () 
    guiSetVisible ( jobScreenMenu, true ) 
end 
  
function closeButton () 
    guiSetVisible ( jobScreenMenu, false ) 
end 
  
-- Handlers 
addEvent ( "showGui", true ) 
addEventHandler ( "showGui", getRootElement(), showGui ) 
addEventHandler ( "onMarkerHit", deliverMarker , boxDeliver ) 
addEventHandler ( "onClientGUIClick", jobScreenStopButton, closeButton ) 
addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), jobGui ) 
]]-- 

@TAPL how can I fix the Client onClientGuiClick?

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

Tell me which?

With this script i'm trying to understand more Events and stuff.

Most of this is new to me.

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

  • Moderators
Posted
Tell me which?

With this script i'm trying to understand more Events and stuff.

Most of this is new to me.

As I said in the pm I send you.

Hoe word de source gecreëerd. Nou eigenlijk alleen door Events.

http://imageshack.us/photo/my-images/809/ttos.png/

http://imageshack.us/photo/my-images/132/xlzz.png/

getRootElement()/root of source

http://img703.imageshack.us/img703/3164/ds6n.png

Het is niet zomaar wat neerzetten.

(1) Het is kijken wat je hebt.

En als je wat mist dan:

(2) Kijken wat je mist.

(3) Kijken hoe je er aan komt.

Everything that is required, must be defined before it can work.

Line 10 t/m end function:

Not defined.

localPlayer

thePlayer

Line 19 t/m end function:

Not defined.

hitElement

thePlayer

Line 80 t/m end function:

Not defined.

thePlayer

ETC.

Sample how to define things:

First read wiki mta.

So for the first function:

https://wiki.multitheftauto.com/wiki/AddCommandHandler

Then you see: Handler function parameters

Choose between client and server parameters.(what kind of script it is)

There you find for serverside: (parameters)

player playerSource, string commandName, [string arg1, string arg2, ...] 

Not required to fill in.

[string arg1, string arg2, ...] 

Then we can fill in the script.

The parameters are:

player playerSource, string commandName, [string arg1, string arg2, ...] 

  
function authorIs () -- not filled in 
  
function authorIs (thePlayer,commandName) -- filled in. 
  

You can name them as you want as long, as you know what they mean.

and so...........

  
function authorIs (thePlayer,commandName) -- we just filled in the arguments 
    outputChatBox("Hello,", thePlayer) 
    outputChatBox("This script is made by Viruzgamiing!", thePlayer) 
    outputChatBox("Thanks for using my script...", thePlayer) 
    outputChatBox("Please don't steal any credits!", thePlayer) 
    outputChatBox(" ", thePlayer) 
    outputChatBox("Thanks You!", thePlayer) 
end 
  
addCommandHandler ("info", authorIs ) 
  

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

1. Do I need to define commandName?

2. Isn't localPlayer and thePlayer automaticly defined by MTA?

Or should I do

local localPlayer = getLocalPlayer(player) 

and what for thePlayer? because thePlayer is server-side.

You can use the predefined variable localPlayer instead of typing getLocalPlayer()

3. Should I use

addEventHandler ( "onColShapeHit", boxCol, hitElement) 

With what function can I define hitElement? Maybe with a "if" that checks if there's a forklift in "boxCol"?

Extra: I don't want to use addCommandHandler exept for the info command, everything else needs to be trigger by event.

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

1. What do you mean by "Do I need to define commandName" ?

2. localPlayer is automaticly defined by MTA ( in client-side only ) but thePlayer is not .

3. You should do something like this :

function aFunction( hitElement ) 
end 
addEventHandler( "onColShapeHit", boxCol, aFunction ) 

" Keep Thinking Different . " - Steve Jops

--------------------

Don't send me PMs asking for help, I Won't reply !

Posted

In server-side, the player is defined once needed, for e.g. :

If you want to define him with a command, it will be like this :

addCommandHandler( "cmd", function( thePlayer ) 
    -- 
end ) 

Also, a lot of events have the player as a source or an argument .

" Keep Thinking Different . " - Steve Jops

--------------------

Don't send me PMs asking for help, I Won't reply !

Posted

+ How should I arrange this,

Forklifts and Crates needs to be the spawned forklift and spawned crate but in getElementPosition you need to fill in an ID.

local x,y,z = getElementPosition ( forklifts ) 
local bx,by,bz = getElementPosition ( crates ) 
local fx,fy,fz = setElementPosition ( x+1,y,z+1 ) 
local boxCol = createColCircle ( bx, by, 2 ) 
local setDamage = setElementCollisionsEnabled ( crates, false ) 

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

Can I just do;

function definePlayer (thePlayer) 
end 
  
addEventHandler("onResourceStart", definePlayer) 

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

Can you (Pain^) or someone else please just send a fixed version so I can see my mistakes and then learn from them?

If I don't get something I will reply here

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

What we put in the brackets aren't random or come from nowhere.

It's called parameters, we know the parameters from the wiki.

The event onResourceStart has only one parameter and it not player but the resource that started.

Also addEventHandler requires 3 arguments (you can see this from the wiki).

CiTLh.png
Posted
someone else please just send a fixed version so I can see my mistakes and then learn from them?

If I don't get something I will reply here

Can you TAPL? Please

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

  • Moderators
Posted
1. Do I need to define commandName?

2. Isn't localPlayer and thePlayer automaticly defined by MTA?

Or should I do

local localPlayer = getLocalPlayer(player) 

and what for thePlayer? because thePlayer is server-side.

You can use the predefined variable localPlayer instead of typing getLocalPlayer()

3. Should I use

addEventHandler ( "onColShapeHit", boxCol, hitElement) 

With what function can I define hitElement? Maybe with a "if" that checks if there's a forklift in "boxCol"?

Extra: I don't want to use addCommandHandler exept for the info command, everything else needs to be trigger by event.

1

You only have to defined what you need. But make sure it is there.....

http://img43.imageshack.us/img43/2921/e9kp.png

and remember, the way you fix/build your script, is more important than having it finished.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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