jingzhi Posted February 11, 2015 Share Posted February 11, 2015 Client-side addEvent("onPlayerArrested",true) function cuffed(arrester,source) local x,y,z = getElementPosition(arrester) local fx,fy,fz = getElementPosition(arrestedcriminal) local distance = getDistanceBetweenPoints2D(fx,fy,x,y) if distance < 2 then setControlState("forwards", false) setControlState("sprint", false ) setTimer (cuffed, 500, 0, arrester, arrestedcriminal ) return else setControlState("forwards", true) setControlState("sprint", true ) setTimer ( cuffed, 500, 0, arrester, arrestedcriminal ) local X,Y = 0,0 local X = math.abs( x - fx ) local Y = math.abs( y - fy ) local angle = math.deg(math.atan2(X/Y)) if ( x > fx ) and ( y > fy ) then angle = 90 - angle elseif ( x > fx ) and ( y < fy ) then angle = 270 + angle elseif ( x < fx ) and ( y > fy ) then angle = 90 + angle elseif ( x < fx ) and ( y < fy ) then angle = 270 - angle setElementRotation( arrestedcriminal, angle ) end end end addEventHandler("onPlayerArrested",getRootElement(),cuffed) Server-side function arrest(arrester,nightstick) if getPlayerTeam(arrester) == getTeamFromName("Police") or getTeamFromName("Speed Enforcement") then if nightstick == 3 then outputChatBox("weapon value correct") if getPlayerWantedLevel(source) > 0 then arrestedcriminal = source if triggerClientEvent(source,"onPlayerArrested",source,source) == true then outputChatBox("clientside event triggered") end end end end end addEventHandler("onPlayerDamage",getRootElement(),arrest) Hey so I wrote this script for after a player being arrested he is forced to follow the police, but it doesn't work. No error is showed, i tried to use outputchatbox to see i found out the server side seems good, please help me Link to comment
Tomas Posted February 11, 2015 Share Posted February 11, 2015 addEvent("onPlayerArrested",true) function cuffed(arrester) arrestedcriminal = source local x,y,z = getElementPosition(arrester) local fx,fy,fz = getElementPosition(arrestedcriminal) local distance = getDistanceBetweenPoints2D(fx,fy,x,y) if distance < 2 then setControlState("forwards", false) setControlState("sprint", false ) setTimer (cuffed, 500, 0, arrester, arrestedcriminal ) return else setControlState("forwards", true) setControlState("sprint", true ) setTimer ( cuffed, 500, 0, arrester, arrestedcriminal ) local X,Y = 0,0 local X = math.abs( x - fx ) local Y = math.abs( y - fy ) local angle = math.deg(math.atan2(X/Y)) if ( x > fx ) and ( y > fy ) then angle = 90 - angle elseif ( x > fx ) and ( y < fy ) then angle = 270 + angle elseif ( x < fx ) and ( y > fy ) then angle = 90 + angle elseif ( x < fx ) and ( y < fy ) then angle = 270 - angle setElementRotation( arrestedcriminal, angle ) end end end addEventHandler("onPlayerArrested",getRootElement(),cuffed) triggerClientEvent(source,"onPlayerArrested",source,arrester) Link to comment
Walid Posted February 12, 2015 Share Posted February 12, 2015 Try this : function followPolice(thecop, theprisoner) if (isPedInVehicle(theprisoner)) then return end local copx, copy, copz = getElementPosition (thecop) local prisonerx, prisonery, prisonerz = getElementPosition (theprisoner) copangle = (360 - math.deg (math.atan2 ((copx - prisonerx), (copy - prisonery)))) % 360 setPedRotation(theprisoner, copangle) setCameraTarget(theprisoner, theprisoner) local dist = getDistanceBetweenPoints2D (copx, copy, prisonerx, prisonery) --Your code here end Link to comment
jingzhi Posted February 12, 2015 Author Share Posted February 12, 2015 addEvent("onPlayerArrested",true) function cuffed(arrester) arrestedcriminal = source local x,y,z = getElementPosition(arrester) local fx,fy,fz = getElementPosition(arrestedcriminal) local distance = getDistanceBetweenPoints2D(fx,fy,x,y) if distance < 2 then setControlState("forwards", false) setControlState("sprint", false ) setTimer (cuffed, 500, 0, arrester, arrestedcriminal ) return else setControlState("forwards", true) setControlState("sprint", true ) setTimer ( cuffed, 500, 0, arrester, arrestedcriminal ) local X,Y = 0,0 local X = math.abs( x - fx ) local Y = math.abs( y - fy ) local angle = math.deg(math.atan2(X/Y)) if ( x > fx ) and ( y > fy ) then angle = 90 - angle elseif ( x > fx ) and ( y < fy ) then angle = 270 + angle elseif ( x < fx ) and ( y > fy ) then angle = 90 + angle elseif ( x < fx ) and ( y < fy ) then angle = 270 - angle setElementRotation( arrestedcriminal, angle ) end end end addEventHandler("onPlayerArrested",getRootElement(),cuffed) triggerClientEvent(source,"onPlayerArrested",source,arrester) TY for answering but still not working Link to comment
jingzhi Posted February 12, 2015 Author Share Posted February 12, 2015 Try this : function followPolice(thecop, theprisoner) if (isPedInVehicle(theprisoner)) then return end local copx, copy, copz = getElementPosition (thecop) local prisonerx, prisonery, prisonerz = getElementPosition (theprisoner) copangle = (360 - math.deg (math.atan2 ((copx - prisonerx), (copy - prisonery)))) % 360 setPedRotation(theprisoner, copangle) setCameraTarget(theprisoner, theprisoner) local dist = getDistanceBetweenPoints2D (copx, copy, prisonerx, prisonery) --Your code here end addEvent("onPlayerArrested",true) function cuffed(arrester,source) if (isPedInVehicle(source)) then return end local copx, copy, copz = getElementPosition (arrester) local prisonerx, prisonery, prisonerz = getElementPosition (source) copangle = (360 - math.deg (math.atan2 ((copx - prisonerx), (copy - prisonery)))) % 360 setPedRotation(theprisoner, copangle) setCameraTarget(theprisoner, theprisoner) local dist = getDistanceBetweenPoints2D (copx, copy, prisonerx, prisonery) if dist < 2 then setControlState("forwards", false) setControlState("sprint", false ) setTimer (cuffed, 500, 0, arrester, arrestedcriminal ) else setControlState("forwards", true) setControlState("sprint", true ) setTimer ( cuffed, 500, 0, arrester, arrestedcriminal ) end end addEventHandler("onPlayerArrested",getRootElement(),cuffed) I did it like this, but its still not working , by the way what is %360 ? Link to comment
Moderators IIYAMA Posted February 12, 2015 Moderators Share Posted February 12, 2015 function cuffed(arrester,source) function cuffed(arrester) Never define a source variable as a parameter. 11 % 10 = 1 21 % 10 = 1 55 % 10 = 5 53673465 % 10 = 5 390 % 360 = 30 721 % 360 = 1 Rest value = % Link to comment
jingzhi Posted February 13, 2015 Author Share Posted February 13, 2015 function cuffed(arrester,source) function cuffed(arrester) Never define a source variable as a parameter. 11 % 10 = 1 21 % 10 = 1 55 % 10 = 5 53673465 % 10 = 5 390 % 360 = 30 721 % 360 = 1 Rest value = % Hey but in this case "source" is not really the source but is a parameter i passed down by "triggerClientEvent()", and also will what will 30 % 360 give me and -30 % 360 give me? thanks for help Link to comment
crismar Posted February 13, 2015 Share Posted February 13, 2015 30 % 360 = 30. You still didn't understand: % = get the rest of the division. It's actually called 'modulo'. 30 % 360 = 30 because 360 > 30, that means the rest is the actual divided number. For your understanding: 721 % 360 = 1. Why ? 721 / 360 = 2, rest = 1 => 721 = 360 * 2 + 1. These are all basic mathematical operators. You should have had a basic understanding about it before even touching Lua. Link to comment
Moderators IIYAMA Posted February 13, 2015 Moderators Share Posted February 13, 2015 Hey but in this case "source" is not really the source but is a parameter i passed down by "triggerClientEvent()", It is automatic defined, so don't have to write it down as parameter, or you will overwrite the source variable which will becomes useless. triggerClientEvent( source, -- = sending to "onPlayerArrested", -- event source, -- = source arrester, -- = first parameter whatEver, -- = second parameter whatEver2 -- = third parameter ----------------------------------------------------------------------------------------------------------- triggerClientEvent(source,"onPlayerArrested",source,arrester,whatEver,whatEver2) > addEvent("onPlayerArrested",true) function cuffed(arrester,whatEver,whatEver2) local mySource = source end addEventHandler("onPlayerArrested",getRootElement(),cuffed) 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