crazyde21 Posted July 20, 2014 Share Posted July 20, 2014 I want to make a simple script. Enter the command to create ped, then I want to use "w / s / a / d" to control him, I do not know how to move ped, my "client script" using "setPedControlState", but others can not see ped move! and next is my script... client addEvent("test1",true) addEventHandler("test1",getRootElement(),function(ped1) function updateCamera ( ) local x, y, z = getElementPosition ( ped1 ) local px, py, pz = getElementPosition ( getLocalPlayer() ) setCameraMatrix ( px, py, pz+10, x, y, z ) setPedCameraRotation (ped1,getPedCameraRotation(getLocalPlayer())) end addEventHandler ( "onClientRender", getRootElement(), updateCamera ) function leftdown ( key,keyState ) rx,ry,rz=getElementRotation ( ped1 ) rz=rz+45 --setPedControlState ( ped1, "left", true ) triggerServerEvent("test3",getLocalPlayer(),keyState,rx,ry,rz) end function leftup ( key,keyState ) --if getPedControlState ( ped1,"left" )then --setPedControlState ( ped1, "left", false ) triggerServerEvent("test3",getLocalPlayer(),keyState,rx,ry,rz) --end end function rightdown ( key,keyState ) rx,ry,rz=getElementRotation ( ped1 ) rz=rz-45 --setPedControlState ( ped1, "right", true ) triggerServerEvent("test3",getLocalPlayer(),keyState,rx,ry,rz) end function rightup ( key,keyState ) --if getPedControlState ( ped1,"right" )then --setPedControlState ( ped1, "right", false ) triggerServerEvent("test3",getLocalPlayer(),keyState,rx,ry,rz) --end end function forwardsdown ( key,keyState ) rx,ry,rz=getElementRotation ( ped1 ) rz=rz --setPedControlState ( ped1, "forwards", true ) triggerServerEvent("test3",getLocalPlayer(),keyState,rx,ry,rz) end function forwardsup( key,keyState ) --if getPedControlState ( ped1,"forwards" )then --setPedControlState ( ped1, "forwards", false ) triggerServerEvent("test3",getLocalPlayer(),keyState,rx,ry,rz) --end end function backwardsdown ( key,keyState ) --setPedControlState ( ped1, "backwards", true ) triggerServerEvent("test3",getLocalPlayer(),keyState,rx,ry,rz) end function backwardsup ( key,keyState ) --if getPedControlState ( ped1,"backwards" )then --setPedControlState ( ped1, "backwards", false ) triggerServerEvent("test3",getLocalPlayer(),keyState,rx,ry,rz) --end end function jumpdown ( ) --setPedControlState ( ped1, "jump", true ) end function jumpup ( ) --if getPedControlState ( ped1,"jump" )then --setPedControlState ( ped1, "jump", false ) --end end function sprintdown ( ) --setPedControlState ( ped1, "sprint", true ) end function sprintup ( ) --if getPedControlState ( ped1,"sprint" )then --setPedControlState ( ped1, "sprint", false ) --end end function renwuboom() unbindKey("g","down",renwuboom) setTimer ( playSound, 1000, 1, "sounds/daoshu321.wav" ) setTimer ( outputChatBox, 1000, 1, "人肉炸弹倒计时3" ) setTimer ( outputChatBox, 2000, 1, "人肉炸弹倒计时2") setTimer ( outputChatBox, 3000, 1, "人肉炸弹倒计时1" ) setTimer (function() triggerServerEvent("test2",getLocalPlayer(),getElementPosition ( ped1 )) playSound("sounds/boom.mp3") removeEventHandler("onClientRender", getRootElement(), updateCamera) fadeCamera(false,1.0,255,255,0) end,4000,1) setTimer ( fadeCamera, 5000, 1, true, 0.5 ) setTimer ( function() setCameraTarget(getLocalPlayer()) unbindKey("a","down",leftdown) unbindKey("a","up",leftup) unbindKey("d","down",rightdown) unbindKey("d","up",rightup) unbindKey("w","down",forwardsdown) unbindKey("w","up",forwardsup) unbindKey("s","down",backwardsdown) unbindKey("s","up",backwardsup) unbindKey("lshift","down",jumpdown) unbindKey("lshift","up",jumpup) unbindKey("space","down",sprintdown) unbindKey("space","up",sprintup) end, 6000, 1 ) end bindKey("g","down",renwuboom) bindKey("a","down",leftdown) bindKey("a","up",leftup) bindKey("d","down",rightdown) bindKey("d","up",rightup) bindKey("w","down",forwardsdown) bindKey("w","up",forwardsup) bindKey("s","down",backwardsdown) bindKey("s","up",backwardsup) bindKey("lshift","down",jumpdown) bindKey("lshift","up",jumpup) bindKey("space","down",sprintdown) bindKey("space","up",sprintup) end ) server xianzhizhadan=0 function Createyaokongche(thePlayer) xianzhizhadan=xianzhizhadan+1 if xianzhizhadan==1 then setElementFrozen(thePlayer,true) toggleAllControls ( thePlayer,false) local x,y,z=getElementPosition(thePlayer) local rx,ry,rz = getElementRotation ( thePlayer ) ped1 = createPed(56,x,y+5,z) outputChatBox("人肉炸弹启动!WSAD控制移动,G倒数引爆",thePlayer) triggerClientEvent(thePlayer,"test1",getRootElement(),ped1) end end addCommandHandler("人肉炸弹",Createyaokongche) addEvent("test2",true) addEventHandler("test2",getRootElement(),function(x,y,z) destroyElement(ped1) createExplosion(x,y,z,0,source) setElementFrozen(source,false) setTimer(toggleAllControls ,2000,1,source,true) xianzhizhadan=0 end ) addEvent("test3",true) addEventHandler("test3",getRootElement(),function(statn,rx,ry,rz) outputChatBox("statn状态为:"..statn) if statn=="down"then local zhuanshen=setPedRotation(ped1,rz) if zhuanshen then setPedAnimation(ped1,"ped", "run_player") end end if statn=="up"then setPedRotation(ped1,rz) setPedAnimation(ped1,false) end end ) Link to comment
Saml1er Posted July 20, 2014 Share Posted July 20, 2014 Dis code is a disaster. --client --[[ ************************************************************************************ I helped you with 2 function, make the rest by yourself. ;P + ************************************************************************************ ]] ped1 = false -- make the variable global local rx,ry,rz --- we make those variables local so we can use them for all functions inside this script addEvent("test1",true) addEventHandler("test1",getRootElement(), function(ped) ped1 = ped -- define it addEventHandler ( "onClientRender", getRootElement(), updateCamera ) -- add the event handler bindKey("space","down",sprintdown) bindKey("a","down",leftdown) end ) function updateCamera ( ) if isElement ( ped1 ) then -- make sure the ped exists local x, y, z = getElementPosition ( ped1 ) local px, py, pz = getElementPosition ( getLocalPlayer() ) setCameraMatrix ( px, py, pz+10, x, y, z ) setPedCameraRotation (ped1,getPedCameraRotation(getLocalPlayer())) end end function rightdown ( key,keyState ) if setPedControlState ( ped1, "right", false ) then --[[ this will prevent from bugging, you must use this for all controls and if you don't then you will see controls not working.]] rx,ry,rz=getElementRotation ( ped1 ) rz=rz-45 setPedControlState ( ped1, "right", true ) triggerServerEvent("test3",getLocalPlayer(),keyState,rx,ry,rz) end end function sprintup ( ) if setPedControlState ( ped1,"sprint",false )then setPedControlState ( ped1, "sprint", true) end end function renwuboom() unbindKey("g","down",renwuboom) setTimer ( playSound, 1000, 1, "sounds/daoshu321.wav" ) setTimer ( outputChatBox, 1000, 1, "人肉炸弹倒计时3" ) setTimer ( outputChatBox, 2000, 1, "人肉炸弹倒计时2") setTimer ( outputChatBox, 3000, 1, "人肉炸弹倒计时1" ) setTimer (function() triggerServerEvent("test2",getLocalPlayer(),getElementPosition ( ped1 )) playSound("sounds/boom.mp3") removeEventHandler("onClientRender", getRootElement(), updateCamera) fadeCamera(false,1.0,255,255,0) end,4000,1) setTimer ( fadeCamera, 5000, 1, true, 0.5 ) setTimer ( function() setCameraTarget(getLocalPlayer()) unbindKey("a","down",leftdown) unbindKey("a","up",leftup) unbindKey("d","down",rightdown) unbindKey("d","up",rightup) unbindKey("w","down",forwardsdown) unbindKey("w","up",forwardsup) unbindKey("s","down",backwardsdown) unbindKey("s","up",backwardsup) unbindKey("lshift","down",jumpdown) unbindKey("lshift","up",jumpup) unbindKey("space","down",sprintdown) unbindKey("space","up",sprintup) end, 6000, 1 ) end bindKey("g","down",renwuboom) bindKey("a","down",leftdown) bindKey("space","up",sprintup) end ) Btw I'll suggest you to use onClientKey. I don't have time to do this all for you so. ;p Link to comment
crazyde21 Posted July 20, 2014 Author Share Posted July 20, 2014 My question is: Is it just add "if setPedControlState (ped1," right ", false) then" execution, others can see ped move? Link to comment
Saml1er Posted July 20, 2014 Share Posted July 20, 2014 My question is: Is it just add "if setPedControlState (ped1," right ", false) then" execution, others can see ped move? Yes. There's no server side function for controlling ped. All you can do it search for animations and use them but you can only use animations, that's the best way. Link to comment
crazyde21 Posted July 21, 2014 Author Share Posted July 21, 2014 Yes. There's no server side function for controlling ped. All you can do it search for animations and use them but you can only use animations, that's the best way. You mean: I have to write server function so that others can see ped move?? , But I can not write server functions, what with a few function? setPedAnimation setPedAnimationProgress setPedArmor setPedChoking setPedDoingGangDriveby setPedFightingStyle setPedFrozen setPedGravity setPedHeadless setPedOnFire setPedSkin setPedStat setPedWeaponSlot Which? function Link to comment
crazyde21 Posted July 21, 2014 Author Share Posted July 21, 2014 if i use "setPedAnimation" , the ped can only go in a straight line~ how to write? Link to comment
12p Posted July 21, 2014 Share Posted July 21, 2014 Set its rotation, so that said "straight line" leads to your desired point... Link to comment
Saml1er Posted July 21, 2014 Share Posted July 21, 2014 A custom function "findRotation" may come handy. Link to comment
crazyde21 Posted July 21, 2014 Author Share Posted July 21, 2014 Who can be my script as a reference, write a server rotation function? Ped and make moving? Link to comment
Saml1er Posted July 22, 2014 Share Posted July 22, 2014 No one. Try at least and if you get stuck then we'll help. 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