Jump to content

[HELP] Script Error.


Recommended Posts

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) 

Link to comment

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.

Link to comment
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

Link to comment

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) 

Link to comment
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)  

Link to comment
"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) 

Link to comment
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)  

Link to comment
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' 

Link to comment
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) 

so?

Link to comment

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) 

Link to comment

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 :P

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...