LiOneLMeSsIShoT Posted November 26, 2013 Posted November 26, 2013 i've made a script which make the ped follows the player but the ped don't even move..and no errors..please check this server: function follow (thePlayer) local x1,y1,z1 = getElementPosition (thePlayer) local guard = createPed (240, x1, y1, z1) local x2,y2,z2 = getElementPosition (guard) local distance = getDistanceBetweenPoints2D (x1, y1, x2, y2) if distance >= 2 then triggerClientEvent (thePlayer, "moveGuard", guard) end end addCommandHandler ("guard", follow) client: function me () setPedControlState (guard, "forwards", true) end addEvent ("moveGuard", true) addEventHandler ("moveGuard", getRootElement(), me)
LiOneLMeSsIShoT Posted November 26, 2013 Author Posted November 26, 2013 This make no sense. why makes no sense? i triggerd client event because setPedControlState is Client side .
tosfera Posted November 26, 2013 Posted November 26, 2013 setPedControlState (guard, "forwards", true), where did you define 'guard'...
TAPL Posted November 26, 2013 Posted November 26, 2013 The trigger will never occur, why? Because you created the ped at same position of your that mean the distance between you and the ped will be 0 so line 6 will not be achieved and you don't have any timer to repeat the checker this mean your code will stop at line 5.
LiOneLMeSsIShoT Posted November 26, 2013 Author Posted November 26, 2013 The trigger will never occur, why?Because you created the ped at same position of your that mean the distance between you and the ped will be 0 so line 6 will not be achieved and you don't have any timer to repeat the checker this mean your code will stop at line 5. Actually removed lines 4, 5, 6 i've edited the script now and it works. with the ped moves forward..but not follows me..check this server: function follow (thePlayer) local x1,y1,z1 = getElementPosition (thePlayer) local guard = createPed (240, x1, y1, z1) local x2,y2,z2 = getElementRotation (guard) triggerClientEvent (thePlayer, "moveGuard", guard) setElementRotation(guard,x1, y1, x2, y2) end addCommandHandler ("guard", follow) client: function me () setPedControlState (source, "forwards", true) end addEvent ("moveGuard", true) addEventHandler ("moveGuard", getRootElement(), me) no errors
LiOneLMeSsIShoT Posted November 26, 2013 Author Posted November 26, 2013 Alright..!! Edited it but still not follows me and no errors! the ped move Forward only server: function follow (thePlayer) local x,y,z = getElementPosition (thePlayer) local guard = createPed (240, x, y, z) local tx,ty,tz = getElementPosition (guard) triggerClientEvent (thePlayer, "moveGuard", guard) setPedRotation(guard, findRotation(tx, ty, x, y)) end addCommandHandler ("guard", follow) 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 client: function me () setPedControlState (source, "forwards", true) end addEvent ("moveGuard", true) addEventHandler ("moveGuard", getRootElement(), me)
LiOneLMeSsIShoT Posted November 26, 2013 Author Posted November 26, 2013 You must setPedLookAt in order to move it server: function follow (thePlayer) local x,y,z = getElementPosition (thePlayer) local guard = createPed (240, x, y, z) triggerClientEvent (thePlayer, "moveGuard", guard) setPedLookAt (guard, x, y, z) end addCommandHandler ("guard", follow) client: function me () setPedControlState (source, "forwards", true) end addEvent ("moveGuard", true) addEventHandler ("moveGuard", getRootElement(), me) Still not follows me and error: attempt to call global 'setPedLookAt' (a nil value)
bandi94 Posted November 26, 2013 Posted November 26, 2013 "setPedLookAt" - is client side and not server side.
LiOneLMeSsIShoT Posted November 26, 2013 Author Posted November 26, 2013 "setPedLookAt" - is client side and not server side. yeah yeah...now see...not work too... server: function follow (thePlayer) local x,y,z = getElementPosition (thePlayer) local guard = createPed (240, x, y, z) triggerClientEvent (thePlayer, "moveGuard", guard) end addCommandHandler ("guard", follow) client: function me () setPedControlState (source, "forwards", true) setPedLookAt (source, getElementPosition(localPlayer)) end addEvent ("moveGuard", true) addEventHandler ("moveGuard", getRootElement(), me)
bandi94 Posted November 26, 2013 Posted November 26, 2013 function follow (thePlayer) local x,y,z = getElementPosition (thePlayer) local guard = createPed (240, x, y, z) setElementData(thePlayer,"guard",guard) triggerClientEvent (thePlayer, "moveGuard", guard) end addCommandHandler ("guard", follow) function Look () if not getElementData(localPlayer,"guard") then return end setPedLookAt (getElementData(localPlayer,"guard"), getElementPosition(localPlayer)) end addEventHandler ("onClientRender", getRootElement(), Look) function SetC(guard) setPedControlState (guard, "forwards", true) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), SetC)
LiOneLMeSsIShoT Posted November 26, 2013 Author Posted November 26, 2013 function follow (thePlayer) local x,y,z = getElementPosition (thePlayer) local guard = createPed (240, x, y, z) setElementData(thePlayer,"guard",guard) triggerClientEvent (thePlayer, "moveGuard", guard) end addCommandHandler ("guard", follow) function Look () if not getElementData(localPlayer,"guard") then return end setPedLookAt (getElementData(localPlayer,"guard"), getElementPosition(localPlayer)) end addEventHandler ("onClientRender", getRootElement(), Look) function SetC(guard) setPedControlState (guard, "forwards", true) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), SetC) Bad argument @ 'setPedControlState'
LiOneLMeSsIShoT Posted November 26, 2013 Author Posted November 26, 2013 i've made a script which make the ped follows the player but the ped don't even move..and no errors..please check thisserver: function follow (thePlayer) local x1,y1,z1 = getElementPosition (thePlayer) local guard = createPed (240, x1, y1, z1) local x2,y2,z2 = getElementPosition (guard) local distance = getDistanceBetweenPoints2D (x1, y1, x2, y2) if distance >= 2 then triggerClientEvent (thePlayer, "moveGuard", guard) end end addCommandHandler ("guard", follow) client: function me () setPedControlState (guard, "forwards", true) end addEvent ("moveGuard", true) addEventHandler ("moveGuard", getRootElement(), me) so?
Renkon Posted November 26, 2013 Posted November 26, 2013 Check setPedLookAt arguments... second argument is not an element
Dealman Posted November 26, 2013 Posted November 26, 2013 Guard should be returning nil on your client, and as such, you should be getting an error message - and provide us with this information to make it easier for us to help you. What you've done wrong here is that you forgot to actually 'retrieve' the data that was sent via the triggerClientEvent. function me (theGuard) setPedControlState (theGuard, "forwards", true) end addEvent ("moveGuard", true) addEventHandler ("moveGuard", getRootElement(), me)
LiOneLMeSsIShoT Posted November 26, 2013 Author Posted November 26, 2013 Check setPedLookAt arguments... second argument is not an element Alright so what sohuld i do on this.
LiOneLMeSsIShoT Posted November 26, 2013 Author Posted November 26, 2013 This make no sense. C'mon man Please check this
Renkon Posted November 26, 2013 Posted November 26, 2013 Check setPedLookAt arguments... second argument is not an element Alright so what sohuld i do on this. check the fucking wiki
LiOneLMeSsIShoT Posted November 26, 2013 Author Posted November 26, 2013 Check setPedLookAt arguments... second argument is not an element Alright so what sohuld i do on this. check the wiki Check the wiki? can you help me with fixing the script man???
Dealman Posted November 26, 2013 Posted November 26, 2013 The code I posted above is retrieving the data. Look at how I added "theGuard" to the function arguments. You can name this whatever you want. "guard" sent via triggerClientEvent will be stored in "theGuard" client-side. Check the wiki? can you help me with fixing the script man??? If you can't take the time to thoroughly read the MTA Wiki about the functions and how they work, then I won't take the time to help you. Even though I already did
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