ronaldoguedess Posted October 22, 2013 Posted October 22, 2013 I have a problem and can not find the solution, I have a client that calls SetTimer in this function server side. The "createZombiePlayer" creates the zombie! But I can not get the variable collision (pedCol), I used the above function! Simplified the code to better understand! function createZombiePlayer(x, y, z) local zombie = createPed ( 70 ),x, y,z, math.random(0, 360)) local Zx, Zy, Zz = getElementPosition( zombie ) local pedCol = createColSphere(Zx, Zy, Zz, 1.5) attachElements(pedCol, zombie, 0, 0, 0) end addEvent("createZombiePlayer", true) addEventHandler("createZomieForPlayer", getRootElement(), createZombiePlayer) function hitCol (player) outputChatBox ( "Hit", player, 255, 255, 0, true ) end addEventHandler("onColShapeHit", pedCol, hitCol) The error is on the line 6 of function "hitCol" ERROR CONSOLE: Bad argument @ ´addEventHandler´ [Expected element at argument 2, got nil] Is there any way I can get the value of (Variable pedCol) I used the above function? NOTE: The two functions in this same file!
Sora Posted October 22, 2013 Posted October 22, 2013 you've error in your createPed code at line 2 you've closed the function bow and left arguments outside the bow function createZombiePlayer(x, y, z) local zombie = createPed (70, x, y , z, math.random(0, 360)) -- it was createPed ( 70 ),x, y,z, math.random(0, 360)) local Zx, Zy, Zz = getElementPosition( zombie ) local pedCol = createColSphere(Zx, Zy, Zz, 1.5) attachElements(pedCol, zombie, 0, 0, 0) end addEvent("createZombiePlayer", true) addEventHandler("createZomieForPlayer", getRootElement(), createZombiePlayer)
TAPL Posted October 22, 2013 Posted October 22, 2013 function createZombiePlayer(x, y, z) local zombie = createPed(70, x, y , z, math.random(0, 360)) local Zx, Zy, Zz = getElementPosition(zombie) local pedCol = createColSphere(Zx, Zy, Zz, 1.5) addEventHandler("onColShapeHit", pedCol, hitCol) attachElements(pedCol, zombie, 0, 0, 0) end addEvent("createZombiePlayer", true) addEventHandler("createZomieForPlayer", getRootElement(), createZombiePlayer) function hitCol(player) if getElementType(player) == "player" then outputChatBox("Hit", player, 255, 255, 0, true) end end
ronaldoguedess Posted October 23, 2013 Author Posted October 23, 2013 you've error in your createPed code at line 2 you've closed the function bow and left arguments outside the bow In the original script has no error, which is a simplification made to understand better, but I ended up erring. hehe Thanks for correcting! function createZombiePlayer(x, y, z) local zombie = createPed(70, x, y , z, math.random(0, 360)) local Zx, Zy, Zz = getElementPosition(zombie) local pedCol = createColSphere(Zx, Zy, Zz, 1.5) addEventHandler("onColShapeHit", pedCol, hitCol) attachElements(pedCol, zombie, 0, 0, 0) end addEvent("createZombiePlayer", true) addEventHandler("createZomieForPlayer", getRootElement(), createZombiePlayer) function hitCol(player) if getElementType(player) == "player" then outputChatBox("Hit", player, 255, 255, 0, true) end end Thank TAPL, worked perfectly. I did not know you could by a "addEvent" inside a function! I came across another problem! The problem is that I can not delete the (pedCol) we use the function "createZombiePlayer". Is there any way I can delete it when the ped is killed using the "onPedWasted"? NOTE: This Code is in the same "file server" what has been fixed! function deanimated( ammo, attacker, weapon, bodypart ) if (getElementData (source, "zombie") == true) then zombiesalive = zombiesalive - 1 outputChatBox ( "Zombi Died!", player, 0, 238, 0, true ) setElementData ( source, "status", "dead" ) destroyElement(pedCol) -- BUG end end addEventHandler("onPedWasted", getRootElement(), deanimated) ERROR CONSOLE: Bad argument @ ´destroyElement´ [Expected element at argument 1, got nil]
TAPL Posted October 23, 2013 Posted October 23, 2013 zombieCol = {} function createZombiePlayer(x, y, z) local zombie = createPed(70, x, y , z, math.random(0, 360)) local Zx, Zy, Zz = getElementPosition(zombie) zombieCol[zombie] = createColSphere(Zx, Zy, Zz, 1.5) addEventHandler("onColShapeHit", pedCol, hitCol) attachElements(pedCol, zombie, 0, 0, 0) end addEvent("createZombiePlayer", true) addEventHandler("createZomieForPlayer", getRootElement(), createZombiePlayer) function hitCol(player) if getElementType(player) == "player" then outputChatBox("Hit", player, 255, 255, 0, true) end end function deanimated(ammo, attacker, weapon, bodypart) if getElementData(source, "zombie") then zombiesalive = zombiesalive - 1 outputChatBox("Zombi Died!", player, 0, 238, 0, true) -- is player defined anywhere? setElementData(source, "status", "dead") if isElement(zombieCol[source]) then destroyElement(zombieCol[source]) end zombieCol[source] = nil end end addEventHandler("onPedWasted", getRootElement(), deanimated)
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