damien111 Posted January 9, 2013 Share Posted January 9, 2013 I cant get the script to let the fire be extinguished. I merged my script with the syncfire script. I cant figure out why it wont let the fire be extinguished though. Server local fireLocations = { {2016.54296875, -1641.65234375, 14.112878799438}, {2151.07421875, -1807.9921875, 13.54638671875}, {2500.5302734375, -1759.71484375, 13.546875}, {2480.876953125, -1536.6943359375, 24.189422607422}, {2434.80859375, -1289.4814453125, 25.347854614258}, { 2407.958984375, -1106.970703125, 40.295722961426} } function unpackFires () return unpack ( fireLocations [ math.random ( #fireLocations ) ] ) end function scriptCreateFire ( player, command ) local rob = getElementModel(player) if ( rob == 277 or rob == 278 or rob == 279) then destroyElement ( fireBlip ) local x, y, z = unpackFires() -- retrive the player's position fire = createFire( x, y, z , 20) -- create the fire in the player's position but with x + 5 fireBlip = createBlipAttachedTo ( fire, 20, 2, 0, 0, 0, 255, 0, 9999.0, source ) end end setTimer ( scriptCreateFire, 180000, 0 ) addCommandHandler ( "fire", scriptCreateFire ) function player_Wasted() destroyElement(fireBlip) end addEventHandler ( "onPlayerWasted", getRootElement(), player_Wasted ) synced_fire.lua local fireModel = 2023 local fires = {} addEvent("onFireExtinguished",true) addEvent("onFireCreate",true) function createFire(x,y,z) local fireElem = createObject(fireModel,x,y,z) setElementCollisionsEnabled(fireElem,false) local col = createColSphere(x,y,z+1,2) fires[fireElem] = {fireElem,col} addEventHandler("onColShapeHit",col,setFire) return fireElem end function setFire(elem,dim) if not dim then return end if not elem or not isElement(elem) then return end if getElementType(elem) == "player" then setPedOnFire(elem,true) end end function fireExtinguished(fireElem) triggerEvent("onFireExtinguished",source,fireElem) destroyElement(fires[fireElem][1]) destroyElement(fires[fireElem][2]) fires[fireElem] = nil end addEvent("fireExtinguished",true) addEventHandler("fireExtinguished",root,fireExtinguished) synced_fire_c.lua local fireModel = 2023 function applyFire() local fire = engineLoadDFF("fire.dff",1) engineReplaceModel(fire,fireModel) end addEventHandler("onClientResourceStart",resourceRoot,applyFire) function createExtinguisher(wep,_,_,hitX,hitY,hitZ) if wep ~= 42 then return end for k, v in ipairs(getElementsByType("object",resourceRoot)) do if getElementModel(v) == fireModel then local fX,fY,fZ = getElementPosition(v) local dist = getDistanceBetweenPoints2D(hitX,hitY,fX,fY) if dist < 1 then triggerServerEvent("fireExtinguished",localPlayer,v) end end end end addEventHandler("onClientPlayerWeaponFire",localPlayer,createExtinguisher) function enterTruck(veh,seat) if getElementModel(veh) ~= 407 or seat > 0 then return end if not rendering then addEventHandler("onClientRender",root,checkTurret) end end addEventHandler("onClientPlayerVehicleEnter",localPlayer,enterTruck) function exitTruck() if rendering then removeEventHandler("onClientRender",root,checkTurret) end end addEventHandler("onClientPlayerVehicleExit",localPlayer,exitTruck) addEventHandler("onClientPlayerWasted",localPlayer,exitTruck) function checkTurret() if not getKeyState("vehicle_fire") and not getKeyState("vehicle_secondary_fire") then return end outputDebugString("0") local veh = getPedOccupiedVehicle(localPlayer) outputDebugString("1") if not veh then return end outputDebugString("2") local fX,fY,fZ = getElementPosition(veh) outputDebugString("3") local turretPosX,turretPosY = getVehicleTurretPosition(veh) outputDebugString("4") local turretPosX = math.deg(turretPosX) outputDebugString("5") if turretPosX < 0 then turretPosX = turretPosX+360 end outputDebugString("6") local rotX,rotY,rotZ = getVehicleRotation(veh) outputDebugString("7") local turretPosX = turretPosX+rotZ-360 outputDebugString("8") if turretPosX < 0 then turretPosX = turretPosX+360 end outputDebugString("9") local firetruckShape = createColCircle(fX,fY,20) outputDebugString("10") local burningVehicles = getElementsWithinColShape(firetruckShape,"object") outputDebugString("11") for k, v in pairs(burningVehicles) do local bX,bY,bZ = getElementPosition(v) local neededRot = findRotation(fX,fY,bX,bY) outputDebugString(tostring(neededRot)) if turretPosX > neededRot-30 and turretPosX < neededRot+30 then triggerServerEvent("fireExtinguished",localPlayer,v) break end end destroyElement(firetruckShape) end function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t+360 end return t end Link to comment
MR.S3D Posted January 9, 2013 Share Posted January 9, 2013 What is the problem in your code؟ Link to comment
damien111 Posted January 9, 2013 Author Share Posted January 9, 2013 As i said ,its not letting me put out the fire.. I cant figure out why. Also there is no onFireExtuinguish event so how can i make something like that , so it pays a fireman per fire Link to comment
myonlake Posted January 9, 2013 Share Posted January 9, 2013 As far as I know, objects are not fire elements. You can't extinguish objects. That script creates an object, which has a fire on it, but it cannot be extinguished. The script requires the createFire function. If I was the one making the syncfire script, I'd make a continuous timer on createFire function so that it always re-creates it after some milliseconds. This also allows it to be extinguished. Link to comment
damien111 Posted January 9, 2013 Author Share Posted January 9, 2013 Well, what your saying is that the scripting just sets a object on fire, i think what it is suppose to do is create those fires server side, useing guidlines set by client side fires, so i made the server file a client file. But now i get another error, Bad Argument @ 'getElementModel' at line 16. local fireLocations = { {2016.54296875, -1641.65234375, 14.112878799438}, {2151.07421875, -1807.9921875, 13.54638671875}, {2500.5302734375, -1759.71484375, 13.546875}, {2480.876953125, -1536.6943359375, 24.189422607422}, {2434.80859375, -1289.4814453125, 25.347854614258}, { 2407.958984375, -1106.970703125, 40.295722961426} } function unpackFires () return unpack ( fireLocations [ math.random ( #fireLocations ) ] ) end function scriptCreateFire () playerSKin = getElementModel(source) if ( playerSKin == 277 or playerSKin == 278 or playerSKin == 279) then destroyElement ( fireBlip ) local x, y, z = unpackFires() -- retrive the player's position fire = createFire( x, y, z , 20) -- create the fire in the player's position but with x + 5 fireBlip = createBlipAttachedTo ( fire, 20, 2, 0, 0, 0, 255, 0, 9999.0, source ) end end setTimer ( scriptCreateFire, 180000, 0 ) addCommandHandler ( "fire", scriptCreateFire ) function player_Wasted() destroyElement(fireBlip) end addEventHandler ( "onPlayerWasted", getRootElement(), player_Wasted ) So yeah, i think i got that figured out, i just need help with that bit , and it should be set, sorry for these questions, i just got back into mta scripting again Link to comment
myonlake Posted January 9, 2013 Share Posted January 9, 2013 You cannot create fire server-side, because it is a client-side function. All rendering is done client-side always, it's obvious. Server doesn't display anything on server's screen because it doesn't have one, simply put. Try this combination, not sure if it'll work but worth of trying. Server-side addCommandHandler("fire", function(player, cmd) local playerSkin = getElementModel(player) if (playerSkin == 277 or playerSkin == 278 or playerSkin == 279) then destroyElement(fireBlip) fireBlip = createBlipAttachedTo(fire, 20, 2, 0, 0, 0, 255, 0, 9999.0, player) setTimer(function(player) local x, y, z = unpackFires() triggerClientEvent(root, "syncFires", player, x, y, z) end, 180000, 0, player) end end ) Client-side addEvent("syncFires", true) addEventHandler("syncFires", root, function(x, y, z) fire = createFire(x, y, z, 20) end ) Link to comment
damien111 Posted January 9, 2013 Author Share Posted January 9, 2013 You cannot create fire server-side, because it is a client-side function. All rendering is done client-side always, it's obvious. Haha yeah i figured that out quite quickly. Link to comment
damien111 Posted January 9, 2013 Author Share Posted January 9, 2013 Alright, so i had to tweak your code a little bit because of the blip being attached, and i think a few other things. I got everythingn to work but the fires spawning, i dont get any debugerrors so im pretty sure its triggering the event : Client addEvent("syncFires", true) addEventHandler("syncFires", root, function(x, y, z) fire = createFire(x, y, z, 50) fire = createFire(x+2, y, z, 50) fire = createFire(x-2, y, z, 50) fire = createFire(x, y+2, z, 50) fire = createFire(x, y-2, z, 50) end ) Server local fireLocations = { {2016.54296875, -1641.65234375, 14.112878799438}, {2151.07421875, -1807.9921875, 13.54638671875}, {2500.5302734375, -1759.71484375, 13.546875}, {2480.876953125, -1536.6943359375, 24.189422607422}, {2434.80859375, -1289.4814453125, 25.347854614258}, { 2407.958984375, -1106.970703125, 40.295722961426} } function unpackFires () return unpack ( fireLocations [ math.random ( #fireLocations ) ] ) end function scriptCreateFire(player, cmd) local playerSkin = getElementModel(player) if (playerSkin == 277 or playerSkin == 278 or playerSkin == 279) then destroyElement(fireBlip) local x, y, z = unpackFires() triggerClientEvent(root, "syncFires", player, x, y, z) fireBlip = createBlip(x ,y, z, 20) end end setTimer ( scriptCreateFire, 180000, 0 ) addCommandHandler ( "fire", scriptCreateFire ) function player_Wasted() destroyElement(fireBlip) end addEventHandler ( "onPlayerWasted", getRootElement(), player_Wasted ) Link to comment
myonlake Posted January 9, 2013 Share Posted January 9, 2013 Okay, let me explain what I actually did in your code. I put the setTimer inside the function, because otherwise the function would be executed without the parameters "player" and "cmd". These are critical in your script, and that is why I put it inside. So please use my code again and implement your version again. Do not remove the setTimer from the function, it won't work otherwise. Perhaps you could change the "player" to "root" as well, that shouldn't make any difference but I don't think that matters at this moment. Link to comment
damien111 Posted January 9, 2013 Author Share Posted January 9, 2013 the thing was the fire command was just to test the script, if i removed the command handler, made it just a function and triggered the function with a timer, that was half of the time, and the second timer was the second half, would that work? Link to comment
myonlake Posted January 9, 2013 Share Posted January 9, 2013 Yes, if you change "player" to "root". Link to comment
damien111 Posted January 9, 2013 Author Share Posted January 9, 2013 So , I am sorry for all this , but , its not creating the blips or anything anymore, heres my code, i did what you said. local fireLocations = { {2016.54296875, -1641.65234375, 14.112878799438}, {2151.07421875, -1807.9921875, 13.54638671875}, {2500.5302734375, -1759.71484375, 13.546875}, {2480.876953125, -1536.6943359375, 24.189422607422}, {2434.80859375, -1289.4814453125, 25.347854614258}, { 2407.958984375, -1106.970703125, 40.295722961426} } function unpackFires () return unpack ( fireLocations [ math.random ( #fireLocations ) ] ) end function scriptCreateFire(root, cmd) local playerSkin = getElementModel(root) if (playerSkin == 277 or playerSkin == 278 or playerSkin == 279) then destroyElement(fireBlip) setTimer(function(root) local x, y, z = unpackFires() fireBlip = createBlip(x,y,z,20) triggerClientEvent(root, "syncFires", root, x, y, z) end, 10000, 0, root) end end setTimer ( scriptCreateFire, 10000, 0 ) addCommandHandler ( "fire", scriptCreateFire ) function player_Wasted() destroyElement(fireBlip) end addEventHandler ( "onPlayerWasted", getRootElement(), player_Wasted ) Link to comment
myonlake Posted January 10, 2013 Share Posted January 10, 2013 I don't know what you actually want to do in the script, because first you say the command is just for testing, and now you use it - incorrectly. I have decided to make you an easier script. Now when the resource starts, it loads a random fire point. Every 10 seconds it repeats the createFire function, which will "synchronize" the fire to all clients (every 10 seconds). If you want to change the random fire point, you use the command "fire" if you have player model 277, 278 or 279. If you want to delete the existing fire point, type "extinguish" (it takes a minute or less to destroy the fire GTA-wise, so don't worry if it doesn't disappear when you type the command. It will just prevent it from creating them repeatedly). TL;DR: When the resource starts, it starts a random fire and keeps it synced every 10 seconds. When you type "fire" it stops the current fire and creates another one. When you type "extinguish" it stops the current fire but doesn't create a new one. Server-side local fireLocations = { {2016.54296875, -1641.65234375, 14.112878799438}, {2151.07421875, -1807.9921875, 13.54638671875}, {2500.5302734375, -1759.71484375, 13.546875}, {2480.876953125, -1536.6943359375, 24.189422607422}, {2434.80859375, -1289.4814453125, 25.347854614258}, {2407.958984375, -1106.970703125, 40.295722961426} } function unpackFires() return unpack(fireLocations[math.random(#fireLocations)]) end function createRandomFirePoint() local x, y, z = unpackFires() fireBlip = createBlip(x, y, z, 20) fireTimer = setTimer(function(x, y, z) triggerClientEvent(root, "syncFires", root, x, y, z) end, 10000, 0, x, y, z) end addEventHandler("onResourceStart", resourceRoot, createRandomFirePoint) addCommandHandler("fire", function(player, cmd) local playerSkin = getElementModel(root) if (playerSkin == 277 or playerSkin == 278 or playerSkin == 279) then if isTimer(fireTimer) then killTimer(fireTimer) end if isElement(fireBlip) then destroyElement(fireBlip) end createRandomFirePoint() end end ) addCommandHandler("extinguish", function(player, cmd) local playerSkin = getElementModel(root) if (playerSkin == 277 or playerSkin == 278 or playerSkin == 279) then if isTimer(fireTimer) then killTimer(fireTimer) end if isElement(fireBlip) then destroyElement(fireBlip) end end end ) Link to comment
damien111 Posted January 11, 2013 Author Share Posted January 11, 2013 Thankyou, you didnt understand what i mean , i msorry about that, im sometimes , very, hard to understand , i try to write to many things at once, also! I took this and it helped me make my own script, so thank you Link to comment
Moderators IIYAMA Posted January 11, 2013 Moderators Share Posted January 11, 2013 Maybe you can change a object with a mod? (dunno if possible with currently mods, but it should be "true") Link to comment
myonlake Posted January 12, 2013 Share Posted January 12, 2013 @damien111: You are very much welcome, and don't worry. Patience is always good Maybe you can change a object with a mod? (dunno if possible with currently mods, but it should be "true") What are you talking about? -- Off: I like that nobody came and interrupted our discussion. It's stupid when 10 people have a solution and everybody attacks the thread. Let the first replier handle the situation and stand back unless they ask someone else. Link to comment
Moderators IIYAMA Posted January 13, 2013 Moderators Share Posted January 13, 2013 Off: I like that nobody came and interrupted our discussion. It's stupid when 10 people have a solution and everybody attacks the thread. Let the first replier handle the situation and stand back unless they ask someone else. It's always good to come with another (good)solution, because the "createFire" function is useless. ( using an object as fire, it makes it possible to delete it and won't give so much trouble with teamkilling etc.) I don't think that is stupid because preventing is better than rewriting. This my opinion. Let the first replier handle the situation and stand back unless they ask someone else. Note: I will mind that, thx I let your discussion to continue, if it is still on. Link to comment
myonlake Posted January 13, 2013 Share Posted January 13, 2013 It's always good to come with another (good)solution, because the "createFire" function is useless. ( using an object as fire, it makes it possible to delete it and won't give so much trouble with teamkilling etc.) I don't think that is stupid because preventing is better than rewriting. This my opinion. I understand your opinion, but the fact that you are not able to extinguish object-based fire is what he didn't want. He wanted to be able to extinguish fires, and to do that, you need to use the createFire -function. It's not useless, it's there for a reason - not only that it is an actual element, but it's useful for many codes. 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