Jump to content

Robber Job [HELP]


Price.

Recommended Posts

this robber job got problem whenever i start it , it tells me @line 41 '=' expected near 'jobwindow' what iam trying to do is to make a math.random @ houses so when i rob a house other appears on map and so on

Client Side:

 robberHouses = 
{ 
    { 1887, -1113, 25 }; 
    { 2092, -1160, 25 }; 
    { 1896, -1165, 22 }; 
    { 2068, -1720, 13 }; 
    { 1970, -1671, 17 }; 
    { 1895, -1071, 23 }; 
    { 1940, -1066, 23 }; 
    { 1955, -1074, 23 }; 
    { 1960, -1069, 23 };  
    { 1956, -1115, 26 }; 
    { 1945, -1115, 26 }; 
    { 1924, -1115, 26 }; 
    { 1900, -1114, 26 }; 
    { 2596, -1237, 47 }; 
    { 2595, -1199, 58 }; 
    { 2516, -1028, 69 }; 
    { 2630, -1072, 68 }; 
    { 2794, -1246, 45 }; 
    { 2809, -1176, 25 }; 
    { 2586, -953, 80 }; 
} 
  
  
  function unpackRobberHouses () 
    return unpack ( robberHouses [ math.random ( #robberHouses ) ] ) 
end 
 addEventHandler("onResourceStart", root, unpackrobberHouses) 
  
    jobmarker = createMarker( 2054.4609375, -1759.5224609375, 13.549641609192, "cylinder", 1.5, 255, 153, 0, 150 ) 
    createBlip ( 2054.4609375, -1759.5224609375, 13.549641609192, 52 ) 
    
addEventHandler("onResourceStart",jobmarker,function(p) if p == lp and not 
isPedInVehicle(lp) then guiSetVisible(jobmarker,true) showCursor(true) end end) 
  
  
sx,sy = guiGetScreenSize()  
lp = getLocalPlayer()  
mr = math.random(1,2) e 
jobwindow = guiCreateWindow(0.3*sx,0.3*sy,0.4*sx,0.4*sy,"Criminal",false) 
sx,sy = 0.5*sx,0.5*sy 
memo = guiCreateMemo(0*sx,0.05*sy,0.8*sx,0.6*sy,"This is house robbing job press Accept and then a red house will appear on your minimap go to the red house blip and rob the house!",false,jobwindow) 
takebutton = guiCreateButton(0.25,0.9,0.2,0.18,"Accept",true,jobwindow) 
cancbutton = guiCreateButton(0.55,0.9,0.2,0.18,"Cancel",true,jobwindow) 
guiSetVisible (jobwindow,false)  
guiMemoSetReadOnly(memo,true)  
guiWindowSetMovable (jobwindow,false )  
guiWindowSetSizable (jobwindow,false ) 
  
addEventHandler("onClientGUIClick",jobwindow, 
function(b) 
    if b == "left" then 
        if source == takebutton then 
            if getTeamName(getPlayerTeam(lp)) ~= "Criminal" then 
            triggerServerEvent ( "HaveCriminalJob", lp) 
            outputChatBox ("You are now now employed as a Criminal",255,255,0, true) 
            guiSetVisible(jobwindow,false) 
            showCursor(false) 
            end 
        elseif source == cancbutton then 
        guiSetVisible(jobwindow,false) 
        showCursor(false) 
        end 
    end 
end) 
  
  
addEventHandler("onClientMarkerHit",jobmarker, 
        function(p) 
             if p == lp and not isPedInVehicle(lp) then 
                 guiSetVisible(jobwindow,true) 
                showCursor(true) -- sets the cursor visible 
                if getTeamName(getPlayerTeam(lp)) == "Criminal" then 
                outputChatBox ("You already have this job..",0,255,0, true) 
        guiSetVisible(jobwindow,false) 
        showCursor(false) 
        end 
    end 
end) 
  
addEvent("HaveCriminalJob", true) 
function createHouses () 
    x, y, z = unpackRobberHouses () 
     robhouseMarker = createMarker ( x, y, z, "cylinder", 3, 255, 51, 102, 85, localPlayer ) 
      robhouseBlip = createBlipAttachedTo ( robhouseMarker, 32, localPlayer ) 
end 
addEventHandler ( "HaveCriminalJob", root, createHouses ) 
  
addEventHandler ( "onClientMarkerHit", root, 
    function ( hitElement ) 
        if ( source == robhouseMarker and not isPedInVehicle ( localPlayer ) and hitElement == localPlayer ) then 
            triggerServerEvent ( "givePlayerPay", localPlayer ) 
         destroyElement ( robhouseMarker ) 
           destroyElement ( robhouseBlip ) 
            triggerEvent ( "createHouseEvent", localPlayer ) 
        end 
    end 
) 
  
addEventHandler ( "onClientPedDamage", resourceRoot, 
    function () 
        cancelEvent () 
    end  
    ) 

Link to comment

Your code has some things that don't make much sense.

Like this:

addEventHandler("onResourceStart",jobmarker,function(p) if p == lp and not 
isPedInVehicle(lp) then guiSetVisible(jobmarker,true) showCursor(true) end end) 

And you didn't told where's the error, this make it more difficult to help you.

Please, type /debugscript 3 whenever there is any error with a script.

Link to comment
  • Moderators

THIS TOPIC HAS BEEN STARTED HERE: https://forum.multitheftauto.com/viewtopic.php?f ... 4&p=666569

Server:

addEvent ( "HaveCriminalJob", true) 
function  HaveCriminalJob() 
    triggerClientEvent(source, "HaveCriminalJob", source) --removed theX, theY + source as source 
    setPlayerTeam(source, getTeamFromName("Criminal")) 
end 
addEventHandler("HaveCriminalJob", root, HaveCriminalJob) 
  
addEvent ( "givePlayerPay", true ) 
function givePlayerRobPay () 
    local money = math.random ( 150, 2500 ) 
    givePlayerMoney ( source, money ) 
    outputChatBox ( "You successfully robbed the house and made $" ..money, source ) 
    fadeCamera ( source, false, 1, 0, 0, 0 ) 
    setTimer ( fadeCamera, 2500, 1, source, true, 1 ) 
end 
addEventHandler ( "givePlayerPay", root, givePlayerRobPay ) 

Client:

local robberHouses = 
{ 
    { 1887, -1113, 25 }, 
    { 2092, -1160, 25 }, 
    { 1896, -1165, 22 }, 
    { 2068, -1720, 13 }, 
    { 1970, -1671, 17 }, 
    { 1895, -1071, 23 }, 
    { 1940, -1066, 23 }, 
    { 1955, -1074, 23 }, 
    { 1960, -1069, 23 }, 
    { 1956, -1115, 26 }, 
    { 1945, -1115, 26 }, 
    { 1924, -1115, 26 }, 
    { 1900, -1114, 26 }, 
    { 2596, -1237, 47 }, 
    { 2595, -1199, 58 }, 
    { 2516, -1028, 69 }, 
    { 2630, -1072, 68 }, 
    { 2794, -1246, 45 }, 
    { 2809, -1176, 25 }, 
    { 2586, -953, 80 } 
} 
  
function getRandomHousePos() 
    return unpack( robberHouses[ math.random( #robberHouses ) ] ) 
end 
  
local jobmarker = createMarker( 2054.4609375, -1759.5224609375, 13.549641609192, "cylinder", 1.5, 255, 153, 0, 150 ) 
local jobBlip = createBlip( 2054.4609375, -1759.5224609375, 13.549641609192, 52 ) 
  
-------- GUI -------- 
jobwindow = guiCreateWindow(0.3, 0.3, 0.4, 0.4, "Criminal", true) 
memo = guiCreateMemo(0, 0.05, 0.8, 0.6, "This is house robbing job press Accept and then a red house will appear on your minimap go to the red house blip and rob the house!", true, jobwindow) 
takebutton = guiCreateButton(0.25, 0.9, 0.2, 0.18, "Accept", true, jobwindow) 
cancbutton = guiCreateButton(0.55, 0.9, 0.2, 0.18, "Cancel", true, jobwindow) 
guiMemoSetReadOnly(memo, true) 
guiWindowSetMovable(jobwindow, false) 
guiWindowSetSizable(jobwindow, false) 
guiSetVisible(jobwindow, false) 
--------------------- 
  
addEventHandler("onClientGUIClick", jobwindow, function(b) 
    if b == "left" then 
        if source == takebutton then 
            if getTeamName(getPlayerTeam(localPlayer)) ~= "Criminal" then 
                triggerServerEvent("HaveCriminalJob", localPlayer) 
                outputChatBox ("You are now employed as a Criminal", 255, 255, 0, true) 
                guiSetVisible(jobwindow, false) 
                showCursor(false) 
            end 
        elseif source == cancbutton then 
            guiSetVisible(jobwindow,false) 
            showCursor(false) 
        end 
    end 
end) 
  
addEventHandler("onClientMarkerHit", jobmarker, function(p) 
    if p == localPlayer and not isPedInVehicle(localPlayer) then 
        guiSetVisible(jobwindow,true) 
        showCursor(true) -- sets the cursor visible 
        if getTeamName(getPlayerTeam(localPlayer)) == "Criminal" then 
            outputChatBox("You already have this job.",0,255,0, true) 
            guiSetVisible(jobwindow,false) 
            showCursor(false) 
        end 
    end 
end) 
  
addEvent("HaveCriminalJob", true) 
function createNewHouse() 
    local x, y, z = getRandomHousePos() 
    robhouseMarker = createMarker( x, y, z, "cylinder", 3, 255, 51, 102, 85) 
    robhouseBlip = createBlipAttachedTo( robhouseMarker, 32) 
end 
addEventHandler ( "HaveCriminalJob", localPlayer, createNewHouse ) 
  
addEventHandler ( "onClientMarkerHit", root, function ( hitElement ) 
    if source == robhouseMarker and not isPedInVehicle ( localPlayer ) and hitElement == localPlayer then 
        triggerServerEvent ( "givePlayerPay", localPlayer ) 
        destroyElement ( robhouseMarker ) 
        destroyElement ( robhouseBlip ) 
        createNewHouse() --Creating a new house 
    end 
end) 
  
addEventHandler ( "onClientPedDamage", root, function () 
    cancelEvent () 
end) 

Link to comment
  • Moderators
there is no debugscript 3 or errors.

Ofc there is no error because you did that to create a new house:

triggerEvent ( "createHouseEvent", localPlayer ) 

But the event wasn't created and wasn't "linked" with an handler function either.

It would work if you added this:

addEvent("createHouseEvent", true) 
addEventHandler ( "createHouseEvent", localPlayer, createHouses  ) 

But I removed a lot of bullshits in your code (gui relative positioning, localPlayer instead of lp, theX and theY on server side, duplicated word in an output etc)

Link to comment
  • Moderators
worked, thx so much

No problem. Just try to think what your code will have to do to make it work:

1 - create job marker

2 - show job gui when marker is hitted by a player

3 - go on serverside to set the team when job when accepted then go back to clientside

4 - create a new random house

5 - when hitted, destroy the marker and ask the server to give him cash

6 - go back on step 4 <------ here was the problem

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