gokalpfirat Posted July 10, 2011 Share Posted July 10, 2011 I create this script but it wont work. It must do when we press ctrl it will fire hunter rocket. I use this script in my map. You can use rocket 1 time in 3 seconds. There is the code its client side. g_Root = getRootElement() g_P = getLocalPlayer() function onResourceStart(res) setElementData(g_P,"rocket",1) end addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),onResourceStart) function rocket (thePlayer) if (getElementData(thePlayer,"rocket")==1) then createProjectile(getLocalPlayer(),19,getElementPosition(getLocalPlayer()),200) rocketT = setTimer(timey,3000,1) else outputChatBox("You must wait 3 seconds to fire again",thePlayer,0,255,0,true) end end bindKey("ctrl","down",rocket) function timey () setElementData(g_P,"rocket",1) killTimer(rocketT) end Link to comment
Arran Posted July 10, 2011 Share Posted July 10, 2011 1. You're using onResourceStart in a client side file it should be onClientResourceStart. 2. Why even bother having some code inside it, and not another bit? I'm talking about that bindKey. 3. g_Root isn't needed as root is a predefined variable. 4. If that element data doesn't need to be known server side, don't sync it (set arg 4 to false) 5. Indent your code so we can follow it (press tab at things like if, function, for) 6. You're using thePlayer inside client side outputChatBox, remove it. 7. thePlayer inside your rocket function won't work because its client side so there is no person arg needed. Link to comment
Aibo Posted July 10, 2011 Share Posted July 10, 2011 also there is no "ctrl" key name, it "lctrl" for left and "rctrl" for right ctrl keys. also i'd ditched element data and used timer variable to check if player is allowed to shoot: g_P = getLocalPlayer() rocketTimer = false function rocket() if not rocketTimer then createProjectile(g_P, 19, getElementPosition(g_P), 200) rocketTimer = setTimer(function() rocketTimer = false end, 3000, 1) else outputChatBox("You must wait 3 seconds to fire again", 0, 255, 0, true) end end function onResourceStart() bindKey("lctrl", "down", rocket) end addEventHandler("onClientResourceStart", resourceRoot, onResourceStart) PS: since you want this on a vehicle, you should check if player is in a vehicle and get vehicle positions for projectile. Link to comment
gokalpfirat Posted July 11, 2011 Author Share Posted July 11, 2011 When i use this g_P = getLocalPlayer() rocketTimer = false g_V = getPedOccupiedVehicle(g_P) function rocket() if not rocketTimer then createProjectile(g_P, 19, getElementPosition(g_V), 200) rocketTimer = setTimer(function() rocketTimer = false end, 3000, 1) else outputChatBox("You must wait 3 seconds to fire again", 0, 255, 0, true) end end function onResourceStart() bindKey("lctrl", "down", rocket) end addEventHandler("onClientResourceStart", resourceRoot, onResourceStart) It wont work and when i use aibo s it blows near my car:) Link to comment
Orange Posted July 11, 2011 Share Posted July 11, 2011 Maybe above vehicle? g_P = getLocalPlayer() rocketTimer = false function rocket() if not rocketTimer then local x,y,z = getElementPosition(g_P) createProjectile(g_P, 19, x,y,z + 1, 200) rocketTimer = setTimer(function() rocketTimer = false end, 3000, 1) else outputChatBox("You must wait 3 seconds to fire again", 0, 255, 0, true) end end function onResourceStart() bindKey("lctrl", "down", rocket) end addEventHandler("onClientResourceStart", resourceRoot, onResourceStart) Link to comment
gokalpfirat Posted July 11, 2011 Author Share Posted July 11, 2011 g_P = getLocalPlayer() rocketTimer = false g_V = getPedOccupiedVehicle(g_P) rotX,rotY,rotZ = getElementRotation(g_V) function rocket() if not rocketTimer then local x,y,z = getElementPosition(g_P) createProjectile(g_P, 19, x,y - 10,z + 1, 200,nil,rotX,rotY,rotZ) rocketTimer = setTimer(function() rocketTimer = false end, 3000, 1) else outputChatBox("You must wait 3 seconds to fire again", 0, 255, 0, true) end end function onResourceStart() bindKey("lctrl", "down", rocket) end addEventHandler("onClientResourceStart", resourceRoot, onResourceStart) I scripted this it works but sometimes rocket goes backwards of vehicle. I want it always go infront of vehicle. Like hunter. Link to comment
gokalpfirat Posted July 11, 2011 Author Share Posted July 11, 2011 No one knows my error Link to comment
Arran Posted July 11, 2011 Share Posted July 11, 2011 g_P = getLocalPlayer() rocketTimer = false function rocket() local g_V = getPedOccupiedVehicle(g_P) local rotX,rotY,rotZ = getElementRotation(g_V) if not rocketTimer then local x,y,z = getElementPosition(g_P) createProjectile(g_P, 19, x,y - 10,z + 1, 200,nil,rotX,rotY,rotZ) rocketTimer = setTimer(function() rocketTimer = false end, 3000, 1) else outputChatBox("You must wait 3 seconds to fire again", 0, 255, 0, true) end end function onResourceStart() bindKey("lctrl", "down", rocket) end addEventHandler("onClientResourceStart", resourceRoot, onResourceStart) Getting the vehicle and its rotation had to be inside the firing function. Link to comment
gokalpfirat Posted July 11, 2011 Author Share Posted July 11, 2011 It works but at my last post i say too it fires left sometimes.I want fire to infront of car. When i look left it fires in front of car but. I want it always fires infront of car Link to comment
Wojak Posted July 11, 2011 Share Posted July 11, 2011 check this: https://forum.multitheftauto.com/viewtop ... cb#p353938 Link to comment
gokalpfirat Posted July 11, 2011 Author Share Posted July 11, 2011 Lots of code Can you only write a fix Link to comment
Wojak Posted July 11, 2011 Share Posted July 11, 2011 g_P = getLocalPlayer() rocketTimer = false function rocket() local g_V = getPedOccupiedVehicle(g_P) local rotX,rotY,rotZ = getElementRotation(g_V) if not rocketTimer then local x, y, z = getElementPosition(occupiedVehicle) local matrix = getElementMatrix( g_V) local offX = 0 * matrix[1][1] + 1 * matrix[2][1] + 0 * matrix[3][1] + 1 * matrix[4][1] local offY = 0 * matrix[1][2] + 1 * matrix[2][2] + 0 * matrix[3][2] + 1 * matrix[4][2] local offZ = 0 * matrix[1][3] + 1 * matrix[2][3] + 0 * matrix[3][3] + 1 * matrix[4][3] vx = offX - x vy = offY - y vz = offZ - z x = 0 * matrix[1][1] + 3 * matrix[2][1] + 0 * matrix[3][1] + 1 * matrix[4][1] y = 0 * matrix[1][2] + 3 * matrix[2][2] + 0 * matrix[3][2] + 1 * matrix[4][2] z = 0 * matrix[1][3] + 3 * matrix[2][3] + 0 * matrix[3][3] + 1 * matrix[4][3] createProjectile(g_p, 19, x, y, z, 200, nil, 0, 0, 360 - rotZ, vx, vy, vz) rocketTimer = setTimer(function() rocketTimer = false end, 3000, 1) else outputChatBox("You must wait 3 seconds to fire again", 0, 255, 0, true) end end function onResourceStart() bindKey("lctrl", "down", rocket) end addEventHandler("onClientResourceStart", resourceRoot, onResourceStart) it should create rocket 3m infront of the center of vehicle Link to comment
gokalpfirat Posted July 11, 2011 Author Share Posted July 11, 2011 It works but i have got 2 problems. Projectile is blowing near when car is moving and timer doesnt works. Link to comment
Aibo Posted July 11, 2011 Share Posted July 11, 2011 occupiedVehicle is nil. use /debugscript 3 also g_p is not g_P g_P = getLocalPlayer() rocketTimer = false function rocket() if not rocketTimer and isPedInVehicle(g_P) then local occupiedVehicle = getPedOccupiedVehicle(g_P) local rotX,rotY,rotZ = getElementRotation(occupiedVehicle) local x, y, z = getElementPosition(occupiedVehicle) local matrix = getElementMatrix(occupiedVehicle) local offX = 0 * matrix[1][1] + 1 * matrix[2][1] + 0 * matrix[3][1] + 1 * matrix[4][1] local offY = 0 * matrix[1][2] + 1 * matrix[2][2] + 0 * matrix[3][2] + 1 * matrix[4][2] local offZ = 0 * matrix[1][3] + 1 * matrix[2][3] + 0 * matrix[3][3] + 1 * matrix[4][3] local vx = offX - x local vy = offY - y local vz = offZ - z x = 0 * matrix[1][1] + 3 * matrix[2][1] + 0 * matrix[3][1] + 1 * matrix[4][1] y = 0 * matrix[1][2] + 3 * matrix[2][2] + 0 * matrix[3][2] + 1 * matrix[4][2] z = 0 * matrix[1][3] + 3 * matrix[2][3] + 0 * matrix[3][3] + 1 * matrix[4][3] createProjectile(g_P, 19, x, y, z, 200, nil, 0, 0, 360 - rotZ, vx, vy, vz) rocketTimer = setTimer(function() rocketTimer = false end, 3000, 1) else outputChatBox("You must wait 3 seconds to fire again", 0, 255, 0, true) end end function onResourceStart() bindKey("lctrl", "down", rocket) end addEventHandler("onClientResourceStart", resourceRoot, onResourceStart) Link to comment
gokalpfirat Posted July 11, 2011 Author Share Posted July 11, 2011 Thanks Aibo there is only one problem left. When car is moving when you fire it will blows you because it fires your near. How can i fix it? Link to comment
Wojak Posted July 11, 2011 Share Posted July 11, 2011 you may try two things: 1) multiply the velocity (vx*2,vy*2,vz*2) 2) add vehicle velocity to rocket velocity and always remember to debug the script, that someone give you Link to comment
gokalpfirat Posted July 11, 2011 Author Share Posted July 11, 2011 Thanks for everything i fix it myself 2 hours ago but now i have got problem with objects look at object topic 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