SetPedHeadless: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Added OOP syntax)
m (t)
 
(3 intermediate revisions by 3 users not shown)
Line 3: Line 3:
With this function, you can set if a ped has a head or not.
With this function, you can set if a ped has a head or not.
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">bool setPedHeadless ( ped thePed, bool headState )</syntaxhighlight>
<syntaxhighlight lang="lua">
bool setPedHeadless(ped thePed, bool headState)
</syntaxhighlight>
[[File:Headless.png|thumb|exmaple]]
{{OOP||[[ped]]:setHeadless|headless}}
{{OOP||[[ped]]:setHeadless|headless}}


Line 15: Line 18:
==Example==
==Example==
<section name="Server" class="server" show="true">
<section name="Server" class="server" show="true">
This example enables a player to behead themselves, and give them their head back.
This example enables a player to behead themselves (or give themselves their head back)
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function removeMyHead(thePlayer)
function beheadMe(p, cmd)
setPedHeadless(thePlayer, true) -- Removes the players head
local hasHead = not isPedHeadless(p)
outputChatBox("You have been beheaded!", thePlayer, 255, 0, 0) -- A confirmation message for the player
end
addCommandHandler("beheadme", removeMyHead)


function giveBackHead(thePlayer)
if hasHead then
setPedHeadless(thePlayer, false) -- Gives the player a head
setPedHeadless(p, true) -- Remove head
outputChatBox("You have been given a head!", thePlayer, 255, 0, 0) -- A confirmation message for the player
outputChatBox("You have been beheaded!", p, 255, 0, 0) -- A confirmation message for the player
else
setPedHeadless(p, false) -- Restore head
outputChatBox("You have been given a head!", p, 255, 0, 0) -- A confirmation message for the player
end
end
end
addCommandHandler("headmeup", giveBackHead)
addCommandHandler("togglehead", beheadMe)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Latest revision as of 06:55, 23 August 2021

With this function, you can set if a ped has a head or not.

Syntax

bool setPedHeadless(ped thePed, bool headState)
exmaple

OOP Syntax Help! I don't understand this!

Method: ped:setHeadless(...)
Variable: .headless


Required Arguments

  • thePed: The ped to check.
  • headState: head state, use true if you want the ped be headless, use false to give back the head.

Returns

Returns true if successful, false otherwise

Example

Click to collapse [-]
Server

This example enables a player to behead themselves (or give themselves their head back)

function beheadMe(p, cmd)
	local hasHead = not isPedHeadless(p)

	if hasHead then
		setPedHeadless(p, true) -- Remove head
		outputChatBox("You have been beheaded!", p, 255, 0, 0) -- A confirmation message for the player
	else
		setPedHeadless(p, false) -- Restore head
		outputChatBox("You have been given a head!", p, 255, 0, 0) -- A confirmation message for the player
	end
end
addCommandHandler("togglehead", beheadMe)

See Also