LiOneLMeSsIShoT Posted March 15, 2014 Share Posted March 15, 2014 (edited) Well i have 2 Problems in the script: 1- When i /weapon to give weapon to 2 guards only one of them take the weapon and i want the weapon be gaven to the 2 guards when i type /weapon /weapon 2 times, guards = {} function followPed (thePlayer) local x, y, z = getElementPosition(thePlayer) guard = createPed (240, x + 2, y, z + 1) triggerClientEvent(thePlayer, 'moveGuard', guard) guards[thePlayer] = guard end addCommandHandler ("guard", followPed) function giveGun (source) if not isElement(guards[source]) then outputChatBox ("You have no Guard") else giveWeapon (guards[source], 30, 200, true) end end addCommandHandler ("weapon", giveGun) function returnTable() return guards end addEvent("returnTable", true) addEventHandler("returnTable", getRootElement(), returnTable) 2- The second problem is in function returnTable, because it made to make the owner of the ped are not able to hurt his ped. Client: function cancelPedDamage ( attacker ) local guardsrecieved = triggerServerEvent("returnTable", attacker) if (guardsrecieved[attacker][1] == source) then cancelEvent() -- cancel any damage done to peds end end addEventHandler ( "onClientPedDamage", getRootElement(), cancelPedDamage ) Alright now the Error: When i hit my ped i get this Error: attempt to index local 'guardsrecieved' ( a boolean value) And THANKS A LOT ! ! Edited March 18, 2014 by Guest Link to comment
Saml1er Posted March 15, 2014 Share Posted March 15, 2014 Use: guards = { } function gweaponPed() for k,v in ipairs (guards) do giveWeapon (v,30, 200, true) end end function followPed (thePlayer) local x, y, z = getElementPosition(thePlayer) guard = createPed (240, x + 2, y, z + 1) triggerClientEvent(thePlayer, 'moveGuard', guard) guards[thePlayer] = guard end addCommandHandler ("guard", followPed) function giveGun (source) if not isElement(guards[source]) then outputChatBox ("You have no Guard") else gweaponPed () end end addCommandHandler ("weapon", giveGun) and triggerServerEvent will just trigger the server event it will return no data for client aide in other words it just sends data it doesn't send data back to client side. Link to comment
LiOneLMeSsIShoT Posted March 15, 2014 Author Share Posted March 15, 2014 (edited) Use: guards = { } function gweaponPed() for k,v in ipairs (guards) do giveWeapon (v,30, 200, true) end end function followPed (thePlayer) local x, y, z = getElementPosition(thePlayer) guard = createPed (240, x + 2, y, z + 1) triggerClientEvent(thePlayer, 'moveGuard', guard) guards[thePlayer] = guard end addCommandHandler ("guard", followPed) function giveGun (source) if not isElement(guards[source]) then outputChatBox ("You have no Guard") else gweaponPed () end end addCommandHandler ("weapon", giveGun) and triggerServerEvent will just trigger the server event it will return no data for client aide in other words it just sends data it doesn't send data back to client side. ِAlright well so if you have an idea about "if the owner hit his guard, the guard will not die or lose hp" have any idea? please i need help + This you've edited Dosen't work when i do /weapon it even don't give weapon Edited March 15, 2014 by Guest Link to comment
JR10 Posted March 15, 2014 Share Posted March 15, 2014 (edited) For your first problem: guards = {} function followPed (thePlayer) local x, y, z = getElementPosition(thePlayer) guard = createPed (240, x + 2, y, z + 1) triggerClientEvent(thePlayer, 'moveGuard', guard) if (not guards[thePlayer]) then guards[thePlayer] = {} end table.insert(guards[thePlayer], guard) end addCommandHandler ("guard", followPed) function giveGun (source) if (not guards[source]) then return end if not isElement(guards[source][1]) then outputChatBox ("You have no Guard") else for i, v in pairs(guards[source]) do giveWeapon (v, 30, 200, true) end end end addCommandHandler ("weapon", giveGun) function returnTable() return guards end addEvent("returnTable", true) addEventHandler("returnTable", getRootElement(), returnTable) A better approach to your second problem is this, the client that I've taken from your other topic: local guards = {} function moveGuard() table.insert(guards, source) addEventHandler('onClientPedDamage', source, function(attacker) if attacker == localPlayer then cancelEvent() end end) 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 Edited March 15, 2014 by Guest Link to comment
LiOneLMeSsIShoT Posted March 15, 2014 Author Share Posted March 15, 2014 For your first problem: guards = {} function followPed (thePlayer) local x, y, z = getElementPosition(thePlayer) guard = createPed (240, x + 2, y, z + 1) triggerClientEvent(thePlayer, 'moveGuard', guard) if (not guards[thePlayer]) then guards[thePlayer] = {} end table.insert(guards[thePlayer], guard) end addCommandHandler ("guard", followPed) function giveGun (source) if (not guards[source]) then return end if not isElement(guards[source][1]) then outputChatBox ("You have no Guard") else for i, v in pairs(guards[source]) do giveWeapon (v, 30, 200, true) end end end addCommandHandler ("weapon", giveGun) function returnTable() return guards end addEvent("returnTable", true) addEventHandler("returnTable", getRootElement(), returnTable) A better approach to your second problem is this, the client that I've taken from your other topic: local guards = {} function moveGuard() table.insert(guards, source) addEventHandler('onClientPedDamage', source, cancelEvent) 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 Wait a second please, I've edited the client to make the ped sprint when he's away and edited somethings, so can you check it: 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 if (dis > 4) then setPedControlState(guard, 'sprint', true) else setPedControlState(guard, 'sprint', 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 function cancelPedDamage ( attacker ) local guardsrecieved = triggerServerEvent("returnTable", attacker) if (guardsrecieved[attacker][1] == source) then cancelEvent() -- cancel any damage done to peds end end addEventHandler ( "onClientPedDamage", getRootElement(), cancelPedDamage ) SO Could you edit this one? ! ! Also there's 2 tables one in server, one in client one in server to defined peds for owners, but in the client that you made idk why, so the script will work with 2 tables? and the both gives sense or what? Link to comment
JR10 Posted March 15, 2014 Share Posted March 15, 2014 local guards = {} function moveGuard() table.insert(guards, source) addEventHandler('onClientPedDamage', source, function(attacker) if attacker == localPlayer then cancelEvent() end end) 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 if (dis > 4) then setPedControlState(guard, 'sprint', true) else setPedControlState(guard, 'sprint', 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 function cancelPedDamage ( attacker ) local guardsrecieved = triggerServerEvent("returnTable", attacker) if (guardsrecieved[attacker][1] == source) then cancelEvent() -- cancel any damage done to peds end end addEventHandler ( "onClientPedDamage", getRootElement(), cancelPedDamage ) Link to comment
LiOneLMeSsIShoT Posted March 15, 2014 Author Share Posted March 15, 2014 local guards = {} function moveGuard() table.insert(guards, source) addEventHandler('onClientPedDamage', source, function(attacker) if attacker == localPlayer then cancelEvent() end end) 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 if (dis > 4) then setPedControlState(guard, 'sprint', true) else setPedControlState(guard, 'sprint', 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 function cancelPedDamage ( attacker ) local guardsrecieved = triggerServerEvent("returnTable", attacker) if (guardsrecieved[attacker][1] == source) then cancelEvent() -- cancel any damage done to peds end end addEventHandler ( "onClientPedDamage", getRootElement(), cancelPedDamage ) So i don't need this? function cancelPedDamage ( attacker ) local guardsrecieved = triggerServerEvent("returnTable", attacker) if (guardsrecieved[attacker][1] == source) then cancelEvent() -- cancel any damage done to peds end end addEventHandler ( "onClientPedDamage", getRootElement(), cancelPedDamage ) and this? function returnTable() return guards end addEvent("returnTable", true) addEventHandler("returnTable", getRootElement(), returnTable) and also that script you fixed is giving weapons to all peds that spawned in one type "man i want to give the weapons to the peds one by one not in one time because i'm gonna do a gui that sell weapons to the guards so when i click on the gui he wont be able to buy one weapon and give it to all avilable guards he have, i hope you understand me ! Link to comment
JR10 Posted March 15, 2014 Share Posted March 15, 2014 Yes you don't need that. I kinda understand what you want now, but there are several ways your idea could be made. Here's one: guards = {} gotWeapon = {} function followPed (thePlayer) local x, y, z = getElementPosition(thePlayer) guard = createPed (240, x + 2, y, z + 1) triggerClientEvent(thePlayer, 'moveGuard', guard) if (not guards[thePlayer]) then guards[thePlayer] = {} end table.insert(guards[thePlayer], guard) end addCommandHandler ("guard", followPed) function giveGun (source) if (not guards[source]) then return end if not isElement(guards[source][1]) then outputChatBox ("You have no Guard") else for i, v in pairs(guards[source]) do if (not gotWeapon[v]) then giveWeapon (v, 30, 200, true) gotWeapon[v] = true break end end end end addCommandHandler ("weapon", giveGun) function returnTable() return guards end addEvent("returnTable", true) addEventHandler("returnTable", getRootElement(), returnTable) Link to comment
LiOneLMeSsIShoT Posted March 15, 2014 Author Share Posted March 15, 2014 Yes you don't need that.I kinda understand what you want now, but there are several ways your idea could be made. Here's one: guards = {} gotWeapon = {} function followPed (thePlayer) local x, y, z = getElementPosition(thePlayer) guard = createPed (240, x + 2, y, z + 1) triggerClientEvent(thePlayer, 'moveGuard', guard) if (not guards[thePlayer]) then guards[thePlayer] = {} end table.insert(guards[thePlayer], guard) end addCommandHandler ("guard", followPed) function giveGun (source) if (not guards[source]) then return end if not isElement(guards[source][1]) then outputChatBox ("You have no Guard") else for i, v in pairs(guards[source]) do if (not gotWeapon[v]) then giveWeapon (v, 30, 200, true) gotWeapon[v] = true break end end end end addCommandHandler ("weapon", giveGun) function returnTable() return guards end addEvent("returnTable", true) addEventHandler("returnTable", getRootElement(), returnTable) Oh yeah ! ! That's what i'm Talking about man and i've tried it but need you to tell me what should i do now function Example (killer) table.insert (guards, source) if killer == exports ["zombies"]:isPedZombie (source) and isElement (guards[source]) then --- i need now to make the guard hit the zombie...after the zombie just hurted the owner... and if some player hit the owner the guard will shot him too idk how i do it. help addEventHandler ("onClientPlayerDamage",getRootElement(),Example) and also how to check if there's object infront of the ped that make him can't move so he jump to cross it. Link to comment
JR10 Posted March 15, 2014 Share Posted March 15, 2014 I've already gave you the code for it, you need to learn more if you're working on a zombies game-mode. and also how to check if there's object infront of the ped that make him can't move so he jump to cross it. isLineOfSightClear processLineOfSight Link to comment
LiOneLMeSsIShoT Posted March 15, 2014 Author Share Posted March 15, 2014 I've already gave you the code for it, you need to learn more if you're working on a zombies game-mode.and also how to check if there's object infront of the ped that make him can't move so he jump to cross it. isLineOfSightClear processLineOfSight ِAlright man ! but the other problem here : function Example (killer) table.insert (guards, source) if killer == exports ["zombies"]:isPedZombie (source) and isElement (guards[source]) then --- i need now to make the guard hit the zombie...after the zombie just hurted the owner... and if some player hit the owner the guard will shot him too idk how i do it. help addEventHandler ("onClientPlayerDamage",getRootElement(),Example) can you help me with that? Link to comment
LiOneLMeSsIShoT Posted March 15, 2014 Author Share Posted March 15, 2014 I've already gave you the code for it, you need to learn more if you're working on a zombies game-mode.and also how to check if there's object infront of the ped that make him can't move so he jump to cross it. isLineOfSightClear processLineOfSight ِAlright man ! but the other problem here : function Example (killer) table.insert (guards, source) if killer == exports ["zombies"]:isPedZombie (source) and isElement (guards[source]) then --- i need now to make the guard hit the zombie...after the zombie just hurted the owner... and if some player hit the owner the guard will shot him too idk how i do it. help addEventHandler ("onClientPlayerDamage",getRootElement(),Example) can you help me with that? startX: The first point's world X coordinate. startY: The first point's world Y coordinate. startZ: The first point's world Z coordinate. endX: The second point's world X coordinate. endY: The second point's world Y coordinate. endZ: The second point's world Z coordinate. do that endX, endY,endZ means rotations? or what..i don't understand what endX,endY,endZ means. Link to comment
JR10 Posted March 15, 2014 Share Posted March 15, 2014 startX, startY, startZ are the coordinates for the starting point of the line of sight. endX, endY, endZ are the coordinates for the ending point of the line of sight. For your other problem, you're asking too much. Try something yourself and then post for help. Link to comment
LiOneLMeSsIShoT Posted March 15, 2014 Author Share Posted March 15, 2014 (edited) startX, startY, startZ are the coordinates for the starting point of the line of sight. endX, endY, endZ are the coordinates for the ending point of the line of sight.For your other problem, you're asking too much. Try something yourself and then post for help. I'm sorry, but now i have made it by myself but i got error: function Example () table.insert (guards, source) local guard = guards local zombies = exports ["zombies"]:isPedZombie (source) local gx, gy, gz = getElementPosition(guard) -- guards local zx, zy, zz = getElementPosition(zombies) -- zombies local clear = isLineOfSightClear (gx, gy, gz, zx, zy, zz,true, false, false, true, false, false, false) if zombies and isElement (guards[source]) then if clear then setPedControlState( ped, "fire", true ) outputChatBox ("Attack! ") end end end addEventHandler ("onClientPlayerDamage",getRootElement(),Example) Bad argument @ 'isLineOfSightClear' [Expected number at argument 1, got boolean] bad argument @ 'getElementPositon' bad argument @ 'getElementPosition' Edited March 15, 2014 by Guest Link to comment
JR10 Posted March 15, 2014 Share Posted March 15, 2014 isPedZombie returns a boolean value, true or false, not a ped element. Link to comment
LiOneLMeSsIShoT Posted March 15, 2014 Author Share Posted March 15, 2014 isPedZombie returns a boolean value, true or false, not a ped element. so i have to do it true ? Link to comment
LiOneLMeSsIShoT Posted March 15, 2014 Author Share Posted March 15, 2014 isPedZombie returns a boolean value, true or false, not a ped element. so i have to do it true ? did it true but still the same errors: if zombies == true and isElement (guards[source]) then if clear then Link to comment
LiOneLMeSsIShoT Posted March 16, 2014 Author Share Posted March 16, 2014 isPedZombie returns a boolean value, true or false, not a ped element. so i have to do it true ? did it true but still the same errors: if zombies == true and isElement (guards[source]) then if clear then So man/ ? ? Link to comment
JR10 Posted March 16, 2014 Share Posted March 16, 2014 Your code is messed up. zombies resource only has two exported functions: createZombie which returns the ped variable if it was created successfully, and isPedZombie which should be self-explanatory. I've no idea what you're trying to accomplish, but you need to learn more before working on something as advanced as this. Link to comment
LiOneLMeSsIShoT Posted March 16, 2014 Author Share Posted March 16, 2014 Your code is messed up. zombies resource only has two exported functions: createZombie which returns the ped variable if it was created successfully, and isPedZombie which should be self-explanatory. I've no idea what you're trying to accomplish, but you need to learn more before working on something as advanced as this. Man! please, could you check the script once again? it will work when someone hit the player so the guard will hit the guy which hurted the owner...... and i got that errors could you help me with fixing them? And Yep, Zombie system here Exports function that allows me to check if that ped is zombie and proofs here first proof: It's in Zady script second one here: Script: function Example () table.insert (guards, source) local guard = guards local zombies = exports ["zombies"]:isPedZombie (source) local gx, gy, gz = getElementPosition(guard) -- guards local zx, zy, zz = getElementPosition(zombies) -- zombies local clear = isLineOfSightClear (gx, gy, gz, zx, zy, zz,true, false, false, true, false, false, false) if zombies and isElement (guards[source]) then if clear then setPedControlState( ped, "fire", true ) outputChatBox ("Attack! ") end end end addEventHandler ("onClientPlayerDamage",getRootElement(),Example) Exports Function: --check if a ped is a zombie or not function isPedZombie(ped) if (isElement(ped)) then if (getElementData (ped, "zombie") == true) then return true else return false end else return false end end addEvent( "onZombieLostPlayer", true ) Meta Exported: "*MaxZombies" value="[100]" /> --maximum allowed zombies --> "*StreamMethod" value="[1]" /> -- 1 to constantly stream zombies, 0 to only allow zombies to spawn via createZombie function, 2 to only allow spawning at set spawnpoints --> "*Speed" value="[1]" /> -- 0 is slowest, 1 is normal, 2 faster --> "Slothman" name="Zday script" version="3.0.1" type="script" description="Zombie Infestation script" edf:definition="edf/zombies.edf"/>/> Can you help me now with that man? !!!! Link to comment
LiOneLMeSsIShoT Posted March 16, 2014 Author Share Posted March 16, 2014 Help Please ?? Link to comment
LiOneLMeSsIShoT Posted March 17, 2014 Author Share Posted March 17, 2014 Hello? anyone here please? Link to comment
LiOneLMeSsIShoT Posted March 18, 2014 Author Share Posted March 18, 2014 Help please guys? Link to comment
JR10 Posted March 18, 2014 Share Posted March 18, 2014 This is a quickly written example, it's not tested and may not work, if it outputs any errors then post them. local target addEventHandler ("onClientPlayerDamage", localPlayer, function(attacker) if (isElement(attacker) and getElementType(attacker) == 'player' and #guards > 0) then -- He's a player target = attacker addEventHandler('onClientRender', root, aimForTarget) end end) function aimForTarget() if (#guards == 0) then removeEventHandler('onClientRender', root, aimForTarget) return end if (not isElement(target) or isPedDead(target)) then for index, guard in pairs(guards) do if (isElement(guard)) then setPedControlState(guard, 'fire', false) end removeEventHandler('onClientRender', root, aimForTarget) return end local x, y, z = getPedBonePosition(target, 6) for index, guard in pairs(guards) do if (not isElement(guard)) then table.remove(guards, guard) return end setPedAimTarget(guard, x, y, z) setPedControlState(guard, 'fire', true) end end Link to comment
LiOneLMeSsIShoT Posted March 19, 2014 Author Share Posted March 19, 2014 This is a quickly written example, it's not tested and may not work, if it outputs any errors then post them. local target addEventHandler ("onClientPlayerDamage", localPlayer, function(attacker) if (isElement(attacker) and getElementType(attacker) == 'player' and #guards > 0) then -- He's a player target = attacker addEventHandler('onClientRender', root, aimForTarget) end end) function aimForTarget() if (#guards == 0) then removeEventHandler('onClientRender', root, aimForTarget) return end if (not isElement(target) or isPedDead(target)) then for index, guard in pairs(guards) do if (isElement(guard)) then setPedControlState(guard, 'fire', false) end removeEventHandler('onClientRender', root, aimForTarget) return end local x, y, z = getPedBonePosition(target, 6) for index, guard in pairs(guards) do if (not isElement(guard)) then table.remove(guards, guard) return end setPedAimTarget(guard, x, y, z) setPedControlState(guard, 'fire', true) end end Only "End MIssed" and added it but when zombie attack me or my guard, the guard do nothing. Link to comment
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