Price. Posted February 26, 2014 Share Posted February 26, 2014 I made a script so whenever I stand on the marker the gui shows up and when I press accept gets me to Criminal job then the job starts, everything is working except this weird error [2014-02-26 23:30:13] ERROR: Client (Price) triggered serverside event HaveCriminalJob, but event is not added serverside here's part of the client side addEventHandler("onClientGUIClick",jobwindow, function(b) if b == "left" then if source == takebutton then -- checks if I press on the accept or not if getTeamName(getPlayerTeam(lp)) ~= "Criminal" then -- checks if I'm in the carjacker team triggerServerEvent ( "HaveCriminalJob", lp) outputChatBox ("You are now now employed as a Criminal",255,255,0, true) -- outputs a message guiSetVisible(jobwindow,false) -- closes the gui showCursor(false) -- removes the cursor end elseif source == cancbutton then -- checks if I press on the cancel button guiSetVisible(jobwindow,false) -- and if I do, the gui will close. showCursor(false) -- removes the cursor end end end) Part of the server side function HaveCriminalJob() triggerClientEvent(source,"HaveCriminalJob",root,TheX,TheY) -- triggers the client event setPlayerTeam(source,getTeamFromName("Criminal")) -- sets me in "Carjacker" team addEvent ( "HaveCriminalJob", true) addEventHandler("HaveCriminalJob", root, HaveCriminalJob) end Link to comment
DNL291 Posted February 26, 2014 Share Posted February 26, 2014 Server: function HaveCriminalJob() triggerClientEvent(source,"HaveCriminalJob",root,TheX,TheY) -- triggers the client event setPlayerTeam(source,getTeamFromName("Criminal")) -- sets me in "Carjacker" team end addEvent ( "HaveCriminalJob", true) addEventHandler("HaveCriminalJob", root, HaveCriminalJob) Link to comment
Price. Posted February 26, 2014 Author Share Posted February 26, 2014 oh, wow it worked thx man! Link to comment
Price. Posted February 26, 2014 Author Share Posted February 26, 2014 got another problem the whole job doesn't work Server function HaveCriminalJob() triggerClientEvent(source,"HaveCriminalJob",root,TheX,TheY) setPlayerTeam(source,getTeamFromName("Criminal")) end addEvent ( "HaveCriminalJob", true) addEventHandler("HaveCriminalJob", root, HaveCriminalJob) addEvent ( "givePlayerPay", true ) function givePlayerRobPay () 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 }; -- add whit { x,y, z}; { 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 jobmarker = createMarker( 2054.4609375, -1759.5224609375, 13.549641609192, "cylinder", 1.5, 255, 153, 0, 150 ) addEventHandler("onResourceStart",jobmarker,function(p) if p == lp and not isPedInVehicle(lp) then guiSetVisible(jobmarker,true) showCursor(true) end end) sx,sy = guiGetScreenSize() -- creates a variable lp = getLocalPlayer() -- creates a variable mr = math.random(1,2) -- creates a variable 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,"Description here",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) -- makes the gui unvisible guiMemoSetReadOnly(memo,true) -- makes so the memo text cannot be edited. guiWindowSetMovable (jobwindow,false ) -- makes to the window is not moveable guiWindowSetSizable (jobwindow,false ) -- makes so you cannot set the size. 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 ( "createHouseEvent", 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 ) no errors or debugscript Link to comment
Moderators Citizen Posted February 27, 2014 Moderators Share Posted February 27, 2014 Hi, On client side: First you can remove the lines 32 and 33 since it just can't work and you are already showing properly the gui somewhere else. Then I would suggest you to replace the name of the unpackRobberHouses function by getRandomHousePosition. It has nothing to do with the solution but it's probably more explicit on what the function is doing. (Note: that I'm using this new name in the code below.) Then replace the lines 80 to 86 to be like this: addEvent("HaveCriminalJob", true) function startCriminalJob() outputChatBox("The job has started, go on the marker ...") createRandomHouse() end addEventHandler("HaveCriminalJob", root, startCriminalJob) addEvent("createHouseEvent", true) function createRandomHouse () local x, y, z = getRandomHousePosition() robhouseMarker = createMarker ( x, y, z, "cylinder", 3, 255, 51, 102, 85 ) robhouseBlip = createBlipAttachedTo ( robhouseMarker, 32 ) outputChatBox("Created marker at: "..tostring(x)..", "..tostring(y)..", "..tostring(z)) end addEventHandler ( "createHouseEvent", root, createRandomHouse ) You weren't "catching" the HaveCriminalJob triggered from server-side after the player got the job so I created the startCriminalJob function instead of adding createRandomHouse as an handler of this event because you would probably want to do stuff only when he is starting the job (as example, I added an outputChatBox. Then, you didn't get that a function available on both sides can have 2 different syntaxes. You used the server syntax for createMarker and createBlipAttachedTo functions on the client-side. We don't need to specify the player for who it should be visible because everything that is created on the client-side is only visible for that client. Also, I added an extra outputChatBox for debugging purposes. You can save a lot of times by using such functions to print where the code is going and where it is stopping. On the server-side: Everything is fine. In the end, I would suggest you to learn about local variables. You should use the local variable as often as possible. For example on the server-side at line 9: There is no need for the money variable to be a global one (accessible outside the the function in this case). You just can use the local keyword because you only need it inside that function: local money = math.random ( 150, 2500 ) It will works just fine and the variable will be deleted at the end of the scope (the function in this case). Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now