[DooD]Heavyair Posted June 21, 2008 Share Posted June 21, 2008 (edited) i am trying to make my own take on the sam site script but when i use onClientRender to fire the sam site things go a bit wrong. everything works fine but i cant stop the explosions and it fires way to fast with onClientRender is there a way of repeatedly firing without using onClientRender or loads of setTimers. oh well here is the script. server side area69samsphere = createColSphere ( 354, 2027, -10, 150 ) function setarea69samsite ( player ) setElementPosition ( area69samsphere, 354, 2027, 25 ) outputChatBox ( "Ready To Fire" ) end function area69samtargeting ( player, matchingDimension ) if ( getElementType ( player ) == "player" ) then triggerClientEvent ( player, "onarea69samfire", getRootElement() ) end end addCommandHandler ( "sam69", setarea69samsite ) addEventHandler ( "onColShapeHit", area69samsphere, area69samtargeting ) client side function area69samfiring ( player ) local px,py,pz = getElementPosition ( getLocalPlayer() ) local glow1 = createMarker ( 353, 2030, 30, "corona", 5, 255, 0, 0, 150 ) local shot1 = createObject ( 3106, 353, 2030, 30 ) attachElementToElement ( glow1, shot1, 0, 0, 0 ) setTimer ( moveObject, 50, 1, shot1, 500, px, py, pz ) setTimer ( destroyElement, 570, 1, shot1 ) setTimer ( destroyElement, 570, 1, glow1 ) setTimer ( createExplosion, 550, 1, px, py, pz, 0 ) end function area69samfire ( player ) addEventHandler ( "onClientRender", getLocalPlayer(), area69samfiring ) setTimer ( removeEventHandler, 1000, 1, "onClientRender", getLocalPlayer(), area69samfiring ) end addEvent ( "onarea69samfire", true ) addEventHandler ( "onarea69samfire", getLocalPlayer(), area69samfire ) i am just messing around with scripting at the moment trying to get an idea of what im doing while i wait for the map editor to come out. any help appreciated. thanx for l kin Edited June 22, 2008 by Guest Link to comment
Ace_Gambit Posted June 21, 2008 Share Posted June 21, 2008 Why not use the current tick count method? You can easily create a time-out using the current and previous tick event. For example: local previousTick = getTickCount() local delay = 5000 -- delay loop with 5000ms (5 seconds) function onClientRender() if (getTickCount() > previousTick + delay) then -- do your thing... previousTick = getTickCount() end end Link to comment
[DooD]Heavyair Posted June 22, 2008 Author Share Posted June 22, 2008 awesome thank u ACE_GAMBIT i remembered seeing that in one of your previous posts but couldnt remember it exactly to find it on wiki i think that should be perfect Link to comment
Sam Fisher Posted June 22, 2008 Share Posted June 22, 2008 Would you please post the script if you finished with it? Link to comment
[DooD]Heavyair Posted June 22, 2008 Author Share Posted June 22, 2008 (edited) this scripting stuff is getting to be quite fun the script works but it only fires once ( trying to figure out multiple shots at the moment ) here u go server side area69samsphere = createColSphere ( 354, 2027, -10, 150 ) function setarea69samsite ( player ) setElementPosition ( area69samsphere, 354, 2027, 25 ) outputChatBox ( "Ready To Fire" ) end function area69samtargeting ( player, matchingDimension ) if ( getElementType ( player ) == "player" ) then triggerClientEvent ( player, "onarea69samfire", getRootElement() ) end end addCommandHandler ( "sam69", setarea69samsite ) addEventHandler ( "onColShapeHit", area69samsphere, area69samtargeting ) client side local previousTick = getTickCount() local area69samfiredelay = 500 function onClientRender ( player ) if ( getTickCount () > previousTick + area69samfiredelay ) then local px,py,pz = getElementPosition ( getLocalPlayer() ) local glow1 = createMarker ( 353, 2030, 30, "corona", 5, 255, 0, 0, 150 ) local shot1 = createObject ( 3106, 353, 2030, 30 ) attachElementToElement ( glow1, shot1, 0, 0, 0 ) setTimer ( moveObject, 50, 1, shot1, 500, px, py, pz ) setTimer ( destroyElement, 570, 1, shot1 ) setTimer ( destroyElement, 570, 1, glow1 ) setTimer ( createExplosion, 550, 1, px, py, pz, 0 ) previousTick = getTickCount() end end addEvent ( "onarea69samfire", true ) addEventHandler ( "onarea69samfire", getLocalPlayer(), onClientRender ) will post changes when i have multiple shots working thanx again ACE_GAMBIT EDIT::: im a bit confused about how to make the function loop so that it fires at u more than once. i thought that it would detect player hitting collision sphere then fire and then continue checkin the tick count and then fire again after 500ms. i tried using onClientRender to repeatedly do the check on tick count but it just created explosions as soon as i joined the server. i will keep trying though Edited June 22, 2008 by Guest Link to comment
[DooD]Heavyair Posted June 22, 2008 Author Share Posted June 22, 2008 after looking through the LUA tutorials for MTA i saw a function using a WHILE command. i dont know where to look to find out if i can use this command or how i can use it. it looks to me like the easiest way to get the samsite to repeatedly fire would be to use the While command for something like While player is within collision sphere then do the sam site fire function anybody know where to look or even how to use this command thanx for any help Link to comment
tma Posted June 22, 2008 Share Posted June 22, 2008 I'd do something like this for the client (untested / replaces all your client code): function SAMfire() setTimer(SAMfireMissile,500,5) -- Call to fire a rocket 5 times with 500 ms between each end function SAMfireMissile ( player ) local px,py,pz = getElementPosition ( getLocalPlayer() ) local glow1 = createMarker ( 353, 2030, 30, "corona", 5, 255, 0, 0, 150 ) local shot1 = createObject ( 3106, 353, 2030, 30 ) attachElementToElement ( glow1, shot1, 0, 0, 0 ) setTimer ( moveObject, 50, 1, shot1, 500, px, py, pz ) setTimer ( destroyElement, 570, 1, shot1 ) setTimer ( destroyElement, 570, 1, glow1 ) setTimer ( createExplosion, 550, 1, px, py, pz, 0 ) end addEvent ( "onarea69samfire", true ) addEventHandler ( "onarea69samfire", getLocalPlayer(), SAMfire) Link to comment
[DooD]Heavyair Posted June 22, 2008 Author Share Posted June 22, 2008 thanx for your reply TMA i have got this working ( hurray ) it detects player inside collision sphere and repeatedly fires until u leave collision sphere. it gives two errors in debugscript 3 one is event allready handled which i think is because the removeEventHandler isnt right second is attempt to call nil value when it stops firing but i think that is the removeEventHandler again but it works and it looks pretty cool. i will try and do some screenshots but it shoots pretty fast. the only way i could get isElementWithinColShape to work was by making collision spheres for client and server but it doesnt seem to be a problem. i am going to try and get the rest of the sam sites firing now ( maybe add some hidden / pop up ones ) server side area69samsphere = createColSphere ( 354, 2027, -10, 150 ) function setarea69samsite ( player ) setElementPosition ( area69samsphere, 354, 2027, 25 ) outputChatBox ( "Ready To Fire" ) end function area69samtargeting ( player, matchingDimension ) if ( getElementType ( player ) == "player" ) then triggerClientEvent ( player, "onarea69samfire", getRootElement() ) end end addCommandHandler ( "sam69", setarea69samsite ) addEventHandler ( "onColShapeHit", area69samsphere, area69samtargeting ) client side previousTick = getTickCount() area69samfiredelay = 500 area69samsphere = createColSphere ( 354, 2027, 25, 150 ) function area69samsitefire ( player, matchingDimension ) detection = isElementWithinColShape ( getLocalPlayer(), area69samsphere ) if detection == true then if ( getTickCount () > previousTick + area69samfiredelay ) then local px,py,pz = getElementPosition ( getLocalPlayer() ) local glow1 = createMarker ( 353, 2030, 30, "corona", 5, 255, 0, 0, 150 ) local shot1 = createObject ( 3106, 353, 2030, 30 ) attachElementToElement ( glow1, shot1, 0, 0, 0 ) setTimer ( moveObject, 50, 1, shot1, 500, px, py, pz ) setTimer ( destroyElement, 570, 1, shot1 ) setTimer ( destroyElement, 570, 1, glow1 ) setTimer ( createExplosion, 550, 1, px, py, pz, 0 ) previousTick = getTickCount() end end end function area69samtarget () addEventHandler ( "onClientRender", getLocalPlayer(), area69samsitefire ) setTimer ( removeEventHandler, 3500, 1, "onClientRender", getLocalPlayer(), area69samsitefire ) end addEvent ( "onarea69samfire", true ) addEventHandler ( "onarea69samfire", getLocalPlayer(), area69samtarget ) 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