Xwad Posted March 23, 2015 Posted March 23, 2015 Hi i have a script that attaches a m4 to rhino and allows to shoot with ctrl but when i shoot a player then it dosent demage the player pls help vehWeapons = {} function createM4Weapon() if getElementModel(source) == 432 then vehWeapons[source] = {} local vX, vY, vZ = getElementPosition(source) -- Wep 1 vehWeapons[source][1] = createWeapon("m4", vX, vY, vZ + 1) setWeaponClipAmmo(vehWeapons[source][1], 500) setWeaponState(vehWeapons[source][1], "ready") attachElements(vehWeapons[source][1],source,0.7,2.4,0.7,0,0,90) setWeaponFiringRate ( vehWeapons[source][1] , 63 ) end end addEventHandler( "onClientVehicleEnter",getRootElement(),createM4Weapon) addEventHandler("onClientKey", root, function(button,state) local veh = getPedOccupiedVehicle(localPlayer) if veh then if getElementModel(veh) == 432 then if vehWeapons[veh][1] then if button == "lctrl" and state == true then setWeaponState(vehWeapons[veh][1],"firing") else setWeaponState(vehWeapons[veh][1],"ready") end end end end end) function destroyCurrentVehicleWeapons() destroyElement(vehWeapons[source][1]) vehWeapons[source] = false -- Destroy the Weapons end addEventHandler("onClientVehicleExit",root, destroyCurrentVehicleWeapons) addEventHandler("onClientVehicleExplode",root, destroyCurrentVehicleWeapons)
Mr.unpredictable. Posted March 23, 2015 Posted March 23, 2015 Hi i have a script that attaches a m4 to rhino and allows to shoot with ctrl but when i shoot a player then it dosent demage the player pls help vehWeapons = {} function createM4Weapon() if getElementModel(source) == 432 then vehWeapons[source] = {} local vX, vY, vZ = getElementPosition(source) -- Wep 1 vehWeapons[source][1] = createWeapon("m4", vX, vY, vZ + 1) setWeaponClipAmmo(vehWeapons[source][1], 500) setWeaponState(vehWeapons[source][1], "ready") attachElements(vehWeapons[source][1],source,0.7,2.4,0.7,0,0,90) setWeaponFiringRate ( vehWeapons[source][1] , 63 ) end end addEventHandler( "onClientVehicleEnter",getRootElement(),createM4Weapon) addEventHandler("onClientKey", root, function(button,state) local veh = getPedOccupiedVehicle(localPlayer) if veh then if getElementModel(veh) == 432 then if vehWeapons[veh][1] then if button == "lctrl" and state == true then setWeaponState(vehWeapons[veh][1],"firing") else setWeaponState(vehWeapons[veh][1],"ready") end end end end end) function destroyCurrentVehicleWeapons() destroyElement(vehWeapons[source][1]) vehWeapons[source] = false -- Destroy the Weapons end addEventHandler("onClientVehicleExit",root, destroyCurrentVehicleWeapons) addEventHandler("onClientVehicleExplode",root, destroyCurrentVehicleWeapons) Script looks fine, What's the problem.
Xwad Posted March 23, 2015 Author Posted March 23, 2015 No i using this to my WW2 server. The problem is that i cant demage players when i shoot with the attached m4
Moderators IIYAMA Posted March 23, 2015 Moderators Posted March 23, 2015 They disabled the weapon damage somehow. Use: https://wiki.multitheftauto.com/wiki/OnClientWeaponFire To overwrite the damage.
toxicsmoke11 Posted March 23, 2015 Posted March 23, 2015 I think that problem is that weapon is not synced with other players
TAPL Posted March 23, 2015 Posted March 23, 2015 I think that problem is that weapon is not synced with other players That's true, he did create the weapon with the event onClientVehicleEnter, the event will trigger for streamed in players only. Also he used the event onClientKey that trigger only to him self which mean other players won't see the weapon firing.
Mr.Loki Posted March 23, 2015 Posted March 23, 2015 try using triggerServerEvent then triggerClientEvent
Xwad Posted April 14, 2015 Author Posted April 14, 2015 You mean need i trigger the client event for setelementHealth?
Mr.Loki Posted April 18, 2015 Posted April 18, 2015 No, onClientkey > triggerserverevent >triggerclientevent > making the weapin fire
Xwad Posted April 29, 2015 Author Posted April 29, 2015 I try but i cant make it:/ Is it something like that? client addEventHandler( "onClientKey", root, function(button,press) if button == "ctrl" then triggerServerEvent ( "createM4Weapon", resourceRoot, "shooting" ) return true end return false end ) server function createM4Weapon ( message ) -- the predefined variable 'client' points to the player who triggered the event and should be used due to security issues triggerClientEvent ( playerSource, "createM4Weapon", playerSource, "Hello World!" ) end addEvent( "createM4Weapon", true ) addEventHandler( "createM4Weapon", resourceRoot, greetingHandler ) -- Bound to this resource only, saves on CPU usage.
Walid Posted April 29, 2015 Posted April 29, 2015 playerSource it's not defined in your code replace it with client.
Xwad Posted May 1, 2015 Author Posted May 1, 2015 you mean need i add this to client? vehWeapons = {} function createM4Weapon() if getElementModel(source) == 432 then vehWeapons[source] = {} local vX, vY, vZ = getElementPosition(source) -- Wep 1 vehWeapons[source][1] = createWeapon("m4", vX, vY, vZ + 1) setWeaponClipAmmo(vehWeapons[source][1], 500) setWeaponState(vehWeapons[source][1], "ready") attachElements(vehWeapons[source][1],source,0.7,2.4,0.7,0,0,90) setWeaponFiringRate ( vehWeapons[source][1] , 63 ) end end addEventHandler( "onClientVehicleEnter",getRootElement(),createM4Weapon) addEventHandler("onClientKey", root, function(button,state) local veh = getPedOccupiedVehicle(localPlayer) if veh then if getElementModel(veh) == 432 then if vehWeapons[veh][1] then if button == "lctrl" and state == true then setWeaponState(vehWeapons[veh][1],"firing") else setWeaponState(vehWeapons[veh][1],"ready") end end end end end) function destroyCurrentVehicleWeapons() destroyElement(vehWeapons[source][1]) vehWeapons[source] = false -- Destroy the Weapons end addEventHandler("onClientVehicleExit",root, destroyCurrentVehicleWeapons) addEventHandler("onClientVehicleExplode",root, destroyCurrentVehicleWeapons)
Xwad Posted May 1, 2015 Author Posted May 1, 2015 is there any video where they teach how to define player source? becaouse i dont know how:/
Walid Posted May 1, 2015 Posted May 1, 2015 is there any video where they teach how to define player source? becaouse i dont know how:/ what do you mean by player source , can you explane to us what you want exactly.
Xwad Posted May 1, 2015 Author Posted May 1, 2015 My script makes possible to attach weapons to vehicles but i cant demage players only vehicles.. And the other problem is that other players cant see the weapon and the projectile and if i press w and start shooting and after that i stop pressing w then the weapon shooting stops.
Mr.unpredictable. Posted May 1, 2015 Posted May 1, 2015 My script makes possible to attach weapons to vehicles but i cant demage players only vehicles.. And the other problem is that other players cant see the weapon and the projectile and if i press w and start shooting and after that i stop pressing w then the weapon shooting stops. It's because your script is client side use triggerClientevent and triggerserver event to fix that.
Xwad Posted May 1, 2015 Author Posted May 1, 2015 ok but what functions or events need i add to server side?
Xwad Posted May 3, 2015 Author Posted May 3, 2015 Fnaly i made i hope i made it good without problems.. So is it good? Client triggerServerEvent ( "MachineGun", localPlayer, { end addEvent ( "MachineGun2", true ); addEventHandler ( "MachineGun2", root, function ( createM4Weapon ) vehWeapons = {} function createM4Weapon() if getElementModel(source) == 432 then vehWeapons[source] = {} local vX, vY, vZ = getElementPosition(source) -- Wep 1 vehWeapons[source][1] = createWeapon("m4", vX, vY, vZ + 1) setWeaponClipAmmo(vehWeapons[source][1], 500) setWeaponState(vehWeapons[source][1], "ready") attachElements(vehWeapons[source][1],source,0.7,2.4,0.7,0,0,90) setWeaponFiringRate ( vehWeapons[source][1] , 63 ) end end addEventHandler( "onClientVehicleEnter",getRootElement(),createM4Weapon) addEventHandler("onClientKey", root, function(button,state) local veh = getPedOccupiedVehicle(localPlayer) if veh then if getElementModel(veh) == 432 then if vehWeapons[veh][1] then if button == "lctrl" and state == true then setWeaponState(vehWeapons[veh][1],"firing") else setWeaponState(vehWeapons[veh][1],"ready") end end end end end) function destroyCurrentVehicleWeapons() destroyElement(vehWeapons[source][1]) vehWeapons[source] = false -- Destroy the Weapons end addEventHandler("onClientVehicleExit",root, destroyCurrentVehicleWeapons) addEventHandler("onClientVehicleExplode",root, destroyCurrentVehicleWeapons) server addEvent ( "MachineGun", true ); addEventHandler ( "MachineGun", root, function ( info ) triggerClientEvent ( root, "MachineGun2", root, info ); end );
Addlibs Posted May 3, 2015 Posted May 3, 2015 I think you should reconsider what you wrote on Line 8 of the client code addEventHandler ( "MachineGun2", root, function ( createM4Weapon ) Didn't you mean addEventHandler ( "MachineGun2", root, createM4Weapon ) — You also need to put it AFTER the createM4Weapon function, not before And what is that only line 2 and 3?
Xwad Posted May 3, 2015 Author Posted May 3, 2015 the line 2 and 3 is for triggering the server event. Is it not good?
Xwad Posted May 5, 2015 Author Posted May 5, 2015 is it now correct? triggerServerEvent ( "MachineGun", root, localPlayer, { end
Xwad Posted May 5, 2015 Author Posted May 5, 2015 or need i give for it and event for onCloentWeaponFire?
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