Jump to content

Phone Walking Style + Animation


Recommended Posts

Phone Animation 



Explanation
Hi there i need HELP COMPLETING this Script for phone animation the Idea is replacing the camera with a phone and when ever i chose camera/phone 1st animation start for 2 sec bringing the "phone out" then triggering client event changing walking style to 137ID (modefied to phone walking style) and ofcourse the phone main page with it then when changing to other weapon or activating the "phone command again returning walking style to default and playing 2nd animation "phone in " and closing phone main page with it :

mta-screen_2019-04-15_13-35-25.png?width

well almost like this this is me making the script work but not exactly as i want :

--------------------------


The Script : 

for now it only activate walking style 137 by command(i want to make him chose weapon 43id by that command) i want to disactivate it too by the same command:( 

Client Side
 



function togglephone() 

	setPedWalkingStyle (localPlayer ,137)
end
addEvent("togglephone",true)
addEventHandler("togglephone",root, togglephone)


  function replaceModel() 
  txd = engineLoadTXD("cellphone.txd", 367 )
  engineImportTXD(txd, 367)
  dff = engineLoadDFF("cellphone.dff", 367 )
  engineReplaceModel(dff, 367)
  end
addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), replaceModel)


Server Side



function togglephone ( playerSource )
			giveWeapon ( source, 43, 200 )
			triggerClientEvent(root, "togglephone", root)
			
	
end
addCommandHandler ( "phone", togglephone )

2. i need to add the two animaions "phone_out " from ped.ifp block that i modified  for 1.2 sec then "phone_in" played when phone is disabled how to mix them both in one script 

function togglephone(thePlayer)
	if not getElementData(thePlayer, "phoning") then
    		giveWeapon ( thePlayer, 43, 200 ) --- this give weap but also how chosing it will trigger the animation thing 
		setPedAnimation(thePlayer, "ped", "phone_out", -1, false, false, false, false)
		setElementData(thePlayer, "phoning", true)
	else
		-- If you use again this command will play phone in animation need timer in both animations 
		setPedAnimation(thePlayer, "ped", "phone_in", -1, false, false, false, false)
		removeElementData(thePlayer, "phoning")
	end
end
addCommandHandler("phone", togglephone)

 

Edited by DarkBeautyDZ
Link to comment

To answer your question, just use "takeWeapon" at the else. Also, it'd be more convenient using tables for these sorts of things. Element data is not the wisest choice.

For example:

local using_phone = {}

function togglePhone(player)

     if (not using_phone[player]) then

           using_phone[player] = true

           --You could also add giveWeapon here (to continue your script)

           --Animation here

     else

          using_phone[player] = false

           --And here you could add takeWeapon here.

           --End animation here

     end

end

addCommandHandler("phone", togglePhone)

 

Furthermore, I suggest you rethink your code, it doesn't look that great and you'll encounter issues in the future. For example, calling root to set a walking style.. First of, there's no need for the walking style as when the phone is enabled I assume you have a cursor enabled too, so the player couldn't move either way (unless you're using it as an idling position). Secondly, you're calling the root element of everything, not really efficient. You have "playerSource" defined, so just call it for "playerSource". Personal advice, remove that whole server function and client trigger for walking style. In addition to all this, I would add a triggerClientEvent to toggle the phone from this function and change the commandHandler to a bindKey. Drop a message if you need any help, we'll be of assistance. Good-luck.

Link to comment
12 hours ago, Ab-47 said:

To answer your question, just use "takeWeapon" at the else. Also, it'd be more convenient using tables for these sorts of things. Element data is not the wisest choice.

For example:

local using_phone = {}

function togglePhone(player)

     if (not using_phone[player]) then

           using_phone[player] = true

           --You could also add giveWeapon here (to continue your script)

           --Animation here

     else

          using_phone[player] = false

           --And here you could add takeWeapon here.

           --End animation here

     end

end

addCommandHandler("phone", togglePhone)

 

Furthermore, I suggest you rethink your code, it doesn't look that great and you'll encounter issues in the future. For example, calling root to set a walking style.. First of, there's no need for the walking style as when the phone is enabled I assume you have a cursor enabled too, so the player couldn't move either way (unless you're using it as an idling position). Secondly, you're calling the root element of everything, not really efficient. You have "playerSource" defined, so just call it for "playerSource". Personal advice, remove that whole server function and client trigger for walking style. In addition to all this, I would add a triggerClientEvent to toggle the phone from this function and change the commandHandler to a bindKey. Drop a message if you need any help, we'll be of assistance. Good-luck.

yes as you say Mr , changing command to bind is what i'm planning to do , but there is something alse about the animation the animation i want it to stop after 1.2 sec means timer after else is another animation 2nd one would be activated for another 1.2 sec (phone out - phone in ) , and about the cursor i got that covered so don't worry :)

Link to comment
On 15/04/2019 at 22:37, Dzsozi (h03) said:

Why don't you just use bone attach and attach a phone object to the player's hand?

i thought about that but like this it's more realistic and if you thought about it enough you would realize that 43ID weapon is Camera so it's fit for phone you would be able to take pics it's more realistic that way so changing to camera will trigger the whole thing animation the walking style and the phone main page

 

Link to comment

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