wesleywillems17 Posted May 30, 2016 Share Posted May 30, 2016 Hello, I'm creating a Car Jacking script for my server. But there is something wrong with line 2 I'm not a pro scripter i'm trying to learn it. Server.lua function JobDone ( hitElement, matchingDimension ) local elementType = getElementType( hitElement ) if elemenyType == "player" then if isElement( EndDesMarker ) then destroyElement( EndDesMarker ) end if isElement( EndDesBlip ) then destroyElement( EndDesBlip ) end if isElement( CarJacker ) then destroyElement( CarJacker ) end if isElement( CarJackerBlip ) then destroyElement( CarJackerBlip ) end money = math.random ( 2000, 5000 ) givePlayerMoney ( source, money ) outputChatBox ( "Got job! You received $" ..money, source ) end end addEventHandler( "onMarkerHit", EndDesMarker, JobDone ) Can somebody tell me what's wrong with it? Link to comment
ViRuZGamiing Posted May 30, 2016 Share Posted May 30, 2016 elemenyType on line 3 should be elementType, typo Link to comment
Captain Cody Posted May 30, 2016 Share Posted May 30, 2016 Typo at line 3 -- Other guy posted while I was typing -- function JobDone ( hitElement, matchingDimension ) local elementType = getElementType( hitElement ) if elementType == "player" then if isElement( EndDesMarker ) then destroyElement( EndDesMarker ) end if isElement( EndDesBlip ) then destroyElement( EndDesBlip ) end if isElement( CarJacker ) then destroyElement( CarJacker ) end if isElement( CarJackerBlip ) then destroyElement( CarJackerBlip ) end money = math.random ( 2000, 5000 ) givePlayerMoney ( source, money ) outputChatBox ( "Got job! You received $" ..money, source ) end end addEventHandler( "onMarkerHit", EndDesMarker, JobDone ) Link to comment
wesleywillems17 Posted May 30, 2016 Author Share Posted May 30, 2016 Thx! But now i get this error in the dubug: Warning: [gameplay]\(SARS)CarJacker\script\server.lua:47 Bad argument @ 'getElementType' [Expected element at argument 1] — Line preview: local elementType = getElementType( hitElement ) Link to comment
Captain Cody Posted May 30, 2016 Share Posted May 30, 2016 function JobDone ( hitElement, matchingDimension ) if hitElement then local elementType = getElementType( hitElement ) if elementType == "player" then if isElement( EndDesMarker ) then destroyElement( EndDesMarker ) end if isElement( EndDesBlip ) then destroyElement( EndDesBlip ) end if isElement( CarJacker ) then destroyElement( CarJacker ) end if isElement( CarJackerBlip ) then destroyElement( CarJackerBlip ) end money = math.random ( 2000, 5000 ) givePlayerMoney ( hitElement , money ) outputChatBox ( "Got job! You received $" ..money, hitElement ) end end addEventHandler( "onMarkerHit", EndDesMarker, JobDone ) Link to comment
ViRuZGamiing Posted May 30, 2016 Share Posted May 30, 2016 Just so he knows what he did, the source from onMarkerHit isn't the player but the marker itself Link to comment
wesleywillems17 Posted May 30, 2016 Author Share Posted May 30, 2016 Still gives me the same error in the debug Link to comment
wesleywillems17 Posted May 30, 2016 Author Share Posted May 30, 2016 @ViRuZGamiing Thx i always forget that Link to comment
ViRuZGamiing Posted May 30, 2016 Share Posted May 30, 2016 Can you show the code you now have Link to comment
wesleywillems17 Posted May 30, 2016 Author Share Posted May 30, 2016 Sure! function JobDone ( hitElement, matchingDimension ) if hitElement then local elementType = getElementType( hitElement ) if elementType == "player" then if isElement( EndDesMarker ) then destroyElement( EndDesMarker ) end if isElement( EndDesBlip ) then destroyElement( EndDesBlip ) end if isElement( CarJacker ) then destroyElement( CarJacker ) end if isElement( CarJackerBlip ) then destroyElement( CarJackerBlip ) end money = math.random ( 2000, 5000 ) givePlayerMoney ( hitElement, money ) outputChatBox ( "Got job! You received $" ..money, hitElement ) end end end addEventHandler( "onMarkerHit", EndDesMarker, JobDone ) Link to comment
Captain Cody Posted May 30, 2016 Share Posted May 30, 2016 That's the same code I just posted, we need the whole code so we can debug it. Link to comment
ViRuZGamiing Posted May 30, 2016 Share Posted May 30, 2016 Where is EndDesMarker declared Link to comment
wesleywillems17 Posted May 30, 2016 Author Share Posted May 30, 2016 Oow i thought you mean that part of the code local EndDesMarker = createMarker ( 2411.81, -1300.46, 23.62, "cylinder", 1, 255, 255, 0, 170 ) EndDesBlip = createBlipAttachedTo ( EndDesMarker, 53 ) setElementVisibleTo ( EndDesMarker, root, false ) setElementVisibleTo ( EndDesBlip, root, false ) local CarParks = { { 2415.27, -1238.13, 23.45 }; { 2433.49, -1224.88, 24.74 }; } local CarTypes = { { 518 }; { 457 }; } function unpackCarParks () return unpack ( CarParks [ math.random ( #CarParks ) ] ) end function unpackCarTypes () return unpack ( CarTypes [ math.random ( #CarTypes ) ] ) end function CreateCar () x, y, z = unpackCarParks () Veh = unpackCarTypes () CarJacker = createVehicle ( Veh, x, y, z, 0, 0, 9 ) CarJackerBlip = createBlipAttachedTo ( CarJacker, 55 ) end addEventHandler ( "onResourceStart", root, CreateCar ) function enterVehicle () setElementVisibleTo ( EndDesMarker, root, true ) setElementVisibleTo ( EndDesBlip, root, true ) end addEventHandler ( "onVehicleEnter", root, enterVehicle ) function DestroyStuff () setElementVisibleTo ( EndDesMarker, root, false ) setElementVisibleTo ( EndDesBlip, root, false ) end addEventHandler ( "onVehicleExit", root, DestroyStuff ) function JobDone ( hitElement, matchingDimension ) if hitElement then local elementType = getElementType( hitElement ) if elementType == "player" then if isElement( EndDesMarker ) then destroyElement( EndDesMarker ) end if isElement( EndDesBlip ) then destroyElement( EndDesBlip ) end if isElement( CarJacker ) then destroyElement( CarJacker ) end if isElement( CarJackerBlip ) then destroyElement( CarJackerBlip ) end money = math.random ( 2000, 5000 ) givePlayerMoney ( hitElement, money ) outputChatBox ( "Got job! You received $" ..money, hitElement ) end end end addEventHandler( "onMarkerHit", EndDesMarker, JobDone ) addEventHandler ( "onResourceStop", root, function () if isElement( CarJacker ) then destroyElement( CarJacker ) end if isElement( CarJackerBlip ) then destroyElement( CarJackerBlip ) end end ) Link to comment
ViRuZGamiing Posted May 31, 2016 Share Posted May 31, 2016 tested it, if isElement(hitElement) then if getElementType (hitElement) == "player" then Also a few suggestions / ideas perhaps, wouldn't it be better to just create a marker client side and destroy it when finished instead of having it all time invisible. Also you're doing 4 if's to check for element and destroy it, You can put those in an table and then loopthrough it with (for key, value in table do) Kind regards Link to comment
wesleywillems17 Posted May 31, 2016 Author Share Posted May 31, 2016 Thx and i'm still busy with it so there are some bugs maybe and i'm learning it so its hard for me to make a script like this. ( without any bugs). And that's a good idea.. i have really no idee why i was use the server-side to create the marker and destroy it). Normally i use the client-side (Really no idee why but that's how i learned it). Also sorry for my bad English 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