jkub Posted January 17, 2009 Share Posted January 17, 2009 ok This has been urking me for a long time now. I know there are real simple ways or alternate ways to tell what certain elements should do here is wat I mean first = createMarker ( 0, 0, 0, "cylinder", 1, 0, 255, 0, 125, getRootElement() ) second = createMarker ( 0, 5, 0, "cylinder", 1, 0, 255, 0, 125, getRootElement() ) third = createMarker ( 0, 10, 0, "cylinder", 1, 0, 255, 0, 125, getRootElement() ) function park_Example ( ) if source == first local myCar = getPlayerOccupiedVehicle ( thePlayer ) setVehicleEngineState ( myCar, false ) end addEventHandler ( "onMarkerHit", getRootElement(), park_Example ) so u see i got 3 markers right... where it says if source == first i would rather want the "source" or what the function is triggered by to be all three of these markers. since I dont know how to do that here is wat i end up doing and it either dont work or is messy I end up just duplicating the function code and pasting it below but just changing the if source == part to another marker ive already tryed doing this if source == first or second or third or ive tryed defining all three of them as one before by doing somthing like this allMarkers = ( first, second, third ) I have no idea lol my methods that i came up with dont work lol plz help? Link to comment
[DKR]silverfang Posted January 17, 2009 Share Posted January 17, 2009 Well firstly, if this code is ripped straight from your resource then it wont load as you have missed out an 'end' for the if statement secondly use if source == first or source == second or source == third Hope this helps Link to comment
Morelli Posted January 17, 2009 Share Posted January 17, 2009 You're also forgetting to place a "then" at the end of line 6. Link to comment
Gamesnert Posted January 17, 2009 Share Posted January 17, 2009 I guess this is just an example piece of code. secondly use if source == first or source == second or source == third You also forgot the the then. if source == first or source == second or source == third then Link to comment
[DKR]silverfang Posted January 17, 2009 Share Posted January 17, 2009 Oh yeah missed that.... Link to comment
robhol Posted January 17, 2009 Share Posted January 17, 2009 thePlayer is not declared. Link to comment
DiSaMe Posted January 17, 2009 Share Posted January 17, 2009 And there's no "end" for "if" after setVehicleEngineState. Link to comment
Gamesnert Posted January 17, 2009 Share Posted January 17, 2009 And there's no "end" for "if" after setVehicleEngineState. Well firstly, if this code is ripped straight from your resource then it wont load as you have missed out an 'end' for the if statement Was already mentioned. Link to comment
jkub Posted January 18, 2009 Author Share Posted January 18, 2009 k thx for that.. but next i got another problem that is related to the same script... I made a marker and used the "onMarkerHit" eventHandler... but the function it is tied too is triggered when u hit the marker in a vehicle or on foot... I want it only to work when ur in a vehicle>>> how would I do that? Link to comment
[DKR]silverfang Posted January 18, 2009 Share Posted January 18, 2009 k thx for that.. but next i got another problem that is related to the same script...I made a marker and used the "onMarkerHit" eventHandler... but the function it is tied too is triggered when u hit the marker in a vehicle or on foot... I want it only to work when ur in a vehicle>>> how would I do that? Using your code I would do... first = createMarker ( 0, 0, 0, "cylinder", 1, 0, 255, 0, 125, getRootElement() ) second = createMarker ( 0, 5, 0, "cylinder", 1, 0, 255, 0, 125, getRootElement() ) third = createMarker ( 0, 10, 0, "cylinder", 1, 0, 255, 0, 125, getRootElement() ) function park_Example ( hitPlayer, matchingDimension ) if source == first or source == second or source == third then local myCar = getPlayerOccupiedVehicle ( hitPlayer ) if myCar then setVehicleEngineState ( myCar, false ) end end end addEventHandler ( "onMarkerHit", getRootElement(), park_Example ) Hope this helps, silverfang Link to comment
jkub Posted January 18, 2009 Author Share Posted January 18, 2009 now that we got that out of the way what about if instead activated by a vehicle but activated by a specific vehicle created within the script like exCar = createVehicle ( 420, 0, 0, 0, 0, 0, 0 ) how would i make it to where it is activated by only that car? Link to comment
arc_ Posted January 18, 2009 Share Posted January 18, 2009 Replace if myCar then by if myCar == exCar then Not so difficult isn't it Link to comment
jkub Posted January 18, 2009 Author Share Posted January 18, 2009 k thx!!! but I got a simple repair script that charges 1000 for a vehicle repair... I am trying to use 3 if statements 1 if he has enough money repair.. if not output a message.. I did that correctly 2 if source is the marker Ive did that correctly 3 if the cars health is already 1000 (mint) then I want to output a message and end the function there but instead it does not say anything and takes the money and repairs anyway???? is there any layout of if or should i use else if or what?? function repair ( thePlayer ) local car = getPlayerOccupiedVehicle ( thePlayer ) local wallet = getPlayerMoney ( thePlayer ) local hp = getElementHealth ( car ) if source == repairMarker then if ( wallet < 1000 ) then if hp == 1000 then outputChatBox ( "right" ) end outputChatBox ( "You cannot afford to fix your car", thePlayer, 255, 0, 0 ) else fixVehicle ( car ) takePlayerMoney ( thePlayer, 1000 ) end else return end end Link to comment
arc_ Posted January 18, 2009 Share Posted January 18, 2009 Look closely at your code. You will see that the "your car is at 1000hp" message ("right") is inside the "if wallet < 1000". Therefore, the message will only appear if your car is healthy and you have too little money to do a repair. So, you want to do it like this: if hp == 1000 then outputChatBox("Your car is already in good shape", player) elseif wallet < 1000 then outputChatBox("You don't have enough money", player) else -- repair car with fixVehicle and takePlayerMoney end A few extra remarks: - Don't forget the player argument for outputChatBox. Without it, *all* players on the server will see the message. - Take better care of your code formatting, specifically indentation. The way you have it now it's pretty messy and not very readable. Link to comment
jkub Posted January 19, 2009 Author Share Posted January 19, 2009 I am making a gui to go along with a script because outputting useful information to the chatbox all the time looks shitty so i got a basic gui window now and I can not make it visible... when i try it gives this in debug attempt to call global 'guiCreateWindow' (a nil value) function gui ( thePlayer ) myWindow = guiCreateWindow ( 90, 175, 244, 228, "Wanted List", false ) guiSetVisible ( myWindow, true ) end addCommandHandler ( "show", gui ) Link to comment
Ace_Gambit Posted January 20, 2009 Share Posted January 20, 2009 ... when i try it gives this in debugattempt to call global 'guiCreateWindow' (a nil value) This function is client side only. Maybe you tried to call it in a server script? 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