Xwad Posted February 2, 2015 Share Posted February 2, 2015 Hi i have a script that makes possible to mount a minigun to a vehicle but id does not work. server.lua local guns = 38 { [470] = { ["xPosOffset"] = 1.0, ["yPosOffset"] = 0, ["zPosOffset"] = 0 } } function attachMod(playerSource, commandName) local vehicle = getPlayerOccupiedVehicle(playerSource) local gun = false if (vehicle) then gun = guns[getVehicleID(vehicle)] or false if (gun) then attachElementToElement(createObject(2985, 0, 0, -100, 0, 0, 0), vehicle, gun.xPosOffset, gun.yPosOffset, gun.zPosOffset, 0, 0, 90) setElementData(vehicle, "toggleVehicleWeapon", true) end end end function detachMod(playerSource, commandName) local vehicle = getPlayerOccupiedVehicle(playerSource) if (vehicle) then for _, element in ipairs(getAttachedElements(vehicle)) do destroyElement(element) end setElementData(vehicle, "toggleVehicleWeapon", false) end end addCommandHandler("/attachmod", attachMod, false) addCommandHandler("/detachmod", detachMod, false) client.lua local root = getRootElement() local player = getLocalPlayer() local toggleVehicleWeapon = false local previousTick = getTickCount() local projectileType = 21 function updateVehicleWeapon(source, dataName) if (getElementType(source) == "vehicle" and dataName == "toggleVehicleWeapon") then toggleVehicleWeapon = (getElementData(source, dataName) and isPlayerInVehicle(player)) end end function callbackDataChange(dataName) updateVehicleWeapon(source, dataName) end Link to comment
xeon17 Posted February 2, 2015 Share Posted February 2, 2015 Your code tottaly no make sense Link to comment
Xwad Posted February 3, 2015 Author Share Posted February 3, 2015 why? what this script makes? Link to comment
xeon17 Posted February 3, 2015 Share Posted February 3, 2015 addCommandHandler("/attachmod", attachMod, false) addCommandHandler("/detachmod", detachMod, false) should be addCommandHandler("attachmod", attachMod, false) addCommandHandler("detachmod", detachMod, false) And there isn't any existing function with the name ToggleVehicleWeapon. Link to comment
Xwad Posted February 13, 2015 Author Share Posted February 13, 2015 not work pls help whitch fu ctions nwed I use? Link to comment
LaCosTa Posted February 13, 2015 Share Posted February 13, 2015 try this server DON'T FORGET IT WORKS ONLY WHEN YOU're ON PATRIOT CAR guns = { ["xPosOffset"] = 1.0, ["yPosOffset"] = 0, ["zPosOffset"] = 0, } function attachMod(playerSource, commandName) if isElement(playerSource) and getElementType(playerSource)=="player" then local vehicle = getPedOccupiedVehicle(playerSource) if (vehicle) then vehMod = getVehicleModel(vehicle) if (vehMod == 470) then attachElementToElement(createObject(2985, 0, 0, -100, 0, 0, 0), vehicle, guns.xPosOffset, guns.yPosOffset, guns.zPosOffset, 0, 0, 90) setElementData(vehicle, "toggleVehicleWeapon", true) end end end end function detachMod(playerSource, commandName) local vehicle = getPedOccupiedVehicle(playerSource) if (vehicle) then for _, element in ipairs(getAttachedElements(vehicle)) do destroyElement(element) end setElementData(vehicle, "toggleVehicleWeapon", false) end end addCommandHandler("attachmod", attachMod, false) addCommandHandler("detachmod", detachMod, false) Link to comment
Xwad Posted February 13, 2015 Author Share Posted February 13, 2015 Hi the the minigun is mounted when i write the command but i cant shoot. i thing i must write a weapon id no? i mean here: guns = { 31 } Link to comment
xeon17 Posted February 13, 2015 Share Posted February 13, 2015 Your code only attach the minigun to the vehicle , post the part of the script where you make the minigun fire. Link to comment
Xwad Posted February 13, 2015 Author Share Posted February 13, 2015 i posted the full script Please can you give me the functions what i need to use to make the minigun fireing i try to make it. Link to comment
xeon17 Posted February 13, 2015 Share Posted February 13, 2015 I'm not sure , createWeapon fireWeapon setWeaponState setWeaponAmmo Link to comment
Xwad Posted February 13, 2015 Author Share Posted February 13, 2015 teher is no example for setweaponstate!!pls help! Link to comment
BlueTheFurry Posted February 17, 2015 Share Posted February 17, 2015 setWeaponState(theWeapon, "firing") Link to comment
Deepu Posted February 18, 2015 Share Posted February 18, 2015 Look I'll show you an example code of how this works.. function attaching () if not isElement(mg) then mg = createWeapon(write the minigun things and all) veh = getPedOccupiedVehicle(localPlayer) attachElement(veh, position on the veh where u want to attach) else destroyElement(mg) end end addCommandHandler("attach", attaching) function wepFire () if isElement(mg) then fireWeapon(mg, or something like that) end end addCommandHandler("fire", wepFire) Link to comment
Castillo Posted February 18, 2015 Share Posted February 18, 2015 It's attachElements, not attachElement. Link to comment
Deepu Posted February 18, 2015 Share Posted February 18, 2015 alright @ castillo Sure, try it and if there is any bug or problem, feel free to tell it here Link to comment
Xwad Posted February 18, 2015 Author Share Posted February 18, 2015 ok thanks i go test it!! Link to comment
Xwad Posted February 18, 2015 Author Share Posted February 18, 2015 I can't make it you will laught that is what i made xdd function MountMinigun() local vehicle = getElementPosition(getLocalPlayer()) local weapon = createWeapon("minigun", x, y, z + 1) setWeaponClipAmmo(weapon, 5000) setWeaponState(weapon, "firing") setWeaponProperty(weapon, "fire_rotation", 0, -30, 0) end addEventHandler("onClientResourceStart", resourceRoot, MountMinigun) local randPlayer = getRandomPlayer() -- Get a random player giveWeapon(randPlayer,35,100) -- Give them a rocket launcher with 100 rockets. setWeaponAmmo(randPlayer,35,50) -- Decide we're only going to give them 50 rockets. if not isElement(minigun) then minigun = createWeapon(38) veh = getPedOccupiedVehicle(localPlayer) attachElement(veh, 0, 0, 3) else destroyElement(minigun) end end addCommandHandler("attach", attaching) if isElement(minigun) then fireWeapon(minigun, or something like that) end end addCommandHandler("fire", wepFire) Link to comment
Deepu Posted February 19, 2015 Share Posted February 19, 2015 Noooo ! do not setWeaponState to firing, that will keep it firing infinite times, even if you are innocent lol.. just use my code, it works perfect, create weapon, fireWeapon(attach to a command) then it should work remove the setWeaponState("firing") Link to comment
Xwad Posted February 19, 2015 Author Share Posted February 19, 2015 Yeah I know that the "firing" will always shoot but I didnt know the other command for no shooting . But thanks. So I dont need to ise the setweaponammo and the setweapon lstage function? Link to comment
Dealman Posted February 19, 2015 Share Posted February 19, 2015 Xwad, you're trying to use server functions in a client-side script. This will not work. Also, you're getting the element position of the player, not the vehicle. Also, you're only storing the X co-ordinate, not the Y and Z co-ordinate. You need to make it something like this; local vX, vY, vZ = getElementPosition(getPedOccupiedVehicle(localPlayer)) This gets the position of the vehicle the local player is using. setWeaponProperty, getRandomPlayer, giveWeapon and setWeaponAmmo are server-side functions. After this I have no idea what you're trying to do, I can't tell if you messed up your paste, but you haven't made any functions - only if statements. There are several solutions to fire the weapon, you could have a check in a timer or a render event to check if the left mouse-button is being held down using getKeyState. Or you can use the function bindKey or the event onClientClick. Take some time and read the MTA Wiki thoroughly, it will be your best friend once you learn how to navigate it to find what you need. Link to comment
Deepu Posted February 19, 2015 Share Posted February 19, 2015 guys guys, he is not wanting a weapon, he is trying to make a mounted vehicle, example like a rhino or a hydra.. I hope you understood and for that he has to make a weapon, attach it to a vehicle and then use it.. and yeah he has to make it all both in server and in client side he has to trigger a lot of things if he needs to work with the position of the player or a ped... ike this x, y, z = getElementPosition(localPlayer) or something like that. and he has to render it if he is using it globally.. This should work for him. Link to comment
Dealman Posted February 19, 2015 Share Posted February 19, 2015 I know what he wants to do, I simply corrected his mistakes. I've been working on a similar resource from time to time, which lets one player enter as a gunner in a vehicle, where he can control the gun, look around and fire etc. I've been meaning to look into releasing it, but it needs more work still. Link to comment
Deepu Posted February 19, 2015 Share Posted February 19, 2015 Thats easy, I'll make it if you want just kidding, its your work so u release it Link to comment
Deepu Posted February 19, 2015 Share Posted February 19, 2015 function posRender () x, y, z = getElementPosition(localPlayer) vx, vy, vz = getElementPosition(veh) end addEventHandler("onClientRender", root, posRender) local veh = createVehicle(441, x+3, y, z+1) local mini = createWeapon("minigun", vx, vy, vz+2) function attaching () if not isElement(mini) then mini = createWeapon("minigun", vx, vy, vz + 2) veh = getPedOccupiedVehicle(localPlayer) else destroyElement(mini) end end addCommandHandler("attach", attaching) -- do /attach to make minigun or destroy it... function wepFire() if isElement(mini) then fireWeapon(mini) end end addCommandHandler("fire", wepFire) 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