Jump to content

zombie rotation corruption


Recommended Posts

Posted (edited)

hello when the zombie amount is 100 or above, when I attack the zombie, the rotation corruption occurs as in the picture.

function findRotation(x1, y1, x2, y2) 
    local t = -math.deg(math.atan2(x2 - x1, y2 - y1 ))
    return t < 0 and t + 360 or t
end

local zSkins = {13,22,56,67,68,69,70,92,97,105,107,108,126,127,128,152,162,167,188,195,206,209,212,229,230,258,264,277,280,287}
local zombies = {}
local zombieDatas = {}
local behaviourUpdater

function createZombie(posX, posY, posZ, targetPlayer, typeZombie)
   local randomSkin = math.random(1, #zSkins)
   local theZombie = createPed(randomSkin, posX, posY, posZ)
   if(typeZombie == "green") then
   	  local randomWalkstyle = math.random(1, 2)
   	  
   	  if(randomWalkstyle == 1) then
         randomWalkstyle = "walk_old"
        elseif(randomWalkstyle == 2) then
      	 randomWalkstyle = "run_old"
   	  end
      zombieDatas[theZombie] = {TypeZombie = "green", Walkstyle = randomWalkstyle, State = "idle", Target = targetPlayer}
      table.insert(zombies, theZombie)
      outputDebugString("Zombie Type: "..zombieDatas[theZombie].TypeZombie)
      outputDebugString("Zombie Walkstyle: "..zombieDatas[theZombie].Walkstyle)
      outputDebugString("State: "..zombieDatas[theZombie].State)
      outputDebugString("Target: "..getElementType(zombieDatas[theZombie].Target))
      return theZombie
   end

end

function removeZombie(theZombie)
   if(isElement(theZombie)) then
      if(zombieDatas[theZombie].TypeZombie ~= nil) then
         zombieDatas[theZombie] = nil
         for k,_ in pairs(zombies) do
            if(theZombie == zombies[k]) then
               destroyElement(zombies[k])
               zombies[k] = nil
               break
            end
         end
      end
   end
end

addCommandHandler("removezombie",function()
   for k,v in pairs(zombies) do
      removeZombie(zombies[k])
   end
end)

addCommandHandler("createzomb", function(player)
   for i=1,10 do
      local x,y,z = getElementPosition(player)
      createZombie(x, y +1, z, player, "green")
   end 
end)

function zombieBehaviour()
   for i=1,#zombies do
       -- face toward zombie to player
      if(zombieDatas[zombies[i]].Target ~= nil) then
         if(isElement(zombies[i])) then
         local zombieX, zombieY, zombieZ = getElementPosition(zombies[i])
         local playerX, playerY, playerZ = getElementPosition(zombieDatas[zombies[i]].Target)
         setElementRotation (zombies[i], zombieX, zombieY, findRotation(zombieX, zombieY, playerX, playerY), "default", true)
         end
      end
   end
end
behaviourUpdater = setTimer(zombieBehaviour, 130, 0)

Ads-z.png

Red marked peds have a broken rotation while others are facing the player I did not see this error on the client side, it happens on the server side

Edited by Burak5312
Link to post
Posted (edited)
6 minutes ago, Tekken said:

Have you tried conformPedRotation = true

https://wiki.multitheftauto.com/wiki/SetElementRotation

not sure but worth giving a try

yes I tried it, but the result has not changed. The interesting thing is that this error does not occur on the client side. I don't know what the error is caused by, but there is something on the server side. or I'm doing something wrong

Edited by Burak5312
Link to post
Posted (edited)
23 minutes ago, Tekken said:

Try checking if target is element rather than checking if target is different then nil

sadly no change

Edited by Burak5312
Link to post
Posted (edited)

 

I simplified the code but it still makes the same error

function findRotation(x1, y1, x2, y2) 
    local t = -math.deg(math.atan2(x2 - x1, y2 - y1 ))
    return t < 0 and t + 360 or t
end

local zSkins = {13,22,56,67,68,69,70,92,97,105,107,108,126,127,128,152,162,167,188,195,206,209,212,229,230,258,264,277,280,287}
local zombies = {}
local zombieDatas = {}
local behaviourUpdater

local theZombie = createPed(0, 0, 0, 4)
local theTarget = getPlayerFromName("Burak2346")

function zombieBehaviour()
   local zombieX, zombieY, zombieZ = getElementPosition(theZombie)
   local playerX, playerY, playerZ = getElementPosition(theTarget)
   setElementRotation (theZombie, zombieX, zombieY, findRotation(zombieX, zombieY, playerX, playerY), "default", true)
end
behaviourUpdater = setTimer(zombieBehaviour, 130, 0)

 

Ads-z.png

 

I'm sure there is something on the server side peds

Edited by Burak5312
Link to post
Posted (edited)

I just tested both the full and the simplified scripts and they work as expected.

So maybe there is another script which also sets the rotation of peds on your server?
I don't know what exactly could be but it's not from the script (if this helps at all).

Jb0Tkpz.png

Edited by SpecT
Link to post
Posted (edited)

The problem is that if you hit the peds with a fist from the face, the rotation will break down at some point, I know it will work fine you can try it it. is not possible for scripts to mix because I only run this script, all other scripts are default scripts

Edited by Burak5312
Link to post
7 minutes ago, Burak5312 said:

The problem is that if you hit the peds with a fist from the face, the rotation will break down at some point, I know it will work fine if you don't do anything, you can try it it. is not possible for scripts to mix because I only run this script, all other scripts are default scripts

The thing is I tried a lot of stuff (hitting, shooting) to them.
They keep rotating even while dead and laying on the ground.
I increased the loop for ped spawning to 100 to make sure it won't break with more peds.

And in the end they all keep rotating to me with no exclusion.

  • Like 1
Link to post
15 minutes ago, SpecT said:

The thing is I tried a lot of stuff (hitting, shooting) to them.
They keep rotating even while dead and laying on the ground.
I increased the loop for ped spawning to 100 to make sure it won't break with more peds.

And in the end they all keep rotating to me with no exclusion.

 

Let me take a video of this

Link to post
Posted (edited)
57 minutes ago, Tekken said:

Try 0 as x and y rotation as for now you set the actual x and y positions 

 

hello, I tried your solution but it didn't work, instead I transferred the rotation finder codes to the client side and ran it with triggerClientEvent on the server side, no problems at the moment. works interestingly

server

function zombieBehaviour()
   for i=1,#zombies do
       -- face toward zombie to player
      if(zombieDatas[zombies[i]].Target ~= nil) then
         if(isElement(zombies[i])) then
            triggerClientEvent(root, "faceTowardZombie", zombies[i], zombies[i], zombieDatas[zombies[i]].Target)
         end
      end
   end
end
behaviourUpdater = setTimer(zombieBehaviour, 130, 0)

client

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

addEvent("faceTowardZombie", true)
addEventHandler("faceTowardZombie", root,
    function(theZombie, theTarget)
       local zombieX, zombieY, zombieZ = getElementPosition(theZombie)
       local playerX, playerY, playerZ = getElementPosition(theTarget)
       local rotX, rotY, rotZ = getElementRotation(theZombie, "default")     
       setElementRotation(theZombie, rotX, rotY, findRotation(zombieX, zombieY, playerX, playerY), "default", true)
    end
)

I think I'll have to rewrite these script, thank you for your answers.

Edited by Burak5312
Link to post
  • Moderators
9 hours ago, Burak5312 said:

I think I'll have to rewrite these script

I am also using triggerClientEvent for the rotations.

But not because of this issue, it is more for combining all AI instructions in to 1 packet and therefore reducing data. While rewriting your code, you might take that concept in consideration.

 

  • Like 1
Link to post
Posted (edited)
2 hours ago, IIYAMA said:

I am also using triggerClientEvent for the rotations.

But not because of this issue, it is more for combining all AI instructions in to 1 packet and therefore reducing data. While rewriting your code, you might take that concept in consideration.

 

thank you yes i thought of doing that too

Edited by Burak5312
  • Like 1
Link to post

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...