Noah_Antilles Posted May 14, 2017 Share Posted May 14, 2017 (edited) Hello there, I am a total noob in scripting, but I thought I'd give it a try for the sake of learning new things. What I am trying to accomplish with this script is disabling the "standard" rustler guns (this works thanks to an example script of the wiki.) and make it fire "custom" projectiles when the player presses the left mouse button. For now I just want to check if the script recognizes a player inside a rustler pressing left mouse button (hence the outputChatBox) However, when I am inside a rustler and use the left mouse button to fire nothing pops up in the chatbox (luckily, as intended, the rustler doesn't fire its guns) What am I doing wrong? I'm sure I made some kind of noob mistake but hey, I am still learning function disableFireForRustler ( theVehicle, seat ) if ( getElementModel ( theVehicle ) == 476 ) then toggleControl ( "vehicle_secondary_fire", false ) else toggleControl ( "vehicle_secondary_fire", true ) end addEventHandler ( "onClientPlayerVehicleEnter", getLocalPlayer(), disableFireForRustler ) function addTracer (mouse1, press) if (press) then outputChatBox ("guns fired") end addEventHandler("onClientKey", root, addTracer) Edited May 14, 2017 by Noah_Antilles Link to comment
Reval Posted May 14, 2017 Share Posted May 14, 2017 (edited) u forget end at line 7 and line14 function disableFireForRustler ( theVehicle, seat ) if ( getElementModel ( theVehicle ) == 476 ) then toggleControl ( "vehicle_secondary_fire", false ) else toggleControl ( "vehicle_secondary_fire", true ) end end addEventHandler ( "onClientPlayerVehicleEnter", getLocalPlayer(), disableFireForRustler ) function addTracer (mouse1, press) if (press) then outputChatBox ("guns fired") end end addEventHandler("onClientKey", root, addTracer) try now Edited May 14, 2017 by Reval 1 Link to comment
SheriFF Posted May 14, 2017 Share Posted May 14, 2017 Replace addTracer with this : function addTracer( BUTTON, STATE ) if( BUTTON == "left" and STATE == "up" ) then outputChatBox( "guns fired" ) end end addEventHandler( "onClientClick", getRootElement(), addTracer ) 1 Link to comment
Noah_Antilles Posted May 14, 2017 Author Share Posted May 14, 2017 (edited) Thanks for your replies. I tried both of them @Reval This doesn't seem to work, the Rustler doesn't fire, but I don't get an output in the chat. @*BeaT* I only get an output in the chat when I am left-clicking in menu's (when using the F1 menu for example) When seated in a rustler nothing happens The two scripts need to work together, but it seems they don't. Edited May 14, 2017 by Noah_Antilles Link to comment
coNolel Posted May 14, 2017 Share Posted May 14, 2017 try this function disableFireForRustler ( theVehicle, seat ) if ( getElementModel ( theVehicle ) == 476 ) then toggleControl ( "vehicle_secondary_fire", false ) else toggleControl ( "vehicle_secondary_fire", true ) end end addEventHandler ( "onClientPlayerVehicleEnter", getLocalPlayer(), disableFireForRustler ) function MouseKey(button, press) if (button == "mouse1" and press) then outputChatBox("Clicked the left mouse !") end end addEventHandler("onClientKey", root, MouseKey) Link to comment
Noah_Antilles Posted May 14, 2017 Author Share Posted May 14, 2017 (edited) @coNolel The script outputs the message whenever I click left mouse button. It exclusively needs to output the text when I am in a Rustler. As far as I can see the second part of the script (line 10-15) ignores the first part of the script (line 1-8) Edited May 14, 2017 by Noah_Antilles Link to comment
coNolel Posted May 14, 2017 Share Posted May 14, 2017 1 minute ago, Noah_Antilles said: @coNolel The script outputs the message whenever I click left mouse button. It exclusively needs to output the text when I am in a Rustler. As far as I can see the second part of the script (line 10-15) ignores the first part of the script (line 1-8) so , whenever you enter the rustler, you add the Event of the mouse button , same thing when you exit, you remove it . Link to comment
Noah_Antilles Posted May 14, 2017 Author Share Posted May 14, 2017 I am afraid I don't understand, I have little experience in scripting This is the result I am striving for: When I'm in a rustler and left click the text should pop up When I'm in another vehicle or on foot and left click it shouldn't pop up. Your script helped me a lot in the right direction, but whenever I left click the text pops up regardless of whether I'm in a rustler or not. Link to comment
coNolel Posted May 14, 2017 Share Posted May 14, 2017 3 hours ago, Noah_Antilles said: I am afraid I don't understand, I have little experience in scripting This is the result I am striving for: When I'm in a rustler and left click the text should pop up When I'm in another vehicle or on foot and left click it shouldn't pop up. Your script helped me a lot in the right direction, but whenever I left click the text pops up regardless of whether I'm in a rustler or not. hey again , sorry about the " late " answer , but not everything you wish comes real and quick , you should make codes and get experience trough out writing codes and the important thing in to know what are you writing, not taking from scratches , as i used to do tbh , so there is nothing to be afraid from , you are now making your experience better and better , so let's don't talk too much , as i said above , you can write a function checking from it the vehicle that you entered , and if it's the Hustler as you want , you add the Event Handler , else you remove the event handler , that's pretty much it ! 1 Link to comment
Noah_Antilles Posted May 14, 2017 Author Share Posted May 14, 2017 (edited) I indeed have to learn it myself. I will try to fix the remainder of the problem myself thanks for helping me @coNolel @*BeaT* and @Reval You've given me lots of motivation to move on and learn more, thanks! Edited May 14, 2017 by Noah_Antilles 1 Link to comment
coNolel Posted May 14, 2017 Share Posted May 14, 2017 3 minutes ago, Noah_Antilles said: I indeed have to learn it myself. I will try to fix the remainder of the problem myself thanks for helping me @coNolel @*BeaT* and @Reval You've given me lots of motivation to move on and learn more, thanks! No problem dude, catch you in the next one ! Link to comment
Noah_Antilles Posted May 15, 2017 Author Share Posted May 15, 2017 Alright, I've tried a load of things, and I am beginning to get a grasp of scripting (atleast I think so ) but I just cannot seem to get the scripts to work with eachother. This is what I have right now: The disable rustler firing script is in another script - client This scipt - client function checkIfRustler ( theVehicle, seat ) local id = getElementModel ( theVehicle ) if id == 476 then end end addEventHandler ("onClientPlayerVehicleEnter", getLocalPlayer(), checkIfRustler) function MouseKey(button, press) if (button == "mouse1" and press) then outputChatBox("Clicked the left mouse !") end end addEventHandler("onClientKey", checkIfRustler, MouseKey) Could you give me some more tips as to what I am doing wrong? because I feel like I am running against a wall right now. Link to comment
coNolel Posted May 15, 2017 Share Posted May 15, 2017 Okey , so function MouseKey(button, press) if (button == "mouse1" and press) then outputChatBox("Clicked the left mouse !") end end function checkIfRustler ( theVehicle, seat ) local id = getElementModel ( theVehicle ) if id == 476 then -- then what ? you shout add the Event Handler addEventHandler("onClientKey", checkIfRustler, MouseKey) else outputChatBox("you can't use it ! ( only in Rustler vehicle ).") end end addEventHandler ("onClientPlayerVehicleEnter", getLocalPlayer(), checkIfRustler) Try this 1 Link to comment
Noah_Antilles Posted May 15, 2017 Author Share Posted May 15, 2017 (edited) Thanks for your reply again @coNolel The script doesn't seem to work. I get no chat message. I have no idea what's wrong, your script seems perfect to me edit: when I enter another vehicle that is not a rustler I get the chat message "you can't use it ! (only in Rustler vehicle)" even though I did not press left mouse button Edited May 15, 2017 by Noah_Antilles Link to comment
DNL291 Posted May 15, 2017 Share Posted May 15, 2017 (edited) Try this: addEventHandler( "onClientKey", root, function ( button ) if button == "mouse1" and getPedOccupiedVehicle(localPlayer) then if getElementModel( getPedOccupiedVehicle(localPlayer) ) == 476 and isControlEnabled( "vehicle_secondary_fire" ) then toggleControl ( "vehicle_secondary_fire", false ) else if not isControlEnabled( "vehicle_secondary_fire" ) then toggleControl ( "vehicle_secondary_fire", true ) end end end end ) If it doesn't work, try using cancelEvent. Edited May 15, 2017 by DNL291 2 Link to comment
Noah_Antilles Posted May 15, 2017 Author Share Posted May 15, 2017 @DNL291 Thanks for the reply, I tested the script and it almost works. I added an outputChatBox function to see whether or not it worked here's what I found: When I press left mouse button in the rustler it posts both outputchatbox texts in the chat. Here's the small addition I added addEventHandler( "onClientKey", root, function ( button ) if button == "mouse1" and getPedOccupiedVehicle(localPlayer) then if getElementModel( getPedOccupiedVehicle(localPlayer) ) == 476 and isControlEnabled( "vehicle_secondary_fire" ) then toggleControl ( "vehicle_secondary_fire", false ) outputChatBox ("Guns activated") else if not isControlEnabled( "vehicle_secondary_fire" ) then toggleControl ( "vehicle_secondary_fire", true ) outputChatBox ("No rustler guns") end end end end ) I added these outputChatBox functions because later on I want to replace them with createProjectile so I have "custom" guns firing from the rustler. 2 Link to comment
coNolel Posted May 15, 2017 Share Posted May 15, 2017 so everythings seems to work fine now ? Link to comment
DNL291 Posted May 15, 2017 Share Posted May 15, 2017 Try using the second parameter: pressOrRelease. So the updated code should look like this: addEventHandler( "onClientKey", root, function ( button, press ) if button == "mouse1" and press and getPedOccupiedVehicle(localPlayer) then if getElementModel( getPedOccupiedVehicle(localPlayer) ) == 476 and isControlEnabled( "vehicle_secondary_fire" ) then toggleControl ( "vehicle_secondary_fire", false ) outputChatBox ("Guns activated") else if not isControlEnabled( "vehicle_secondary_fire" ) then toggleControl ( "vehicle_secondary_fire", true ) outputChatBox ("No rustler guns") end end end end ) 1 Link to comment
Elmatus Posted May 16, 2017 Share Posted May 16, 2017 function shootProjectile() local vehicle = getPedOccupiedVehicle(localPlayer) -- Check if the player is in a vehicle if(vehicle)then --Check if its a rustler if getElementModel(vehicle) == 476 then --Get the current position of the vehicle and fire a rocket (No rotation is passed to createProjectile function because it automaticaly gets the vehicle rotation) local x, y, z = getElementPosition(vehicle) createProjectile(vehicle, 19, x, y, z) end end end bindKey("mouse1", "down", shootProjectile) I think I understand you. Give a try to this. 1 Link to comment
Noah_Antilles Posted May 16, 2017 Author Share Posted May 16, 2017 Tested both scripts, thanks again for your replies @DNL291 When I am in a rustler and press the left mouse it works perfectly. however, when I press it for the second time the guns fire and the chatbox launches the "No rustler guns message" @Elmatus Your script works perfectly, it spawns a rocket when I press left mouse and am inside of a rustler. However, the normal rustler guns still fired, so I added the disableFireForRustler script. It now works perfectly fine! For anyone interested in the script, here it is: function disableFireForRustler ( theVehicle, seat ) if ( getElementModel ( theVehicle ) == 476 ) then toggleControl ( "vehicle_secondary_fire", false ) else toggleControl ( "vehicle_secondary_fire", true ) end end addEventHandler ( "onClientPlayerVehicleEnter", getLocalPlayer(), disableFireForRustler ) function shootProjectile() local vehicle = getPedOccupiedVehicle(localPlayer) -- Check if the player is in a vehicle if(vehicle)then --Check if its a rustler if getElementModel(vehicle) == 476 then --Get the current position of the vehicle and fire a rocket (No rotation is passed to createProjectile function because it automaticaly gets the vehicle rotation) local x, y, z = getElementPosition(vehicle) createProjectile(vehicle, 19, x, y, z) end end end bindKey("mouse1", "down", shootProjectile) I want to thank all of you for helping out a beginner in scripting. I feel more confident knowing there is a big community that is willing to help me when I am struggling. Big thanks to everyone who helped me -Noah 1 Link to comment
Elmatus Posted May 16, 2017 Share Posted May 16, 2017 Yeah, you said you already had it so I didn't post it! I'm glad its working now. 1 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