LiOneLMeSsIShoT Posted November 30, 2013 Posted November 30, 2013 In this script no errors...whatever the ped don't even move forward and follows me. server: function follow (thePlayer) local x, y, z = getElementPosition(thePlayer) local guard = createPed (240, x, y, z) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if dis > 2 then setElementData (guard, "Move!", guard) triggerClientEvent (thePlayer, "moveGuard", guard) else setElementData (guard, "Stop!", guard) triggerClientEvent (thePlayer, "stopGuard", guard) end 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 moveGuard() getElementData (source, "Move!", guard) setPedControlState (source, "forwards", true) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function stopGuard () getElementData (source, "Stop!", guard) setPedControlState (source, "forwards", false) end addEvent("stopGuard", true) addEventHandler ("stopGuard", getRootElement(), stopGuard)
LiOneLMeSsIShoT Posted November 30, 2013 Author Posted November 30, 2013 Your code doesn't really make much sense. why?
LiOneLMeSsIShoT Posted December 1, 2013 Author Posted December 1, 2013 Your code doesn't really make much sense. what's not giving sense in the script?
Castillo Posted December 1, 2013 Posted December 1, 2013 Well, to begin with, you're using getElementData, but you're not defining it, which means you're getting it for nothing.
LiOneLMeSsIShoT Posted December 1, 2013 Author Posted December 1, 2013 Well, to begin with, you're using getElementData, but you're not defining it, which means you're getting it for nothing. whatever when i remove it .. the ped don't even follow me or move forward too !!!!
Chronic Posted December 1, 2013 Posted December 1, 2013 In this script no errors...whatever the ped don't even move forward and follows me. setPedControlState (source, "forwards", true) source is not a ped.
LiOneLMeSsIShoT Posted December 1, 2013 Author Posted December 1, 2013 In this script no errors...whatever the ped don't even move forward and follows me. setPedControlState (source, "forwards", true) source is not a ped. yeah but the ped not defined in the client side..so ?
Chronic Posted December 1, 2013 Posted December 1, 2013 In this script no errors...whatever the ped don't even move forward and follows me. setPedControlState (source, "forwards", true) source is not a ped. yeah but the ped not defined in the client side..so ? So... if it's not defined how do you expect it to work?
LiOneLMeSsIShoT Posted December 1, 2013 Author Posted December 1, 2013 alright...should i createPed in clientside too? or what should i do ?
LiOneLMeSsIShoT Posted March 14, 2014 Author Posted March 14, 2014 alright...should i createPed in clientside too? or what should i do ? so help please?
JR10 Posted March 14, 2014 Posted March 14, 2014 Actually, source should be the ped since he's triggering the event with the ped as the sourceElement. As for the code, it's totally messed up. You have the findRotation server-side which should be client-side. You need to use onClientRender, findRotation and set the control state.
LiOneLMeSsIShoT Posted March 14, 2014 Author Posted March 14, 2014 Actually, source should be the ped since he's triggering the event with the ped as the sourceElement.As for the code, it's totally messed up. You have the findRotation server-side which should be client-side. You need to use onClientRender, findRotation and set the control state. could you help me to do this?
JR10 Posted March 14, 2014 Posted March 14, 2014 Not tested. Server: function follow (thePlayer) local x, y, z = getElementPosition(thePlayer) local guard = createPed (240, x + 2, y, z + 1) triggerClientEvent(thePlayer, 'moveGuard', guard) end addCommandHandler ("guard", follow) Client: local guard function moveGuard() guard = source addEventHandler('onClientPreRender', root, followPlayer) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end 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
LiOneLMeSsIShoT Posted March 14, 2014 Author Posted March 14, 2014 Not tested.Server: function follow (thePlayer) local x, y, z = getElementPosition(thePlayer) local guard = createPed (240, x + 2, y, z + 1) triggerClientEvent(thePlayer, 'moveGuard', guard) end addCommandHandler ("guard", follow) Client: local guard function moveGuard() guard = source addEventHandler('onClientPreRender', root, followPlayer) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end 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 Actually worked Nice! You're Good! Thanks, but there's problem here, when i enter Interior or i be already in interior and do /guard the ped dissapear , could you help me with that please?
JR10 Posted March 14, 2014 Posted March 14, 2014 Client: local guard function moveGuard() guard = source addEventHandler('onClientPreRender', root, followPlayer) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end 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 Server is the same.
LiOneLMeSsIShoT Posted March 14, 2014 Author Posted March 14, 2014 Client: local guard function moveGuard() guard = source addEventHandler('onClientPreRender', root, followPlayer) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end 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 Server is the same. Error: Client: Line 5 addEventHandler 'onClientPreRender' with this function is already handled
LiOneLMeSsIShoT Posted March 14, 2014 Author Posted March 14, 2014 Client: local guard function moveGuard() guard = source addEventHandler('onClientPreRender', root, followPlayer) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end 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 Server is the same. Error: Client: Line 5 addEventHandler 'onClientPreRender' with this function is already handled This Problem happen when i spawn more than one guard, and only one guard follows me.
JR10 Posted March 14, 2014 Posted March 14, 2014 Try this, client: local guards = {} function moveGuard() table.insert(guards, source) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, index) else local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end end end end addEventHandler('onClientPreRender', root, followPlayer) 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
LiOneLMeSsIShoT Posted March 14, 2014 Author Posted March 14, 2014 Try this, client: local guards = {} function moveGuard() table.insert(guards, source) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, index) else local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end end end end addEventHandler('onClientPreRender', root, followPlayer) 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 Aha Worked man but it's possible to make them hit zombies near them by weapons or hands? and protect you if someone just shot you? please help me with that ! ! ! and makes them jump if they're stucked and run fast if they're away from you .. I'm sorry for this long things but i'm really need help with them and , THANKS A Lot man
LiOneLMeSsIShoT Posted March 14, 2014 Author Posted March 14, 2014 Try this, client: local guards = {} function moveGuard() table.insert(guards, source) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, index) else local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end end end end addEventHandler('onClientPreRender', root, followPlayer) 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 Aha Worked man but it's possible to make them hit zombies near them by weapons or hands? and protect you if someone just shot you? please help me with that ! ! ! and makes them jump if they're stucked and run fast if they're away from you .. I'm sorry for this long things but i'm really need help with them and , THANKS A Lot man So man ?
JR10 Posted March 14, 2014 Posted March 14, 2014 No man will help you with that. Your best option is to learn, you can take a look at the zombies resource.
LiOneLMeSsIShoT Posted March 14, 2014 Author Posted March 14, 2014 No man will help you with that. Your best option is to learn, you can take a look at the zombies resource. Alright can you tell me how to defined a owner for the guard? like when i do /guard the guard be mine so i can edit things for him.
JR10 Posted March 14, 2014 Posted March 14, 2014 Use element data or tables. setElementData(thePlayer, 'guard', guard)
LiOneLMeSsIShoT Posted March 15, 2014 Author Posted March 15, 2014 Use element data or tables. setElementData(thePlayer, 'guard', guard) I'm sorry but still don't understand it's like this?: I've made this for example and want to know something: function follow (thePlayer) local x, y, z = getElementPosition(thePlayer) local guard = createPed (240, x + 2, y, z + 1) triggerClientEvent(thePlayer, 'moveGuard', guard) setElementData (thePlayer,"guard", guard) end addCommandHandler ("guard", follow) function Example () if not getElementData (source, "guard", guard) then outputChatBox ("You have no Guard") else giveWeapon (guard, 30, 200) end addCommandHandler ("ArmGuard", Example so the gun will be added to all guards with the players and i need every guard with people that have own things, not all guards have the same things when player write /ArmGuard ...please can you help me with that?
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