CapY Posted July 13, 2011 Share Posted July 13, 2011 (edited) I have this code(Ace_Gambit is the original creator of it) for mounting weapons onto a vehicle's passenger side for shooting that. I want edit it. I wanna aim with that minigun(mouse aiming) Client: local root = getRootElement() local player = getLocalPlayer() local toggleVehicleWeapon = false local previousTick = getTickCount() local projectileType = 20 function updateVehicleWeapon(source, dataName) if (getElementType(source) == "vehicle" and dataName == "toggleVehicleWeapon") then toggleVehicleWeapon = (getElementData(source, dataName) and isPedInVehicle(player)) end end function callbackDataChange(dataName) updateVehicleWeapon(source, dataName) end function callbackVehicleEnter(thePlayer, seat) updateVehicleWeapon(source, "toggleVehicleWeapon") end function callbackRender() if (getControlState("vehicle_fire") and toggleVehicleWeapon) then if (getTickCount() > (previousTick + 150) and previousTick > 0) then fireProjectile() end end end function fireProjectile() local vehicle = getPedOccupiedVehicle(player) local gun = false local gX, gY, gZ = 0, 0, 0 local gRotX, gRotY, gRotZ = 0, 0, 0 local pX, pY, pZ = 0, 0, 0 local vX, vY, vZ = 0, 0, 0 local currentLoSOffset = 3.5 local zPosOffset = 1.1 local thrust = 2.0 previousTick = 0 if (vehicle) then if (#getAttachedElements(vehicle) > 0) then gun = getAttachedElements(vehicle)[1] if (gun) then gX, gY, gZ = getElementPosition(gun) gRotX, gRotY, gRotZ = getElementRotation(gun) pX = gX - math.sin(-math.rad(gRotZ + 90)) * currentLoSOffset pY = gY + math.cos(-math.rad(gRotZ + 90)) * currentLoSOffset pZ = gZ + zPosOffset vX = math.sin (math.rad((gRotZ + 90))) * thrust vY = math.cos(math.rad((gRotZ + 90))) * thrust vZ = 0 createExplosion(pX, pY, pZ, 5, true, -1.0, false) createProjectile(player, projectileType, pX, pY, pZ, 0, nil, 0, 0, 0, vX, vY, vZ) end end end previousTick = getTickCount() end function changeProjectileType(commandName, arg) projectileType = tonumber(arg) or 20 end addEventHandler("onClientElementDataChange", root, callbackDataChange, true) addEventHandler("onClientVehicleEnter", root, callbackVehicleEnter, true) addEventHandler("onClientRender", root, callbackRender, true) addCommandHandler("guntype", changeProjectileType) Server(little edited by me): local guns = { [411] = { ["xPosOffset"] = 0, ["yPosOffset"] = 1.0, ["zPosOffset"] = -0.5 } } function attachMod(playerSource, commandName) local vehicle = getPedOccupiedVehicle(playerSource) local gun = false if (vehicle) then gun = guns[getElementModel(vehicle)] or false if (gun) then attachElements(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 = getPedOccupiedVehicle(playerSource) if (vehicle) then for _, element in ipairs(getAttachedElements(vehicle)) do destroyElement(element) end setElementData(vehicle, "toggleVehicleWeapon", false) end end addCommandHandler("mountit", attachMod, false) addCommandHandler("unmountit", detachMod, false) Is these 2 functions i must include in client side ? moveObject: -- Find a player called 'someguy' someGuy = getPlayerFromNick ( "someguy" ) -- If a player called someguy was found then if ( someGuy ) then -- Get the player's position x, y, z = getElementPosition ( someGuy ) -- Create a bed (1700) object near to the player bed = createObject ( 1700, x + 5, y, z ) -- Move the bed towards the player over 3 seconds (3000 milliseconds) moveObject ( bed, 3000, x, y, z ) -- Tell the player in the chat box outputChatBox ( "Moving a bed towards you!", someGuy ) else -- Tell everyone that a player called 'someguy' could not be found outputChatBox ( "Player someguy doesn't exist" ) end setObjectRotation: function onResourceStart ( name, root ) -- predefined variables, needed for the math code below rotX = 0 rotY = 0 rotZ = 0 -- assign element named 'minigun' in map file to variable pirateship = getElementByID ( "minigun" ) end function chatboxShipRotateLeft ( playerSource, commandName ) -- On console command 'increaserotations' outputChatBox ( "Rotational values increased" ) -- rotations = rotations + 10 rotX = rotX + 10 rotY = rotY + 10 rotZ = rotZ + 10 -- Changed rotation is applied setObjectRotation ( minigun, rotX, rotY, rotZ ) end function chatboxMinigunRotateRight ( playerSource, commandName ) -- On console command 'decreaserotations' outputChatBox ( "Rotational values decreased" ) -- rotations = rotations - 10 rotX = rotX - 10 rotY = rotY - 10 rotZ = rotZ - 10 -- Changed rotation is applied setObjectRotation ( minigun, rotX, rotY, rotZ ) end -- Set up event and command handlers addEventHandler ( "onResourceStart", getRootElement(), onResourceStart ) addCommandHandler ( "increaserotations", chatboxShipRotateLeft ) addCommandHandler ( "decreaserotations", chatboxShipRotateRight) And my problem is that IDK how to add it to let it work ... Edited July 14, 2011 by Guest Link to comment
bandi94 Posted July 13, 2011 Share Posted July 13, 2011 hmm. i and one of my friends next project is this shooting whit minigun if this code is workin only add if getKeyState( "here put your buton whit you whant to aim" ) == true then if this code its not working and you can't fix it then when my code is ready i will help you Link to comment
CapY Posted July 13, 2011 Author Share Posted July 13, 2011 I tryied it, but i don't know, how to let it work . Link to comment
CapY Posted July 13, 2011 Author Share Posted July 13, 2011 I'm stuck on the line 4 function minigunAimFunction() -- if the right click has pressed, you'll be able to aim if getKeyState( "rclick" ) == true then Any solution ? Link to comment
CapY Posted July 13, 2011 Author Share Posted July 13, 2011 So here it is : local root = getRootElement() local player = getLocalPlayer() local toggleVehicleWeapon = false local previousTick = getTickCount() local projectileType = 20 function updateVehicleWeapon(source, dataName) if (getElementType(source) == "vehicle" and dataName == "toggleVehicleWeapon") then toggleVehicleWeapon = (getElementData(source, dataName) and isPedInVehicle(player)) end end function callbackDataChange(dataName) updateVehicleWeapon(source, dataName) end function callbackVehicleEnter(thePlayer, seat) updateVehicleWeapon(source, "toggleVehicleWeapon") end function callbackRender() if (getControlState("vehicle_fire") and toggleVehicleWeapon) then if getKeyState( "rclick" ) == true then createProjectile(player,projectileType, pX, pY, pZ, 0, nil, 0, 0, 0, vX, vY, vZ)) elseif (getTickCount() > (previousTick + 150) and previousTick > 0) then fireProjectile() end end end function fireProjectile() local vehicle = getPedOccupiedVehicle(player) local gun = false local gX, gY, gZ = 0, 0, 0 local gRotX, gRotY, gRotZ = 0, 0, 0 local pX, pY, pZ = 0, 0, 0 local vX, vY, vZ = 0, 0, 0 local currentLoSOffset = 3.5 local zPosOffset = 1.1 local thrust = 2.0 previousTick = 0 if (vehicle) then if (#getAttachedElements(vehicle) > 0) then gun = getAttachedElements(vehicle)[1] if (gun) then gX, gY, gZ = getElementPosition(gun) gRotX, gRotY, gRotZ = getElementRotation(gun) pX = gX - math.sin(-math.rad(gRotZ + 90)) * currentLoSOffset pY = gY + math.cos(-math.rad(gRotZ + 90)) * currentLoSOffset pZ = gZ + zPosOffset vX = math.sin (math.rad((gRotZ + 90))) * thrust vY = math.cos(math.rad((gRotZ + 90))) * thrust vZ = 0 createExplosion(pX, pY, pZ, 5, true, -1.0, false) createProjectile(player, projectileType, pX, pY, pZ, 0, nil, 0, 0, 0, vX, vY, vZ) end end end previousTick = getTickCount() end function changeProjectileType(commandName, arg) projectileType = tonumber(arg) or 20 end addEventHandler("onClientElementDataChange", root, callbackDataChange, true) addEventHandler("onClientVehicleEnter", root, callbackVehicleEnter, true) addEventHandler("onClientRender", root, callbackRender, true) addCommandHandler("guntype", changeProjectileType) It doesn't want to fire anymore and still nothing with aim . Link to comment
bandi94 Posted July 13, 2011 Share Posted July 13, 2011 whitout getkeystate work ? i mean whitout my code ? Link to comment
NeXTreme Posted July 14, 2011 Share Posted July 14, 2011 I don't exactly know what you want, however "rclick" is not a valid key. If you want the right mouse button, use "mouse2". Link to comment
CapY Posted July 14, 2011 Author Share Posted July 14, 2011 @NeXTreme I want to aim with minigun . @Bandi94 It doesn't works for now . Link to comment
bandi94 Posted July 14, 2011 Share Posted July 14, 2011 ok in next 3 days maybe i make my minigun script whit a map and i will update thet map whit script on comunity and after you download it get the code part what you whant and edit it .. (only to have a litel time) Link to comment
CapY Posted July 14, 2011 Author Share Posted July 14, 2011 Okay! Thanks for your help. Link to comment
CapY Posted July 14, 2011 Author Share Posted July 14, 2011 Check this vid. I want minigun aims and moves exactly like this one on the vid. EDIT:Just watch whole vid. and you'll know what im talking about. Link to comment
bandi94 Posted July 14, 2011 Share Posted July 14, 2011 i make my own minigun whit a car and map if you like it ok if not make it yourself .... Link to comment
CapY Posted July 14, 2011 Author Share Posted July 14, 2011 Okay, im waiting for you . Link to comment
CapY Posted July 18, 2011 Author Share Posted July 18, 2011 i make my own minigun whit a car and map if you like it ok if not make it yourself .... Then, are you done ? 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