heavy air Posted February 10, 2008 Share Posted February 10, 2008 is it possible to mount guns on cars ala interstate69 but in a freeroam map i have looked throuh the scripts for interstate69 but cant figure out what i need to do is it just a case of using attachelement (but then how do i fire) or something more complicated ANY HELP s APPRECIATED Link to comment
Magus1724 Posted February 11, 2008 Share Posted February 11, 2008 I'd like to know too Also, what about attaching guns to an object and using them somehow, maybe like a turret. My main idea being the pirate ship, imagine being able to captain a pirate ship and have a crew shooting from the flanks Link to comment
heavy air Posted February 11, 2008 Author Share Posted February 11, 2008 thats a pretty sweet idea what about the turret from the rhino as the basis for movement i have been looking in the interstate69 scripts again and i think im getting somewhere ive started with get player occupied vehicle for the x y z then attach element to place the gun but im getting a bit lost im a very noob scripter and have just begun learning in the interstate69 scripts the vehicle spawn with weapon seems to be split between lots of different scripts and im struggling to piece it all together into one function i dont know if i can make it a function to add the weapon with command or if ill have to make it as a spawnpoint vehicle when u start interstate69 it gives u the option to pick weapons where as i just want a single weapon mounted on the vehicle (allways minigun) trying to make a bit of a madmax movie i was considering just increasing the world size in interstate69 so i can use the whole map but i think that will take quite some time so it might be a while will post updates if i make any progress Link to comment
Magus1724 Posted February 11, 2008 Share Posted February 11, 2008 Nice to see that someone else is also interested in this If I ever get more spare time I might look into it myself, unless some experienced scripter is interested in this idea I am also a veryyyyyyy n00bish scripter and I'm so busy I have barely any time to learn more, but if you do get anything going make sure to let us know Link to comment
Mr.Hankey Posted February 12, 2008 Share Posted February 12, 2008 hm... if you want to attach weapons like in the interstate69 mode you have to write two different parts one for creating and attaching the minigun or rocket or whatever you want to the vehicle and one for binding a key for firing the projectile(s). I just made a quick example to show you how it works and i hope you dont just copy'n paste it but also look at the comments and try to understand it! The resource should consist out of 3 files: First the rocket_server.lua: function mount_rocket (player) local vehicle = getPlayerOccupiedVehicle (player) --get the Vehicle element of the player who entered the command if (vehicle) then -- check if there's a vehicle the player is in local object = createObject ( 3790, 0, 0, 0) --create a rocket object (id:3790) at the vehicle position (could also be any other position attachElementToElement (object, vehicle, 0, 0, 1, 0, 0, -90) --attach the rocket object to the vehicle with an z offset of 1 unit and -90° rotation along the z axis triggerClientEvent ("bind_key", getRootElement (), object) -- trigger the client event and pass the object element variable else end end addCommandHandler ("mount_rocket", mount_rocket) --add a Command that calls the function mount_rocket Second the rocket_client.lua: addEvent ("bind_key", true) -- add an Event and set enable remote triggering for it so we can trigger this event with the server script function fire_rocket () local x, y, z = getElementPosition (getPlayerOccupiedVehicle (getLocalPlayer()))-- get the position of the vehicle the player sits in createProjectile ( getLocalPlayer(), 19, x, y, z + 4, 4.0 )-- create a rocket 4 units above the position of the vehicle end function bind_key_function () bindKey ("vehicle_fire", "down", fire_rocket) --bind the vehicle_fire control to the fire_rocket function local attachedElements = getAttachedElements ( getPlayerOccupiedVehicle (getLocalPlayer()) ) --get all elements that are attached to the car for ElementKey, ElementValue in ipairs ( attachedElements ) do--loop through all attached elements... setElementCollisionsEnabled (ElementValue, false) -- ...and disable their collision end end addEventHandler ("bind_key", getLocalPlayer(), bind_key_function) --add an EventHandler to the "bind_key" event and attach the bind_key_function function to it --*NOTE i think you have to set the root element to the local player because otherwise it would be triggered on all clients if someone enters the command but im not sure and at last the meta.xml <meta> <info author="eXo|Mr.Hankey" version="1.0" type="script"/> <script src="rocket_server.lua" /> <script src="rocket_client.lua" type="client" /> </meta> I tried to comment every single line to make it as understandable as possible and i hope i could help you with this Link to comment
heavy air Posted February 12, 2008 Author Share Posted February 12, 2008 WOW that is awesome and just what i wanted i really want to learn scripting so i can do what i want but its awful hard last time i was into programming i was on pascal and visual basic at college but that was about 12 years ago and im struggling to get back into it i have been through all the tutorials and such but they just dont seem to click ( i really really want an ion cannon) i will have a proper look this evening and see where i can get THANX LOADS i think this should be quite helpful ONCE AGAIN THANX A BUNCH EDIT : just had a little play with it and have mounted a rocket on car but still having problems firing ( not to big a problem as its just for the look ) still not totally sure what im doin but im going to try and expand a little ( multiple rockets ) your guide was very helpful though and i think im getting somewhere at last U R AN ANGEL THANX SO MUCH Link to comment
heavy air Posted February 12, 2008 Author Share Posted February 12, 2008 on another note i am trying to make a vehicle invisible i am basing my script on set player alpha level (function ElementAlpha) and the change vehicle script that i made with the help of FGWELDER and JUMBA this is where i am function vehicleAlpha ( source, command, level ) local vehicle = getPlayerOccupiedVehicle ( source ) local alphalevel = getElementAlpha ( source ) setElementAlpha ( localvehicle, tonumber ( level )) end end and i get this error 17:36:04] SCRIPT ERROR: C:/MTA Server/mods/deathmatch/resourcecache/hafr/heavyair.lua:48: '' expected near 'end' [17:36:04] INFO: Loading script failed: C:/MTA Server/mods/deathmatch/resourcecache/hafr/heavyair.lua:48: '' expected near 'end' not sure where im goin wrong or if this is even possible but i find i learn best by doing i think i just need a push in the right direction Link to comment
szlend Posted February 12, 2008 Share Posted February 12, 2008 Why the hell do you have 2x "end" in the function? And the variable "localvehicle" in "setElementAlpha ( localvehicle, tonumber ( level ))" isn't even defined.... Are you sure you've coded before? I seriously doubt you would forget basic stuff as syntax ... Link to comment
heavy air Posted February 12, 2008 Author Share Posted February 12, 2008 ive never used lua before and i really dont remember much of my basic / pascal days thats why i want to get to know this stuff sorry if i seem a bit dumb sometimes but it has been a very LONG time but i keep going through the tutorials and such trying to remind myself Thanx for posting Link to comment
Magus1724 Posted February 12, 2008 Share Posted February 12, 2008 Cool, I'm gonna have to try that sample script out when I have the time, but I have a question for you eXo|Mr.Hankey: Do you know if it's possible to attach a gun to a particular object, at a specific spot, instead of a vehicle? (like a pirate ship ). Either way I'll be looking forward to free-roaming with gun-equipped vehicles And heavy air, just keep it up man, like anything else it takes practice to get better at something. I'm not great either but if I have more time I will try and learn as much LUA as possible, because i'm incredibly interested in what I can do in MTA Link to comment
Mr.Hankey Posted February 12, 2008 Share Posted February 12, 2008 sure it is possible Magus just use attachElementToElement ( gun_element, pirateship_element, xoffset, yoffset, zoffset ) but if you attach the gun to the ship you have to think how a single player should fire the projectiles... maybe stick him next to the gun or just set his camera to the gun =) many many ways to realise this i think Link to comment
Magus1724 Posted February 12, 2008 Share Posted February 12, 2008 Awesome The best way to do it would probably be to make a sort of 'seat' (player can maybe stand behind it with feet locked) where the player can sit or w/e and once in that state the binds change for him to shoot (and possibly zoom in) while he is there. The amount of stuff that can be done is great Link to comment
heavy air Posted February 13, 2008 Author Share Posted February 13, 2008 Just got this workin function setvehiclealpha (player, command, level ) local veh = getPlayerOccupiedVehicle ( player ) setElementAlpha ( veh, tonumber ( level ) ) end awful simple i know but im getting somewhere at last anybody is welcome to use this and alter any way they want slight problem though makes all cars of its type invisible as well thanx for the help all and hopefully ill be onto gamemodes in a month or two still lovin the pirate ship idea but i think ive got a fair way to go before i can make that i think im going to try for a command that sets player and vehicle alpha together next 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