<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/SetPedAttack?action=history&amp;feed=atom</id>
	<title>SetPedAttack - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/SetPedAttack?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=SetPedAttack&amp;action=history"/>
	<updated>2026-05-18T16:54:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=SetPedAttack&amp;diff=74467&amp;oldid=prev</id>
		<title>Hydra at 20:29, 12 April 2022</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=SetPedAttack&amp;diff=74467&amp;oldid=prev"/>
		<updated>2022-04-12T20:29:55Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 20:29, 12 April 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l66&quot;&gt;Line 66:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 66:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    setPedAttack(ped, localPlayer, 38, 9999, 7)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    setPedAttack(ped, localPlayer, 38, 9999, 7)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;end&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;end&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;addCommandHandler&lt;/del&gt;(&amp;quot;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;attackme&lt;/del&gt;&amp;quot;, TestAttack)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;addEventHandler&lt;/ins&gt;(&amp;quot;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;onClientRender&lt;/ins&gt;&amp;quot;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;, root&lt;/ins&gt;, TestAttack)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki-wiki_dev_:diff::1.12:old-74464:rev-74467 --&gt;
&lt;/table&gt;</summary>
		<author><name>Hydra</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=SetPedAttack&amp;diff=74464&amp;oldid=prev</id>
		<title>Hydra: Created page with &quot;{{Useful Function}} __NOTOC__ This function makes a ped to attack a player. &lt;br&gt; '''Only CLIENT-SIDE''' &lt;br&gt;  ==Syntax== &lt;syntaxhighlight lang=&quot;lua&quot;&gt;bool setPedAttack(ped theElement, target element theTarget, weapon theWeapon, ammo theAmmo, slot thePedSlot)&lt;/syntaxhighlight&gt;  ===Required Arguments=== * '''theElement''': The ped element. * '''theTarget''': The target element. * '''theWeapon''': The weapon for the ped. * '''theAmmo''': The weapon ammo for the ped. * '''the...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=SetPedAttack&amp;diff=74464&amp;oldid=prev"/>
		<updated>2022-04-12T20:23:09Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Useful Function}} __NOTOC__ This function makes a ped to attack a player. &amp;lt;br&amp;gt; &amp;#039;&amp;#039;&amp;#039;Only CLIENT-SIDE&amp;#039;&amp;#039;&amp;#039; &amp;lt;br&amp;gt;  ==Syntax== &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;bool setPedAttack(ped theElement, target element theTarget, weapon theWeapon, ammo theAmmo, slot thePedSlot)&amp;lt;/syntaxhighlight&amp;gt;  ===Required Arguments=== * &amp;#039;&amp;#039;&amp;#039;theElement&amp;#039;&amp;#039;&amp;#039;: The ped element. * &amp;#039;&amp;#039;&amp;#039;theTarget&amp;#039;&amp;#039;&amp;#039;: The target element. * &amp;#039;&amp;#039;&amp;#039;theWeapon&amp;#039;&amp;#039;&amp;#039;: The weapon for the ped. * &amp;#039;&amp;#039;&amp;#039;theAmmo&amp;#039;&amp;#039;&amp;#039;: The weapon ammo for the ped. * &amp;#039;&amp;#039;&amp;#039;the...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Useful Function}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
This function makes a ped to attack a player.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Only CLIENT-SIDE'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;bool setPedAttack(ped theElement, target element theTarget, weapon theWeapon, ammo theAmmo, slot thePedSlot)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
* '''theElement''': The ped element.&lt;br /&gt;
* '''theTarget''': The target element.&lt;br /&gt;
* '''theWeapon''': The weapon for the ped.&lt;br /&gt;
* '''theAmmo''': The weapon ammo for the ped.&lt;br /&gt;
* '''thePedSlot''': The weapon slot for the ped.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
{{RequiredFunctions|findRotation}}&lt;br /&gt;
&amp;lt;section name=&amp;quot;Clientside script&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function setPedAttack(theElement, theTarget, theWeapon, theAmmo, thePedSlot)&lt;br /&gt;
   if theElement then&lt;br /&gt;
      local x, y, z = getElementPosition(theTarget)&lt;br /&gt;
      local ex, ey, ez = getElementPosition(theElement)&lt;br /&gt;
      local distance = getDistanceBetweenPoints3D(x, y, z, ex, ey, ez)&lt;br /&gt;
      local rotation = findRotation(ex, ey, x, y)&lt;br /&gt;
      setPedRotation(theElement, rotation)&lt;br /&gt;
      setPedLookAt(theElement, x, y, z + 5)&lt;br /&gt;
      setPedAimTarget(theElement, x, y, z)&lt;br /&gt;
      givePedWeapon(theElement, theWeapon, theAmmo)&lt;br /&gt;
      if distance &amp;gt; 3 then&lt;br /&gt;
         setPedControlState(theElement, &amp;quot;forwards&amp;quot;, true)&lt;br /&gt;
         setPedControlState(theElement, &amp;quot;fire&amp;quot;, false)&lt;br /&gt;
         setPedWeaponSlot(theElement, 0)&lt;br /&gt;
      else&lt;br /&gt;
         setPedControlState(theElement, &amp;quot;fire&amp;quot;, true)&lt;br /&gt;
         setPedControlState(theElement, &amp;quot;forwards&amp;quot;, false)&lt;br /&gt;
         setPedWeaponSlot(theElement, thePedSlot)&lt;br /&gt;
      end&lt;br /&gt;
      if getPedControlState(theTarget, &amp;quot;forwards&amp;quot;) or getPedControlState(theTarget, &amp;quot;sprint&amp;quot;) or getPedControlState(theTarget, &amp;quot;backwards&amp;quot;) then&lt;br /&gt;
         setPedControlState(theElement, &amp;quot;fire&amp;quot;, false)&lt;br /&gt;
         setPedWeaponSlot(theElement, 0)&lt;br /&gt;
      else&lt;br /&gt;
         setPedControlState(theElement, &amp;quot;fire&amp;quot;, true)&lt;br /&gt;
         setPedWeaponSlot(theElement, thePedSlot)&lt;br /&gt;
      end&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
_setPedRotation = setPedRotation&lt;br /&gt;
function setPedRotation(element, rot)&lt;br /&gt;
   return _setPedRotation(element, rot)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&lt;br /&gt;
'''The example will show you how you can make a ped attack a player'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local ped = createPed(0, 0, 0, 5)&lt;br /&gt;
&lt;br /&gt;
function TestAttack()&lt;br /&gt;
   setPedAttack(ped, localPlayer, 38, 9999, 7)&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler(&amp;quot;attackme&amp;quot;, TestAttack)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Author==&lt;br /&gt;
&lt;br /&gt;
'''by Hydra45'''&lt;br /&gt;
'''Discord: Hydra45#6859'''&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Useful_Functions}}&lt;/div&gt;</summary>
		<author><name>Hydra</name></author>
	</entry>
</feed>