Jump to content

Xwad

Members
  • Posts

    1,089
  • Joined

  • Last visited

Everything posted by Xwad

  1. Xwad

    can't store data

    Well, i can't explain myself eneugh, so here is my full script. This script creates a machine gun on the map, in which you can enter and shoot. What i want to do is duplicate the machine gun. I mean creating a second machine gun. More precisely: If i put one more "createMG" function after line 2 then it will create a new machinegun. function mg_pos() createMG(-2861.9, 19.4, 15.83, 0, 0, 188) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), mg_pos) I tried to do it in a lot of ways, but always when i tested it, it had a lot of sync bugs. I ask you guys for help to fix this script. I am creating this script for the community. http://www.mediafire.com/file/3oud140w15dims4/mg.rar
  2. Xwad

    can't store data

    yes i need the setElementData, because there are other functions that cant get the data without the setElementData. When i remove "local" from local mg = createObject ( 356, 0,0,0) then its working, but i want to use it in local
  3. Xwad

    can't store data

    ok, now i edited my script a littlebit. i removed the table and added a local element, but its still not sotring the data server function mg_pos() createMG(-2861.9, 19.4, 15.83, 0, 0, 188) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), mg_pos) function createMG(posX,posY,posZ,rotX,rotY,rotZ) local mg = createObject ( 356, 0,0,0) -- this is where the data will be stored (new line) local weapon_base = createObject ( 1897, posX,posY,posZ,rotX,rotY,rotZ) local weapon = createObject ( 356, 0,0,0) attachElements ( weapon, weapon_base, -0.55, 0, 0.75, 0, 0, 0) setElementData ( mg, "weapon_base", weapon_base) setElementData ( mg, "weapon", weapon) setElementAlpha(weapon_base, 0) setTimer ( event, 500, 1 ) end function event() local weapon = getElementData ( mg, "weapon" ) triggerClientEvent("createRealWeapon", root, weapon, weapon2) end and client function create_client(weapon) local x,y,z = getElementPosition ( weapon ) local weapon_c = createWeapon("minigun", x,y,z) attachElements ( weapon_c, weapon, 1.1, -0.12, 0.152, -6, 3, -2 ) setElementCollisionsEnabled( weapon_c, false ) setWeaponState ( weapon_c, "ready" ) setElementAlpha ( weapon_c, 255 ) setWeaponFiringRate ( weapon_c , 60 ) setElementParent( weapon_c, weapon ) setWeaponProperty( weapon_c, "damage", 0) setWeaponProperty ( weapon_c, "fire_rotation", 0, -27, -5.5 ) setWeaponProperty ( weapon_c, "weapon_range", 10000 ) setWeaponProperty ( weapon_c, "target_range", 10000 ) setWeaponClipAmmo( weapon_c, 250 ) setElementData ( weapon_c, "owner", player ) setElementData ( localPlayer, "gun", weapon_c ) end addEvent("createRealWeapon", true) addEventHandler("createRealWeapon",root, create_client)
  4. Xwad

    can't store data

    I try to get the element data with getElementData(mg, "weapon_base") but its not getting the element data.
  5. My problem is that it's not storing the data in the local mg = {}. The debugscript says: bad argumentum @ 'setElememtData' expected element at argument 1, got table Thanks in advance! function mg_pos() createMG(-2861.9, 19.4, 15.83, 0, 0, 188) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), mg_pos) --MG 1 local mg = {} function createMG(posX,posY,posZ,rotX,rotY,rotZ) local weapon_base = createObject ( 1897, posX,posY,posZ,rotX,rotY,rotZ) local weapon = createObject ( 356, 0,0,0) attachElements ( weapon, weapon_base, -0.55, 0, 0.75, 0, 0, 0) setElementData ( mg, "weapon_base", weapon_base) setElementData ( mg, "weapon", weapon) end
  6. Xwad

    [MAP] Normandy 1944

    Download link has been added to the topic. Check the top of the page.
  7. Now i test it and i am sure that the problem is not with the element rotation. The problem is with the setElementData.. it dosent get the element data of the object called "object3", and thats why it cant rotate it
  8. the wiki says: "This function updates the offsets of an element that has been attached to another element using attachElements." thats why i am using setElementAttachedOffsets and not setElementRotation. Thats true, i gonna try it:D
  9. Everythink is working in the code, only the rotating not. When i press mouse1 then the weapons and the object will be created but its not rotating. This rotating function makes possible to rotate the object called "object3" to that direction where the "misc_a" (vehicle component) and the "misc_c" (vehicle component) is rotating at. The problem is that its not rotating the object. I hope you can help me again. Thanks in advance! client object3 = {}; mg1 = {}; mg2 = {}; addEvent ( 'fire_mg',true ); addEventHandler ( 'fire_mg',root, function ( aVehicle,aX,aY,aZ ) if aVehicle and aX and aY and aZ then object3 [ aVehicle ] = createObject ( 357, aX,aY,aZ) attachElements ( object3 [ aVehicle ], aVehicle, -0.05,10,3, 0,0,90 ) mg1 [ aVehicle ] = createWeapon("m4", aX,aY,aZ) mg2 [ aVehicle ] = createWeapon("m4", aX,aY,aZ) setWeaponFiringRate(mg1 [ aVehicle ], 20) setWeaponFiringRate(mg2 [ aVehicle ], 20) setWeaponState(mg1 [ aVehicle ], "firing") setWeaponState(mg2 [ aVehicle ], "firing") attachElements(mg1 [ aVehicle ], object3 [ aVehicle ], 0.2, 0.2, 0, 0, 0, 0) attachElements(mg2 [ aVehicle ], object3 [ aVehicle ], 0.2, -0.3, 0, 0, 0, 0) setElementData ( aVehicle,'mgFireOn',true ); local veh = getPedOccupiedVehicle(localPlayer) setElementData ( aVehicle,'object3',object3 [ aVehicle ] ); addEventHandler("onClientRender",root,rotate_object) end end ); function rotate_object() local veh = getPedOccupiedVehicle(localPlayer) local _,_,rz = getVehicleComponentRotation(veh, "misc_a") local rx,_,_ = getVehicleComponentRotation(veh, "misc_c") triggerServerEvent("rotateWeapon", localPlayer, rx,rz) end server function rotateWeapon(rx,rz) outputChatBox("rotate_s") local object3 = getElementData ( aVehicle, "object3" ) rx = (-rx) setElementAttachedOffsets ( object3, 0, 5.25, 2.45, 0, rx+7, rz+96) end addEvent("rotateWeapon", true) addEventHandler("rotateWeapon", root, rotateWeapon) function fire ( aPlayer ) if aPlayer and getElementType ( aPlayer ) == 'player' then if isPedInVehicle ( aPlayer ) then local aVehicle = getPedOccupiedVehicle( aPlayer ); if aVehicle and getElementModel ( aVehicle ) == 592 then local aX,aY,aZ = getElementPosition ( aVehicle ); triggerClientEvent ( root,'fire_mg',root,aVehicle,aX,aY,aZ ); end end end end function bind_start() for _,aPlayers in ipairs ( getElementsByType ( 'player' ) ) do bindKey ( aPlayers,'mouse1','down',fire ); end end addEventHandler ( 'onResourceStart',resourceRoot,bind_start) function bind_join() bindKey ( aPlayers,'mouse1','down',fire ); end addEventHandler ( 'onPlayerJoin',root,bind_join )
  10. I have a new problem. Do not get me wrong, the previous code works perfect. I just added some new functions in the code. So first i changed all playSound3D to createWeapon, and it worked perfect. But i added a rotation system that does not work. This rotating function makes possible to rotate the object called "object3" to that direction where the "misc_a" (vehicle component) and the "misc_c" (vehicle component) is rotating at. The problem is that its not rotating the object. I hope you can help me again. Thanks in advance! client object3 = {}; mg1 = {}; mg2 = {}; addEvent ( 'fire_mg',true ); addEventHandler ( 'fire_mg',root, function ( aVehicle,aX,aY,aZ ) if aVehicle and aX and aY and aZ then object3 [ aVehicle ] = createObject ( 357, aX,aY,aZ) attachElements ( object3 [ aVehicle ], aVehicle, -0.05,10,3, 0,0,90 ) mg1 [ aVehicle ] = createWeapon("m4", aX,aY,aZ) mg2 [ aVehicle ] = createWeapon("m4", aX,aY,aZ) setWeaponFiringRate(mg1 [ aVehicle ], 20) setWeaponFiringRate(mg2 [ aVehicle ], 20) setWeaponState(mg1 [ aVehicle ], "firing") setWeaponState(mg2 [ aVehicle ], "firing") attachElements(mg1 [ aVehicle ], object3 [ aVehicle ], 0.2, 0.2, 0, 0, 0, 0) attachElements(mg2 [ aVehicle ], object3 [ aVehicle ], 0.2, -0.3, 0, 0, 0, 0) setElementData ( aVehicle,'mgFireOn',true ); local veh = getPedOccupiedVehicle(localPlayer) setElementData ( aVehicle,'object3',object3 [ aVehicle ] ); addEventHandler("onClientRender",root,rotate_object) end end ); function rotate_object() local veh = getPedOccupiedVehicle(localPlayer) local _,_,rz = getVehicleComponentRotation(veh, "misc_a") local rx,_,_ = getVehicleComponentRotation(veh, "misc_c") triggerServerEvent("rotateWeapon", localPlayer, rx,rz) end and the server side function rotateWeapon(rx,rz) outputChatBox("rotate_s") local object3 = getElementData ( aVehicle, "object3" ) rx = (-rx) setElementAttachedOffsets ( object3, 0, 5.25, 2.45, 0, rx+7, rz+96) end addEvent("rotateWeapon", true) addEventHandler("rotateWeapon", root, rotateWeapon) function fire ( aPlayer ) if aPlayer and getElementType ( aPlayer ) == 'player' then if isPedInVehicle ( aPlayer ) then local aVehicle = getPedOccupiedVehicle( aPlayer ); if aVehicle and getElementModel ( aVehicle ) == 592 then local aX,aY,aZ = getElementPosition ( aVehicle ); triggerClientEvent ( root,'fire_mg',root,aVehicle,aX,aY,aZ ); end end end end function bind_start() for _,aPlayers in ipairs ( getElementsByType ( 'player' ) ) do bindKey ( aPlayers,'mouse1','down',fire ); end end addEventHandler ( 'onResourceStart',resourceRoot,bind_start) function bind_join() bindKey ( aPlayers,'mouse1','down',fire ); end addEventHandler ( 'onPlayerJoin',root,bind_join )
  11. Now it works perfect! I just changed false to true at line 11 in client side to make the sound looped!! Thanks Kariim and FaHaD for your help!! <3
  12. now it has a new bug: when player1 press CTRL then the sound starts. But when player2 press CTRL too, then the sound stops for player1!
  13. Now the sync works again, but it has the same bug as the first time (the sound will not stop for player2 because the setElementData is owerwrited). And it has now one more bug. the sound_fire_lastshot is always repeating:/
  14. other players still can't hear it
  15. I changed all triggerServerEvents to: triggerServerEvent ( "start_fire_sound", localPlayer, veh ) In the server side i changed the getRootElement() to source triggerClientEvent ("start_fire_sound", source, veh) Now the problem is that other player cant hear the sound (sync is not working). Please help!
  16. Hi! This script makes possible to play a 3d sound (looped sound) by pressing the CTRL button, and stop the sound when the CTRL button is "up". Well, it has a really annoying sync bug. As you can see, there is a setElementData function in my client side script, that stores the sound element. When the player stops pressing the CTRL button then the script stops the sound with the stored element. Well the problem is that when another player press the CTRL button then the setElementData will be overwritted, and will cause really strange, annoying bugs. So the bug is: when player1 press CTRL, and after that player2 also press CTRL then the sound for player1 will not stop anymore, because player2 owerwrited the setElementData, when he pressed CTRL. Well, its not easy to explain, so i hope you understood me. Is the any way to avoid this owerwriting? or do i have to do this another way, without setElementData? Thanks in advance. client --start sound function start_fire_sound() if isPedInVehicle (localPlayer) then local veh = getPedOccupiedVehicle(localPlayer) if getElementModel(veh) == 476 then triggerServerEvent ( "start_fire_sound", resourceRoot, veh ) end end end bindKey("lctrl", "down", start_fire_sound) function start_fire_c(veh) local x,y,z = getElementPosition (veh) local sound_fire = playSound3D("files/fire.wav",x,y,z, true) setSoundMaxDistance( sound_fire, 500 ) setSoundVolume(sound_fire, 1) attachElements ( sound_fire, veh, 0,0,0 ) setElementData(localPlayer, "sound_fire", sound_fire) end addEvent( "start_fire_sound", true ) addEventHandler( "start_fire_sound", localPlayer, start_fire_c ) --stop sound function stop_fire_sound() if isPedInVehicle (localPlayer) then local veh = getPedOccupiedVehicle(localPlayer) if getElementModel(veh) == 476 then triggerServerEvent ( "stop_fire_sound", resourceRoot, veh ) end end end bindKey("lctrl", "up", stop_fire_sound) function stop_fire_sound_c(veh) local x,y,z = getElementPosition (veh) local sound_fire_lastshot = playSound3D("files/fire_lastshot.wav",x,y,z, false) setSoundMaxDistance( sound_fire_lastshot, 500 ) setSoundVolume(sound_fire_lastshot, 1) attachElements ( sound_fire_lastshot, veh, 0,0,0 ) local sound_fire = getElementData(localPlayer, "sound_fire") stopSound(sound_fire) end addEvent( "stop_fire_sound", true ) addEventHandler( "stop_fire_sound", localPlayer, stop_fire_sound_c ) server function start_fire_sound(veh) triggerClientEvent ("start_fire_sound", getRootElement(), veh) end addEvent( "start_fire_sound", true ) addEventHandler( "start_fire_sound", getRootElement(), start_fire_sound ) function stop_fire_sound(veh) triggerClientEvent ("stop_fire_sound", getRootElement(), veh) end addEvent( "stop_fire_sound", true ) addEventHandler( "stop_fire_sound", getRootElement(), stop_fire_sound )
  17. Why does the setElementAttachedOffsets (in server side) not work? i got no debugscript client function onEnter2(player,seat) local model = getElementModel(source) if player == localPlayer and (model == 602) and seat == 0 then local veh = getPedOccupiedVehicle(localPlayer) local x,y,z = getElementPosition(veh) local object = createObject ( 357, x,y,z) attachElements(object, veh, 0,0,1,0,0,0) createWeapon_c(veh,object) setElementData(localPlayer,"object", object) addEventHandler('onClientRender', root, rotate_object ) end end addEventHandler("onClientVehicleEnter", root, onEnter2) function rotate_object() local veh = getPedOccupiedVehicle(localPlayer) local object = getElementData(localPlayer,"object") local _,_,rz = getVehicleComponentRotation(veh, "misc_a") local rx,_,_ = getVehicleComponentRotation(veh, "misc_b") triggerServerEvent("rotateWeapon", root, object,rx,rz) end and the server (which is actualy not woroking) function rotateWeapon(object,rx,rz) outputChatBox("rotate_s") rx = (-rx) setElementAttachedOffsets ( object, 0, 0, 1, 0, rx+7, rz+96) end addEvent("rotateWeapon", true) addEventHandler("rotateWeapon", root, rotateWeapon)
  18. No, i mean setting the x,y,z position. Gor example: I enter in a vehicle and set the z position of the player +10. Then the player will not inside the vehicle anymore, because its on the top of the vehicle. But it can still drive the car untin he exit from the car.
×
×
  • Create New...