Jump to content

SAM rocket help


Recommended Posts

hello again. sorry to ask aa question again so soon, but this is bugign the hell out of me. this script is supposed to create a collision sphere serverside and initiate rockets at clientside that lock on to an intruder in a jetpack or flying vehicle that is not a hunter or a hydra. however, all it does is give me the chatbox messages. other than that nothing happens. there are no errors either. can someone point me to the right direction?

SERVERSIDE:

function samOn ( thePlayer ) 
  
     deathSphere = createColSphere ( 188.28005981445, 1941.6798095703, 17.673742294312, 100 ) 
  
     outputChatBox ( "You have activated the Area 69 SAM sites", thePlayer, 255, 0, 0 ) 
  
end 
  
function samOff ( thePlayer ) 
  
     destroyElement ( deathSphere ) 
  
     outputChatBox ( "You have disabled the Area 69 SAM sites", thePlayer, 255, 0, 0 ) 
  
end 
  
  
  
addCommandHandler ( "samon", samOn ) 
addCommandHandler ( "samoff", samOff ) 
  

CLIENTSIDE:

function onClientColShapeHit ( thePlayer, playervehicle, id ) 
  
     playervehicle = getPlayerOccupiedVehicle ( thePlayer ) 
  
     id = getVehicleID ( playervehicle ) 
  
     if ( playervehicle ) then 
  
          if ( id == 592 or id == 577 or id == 511 or id == 548 or id == 512 or id == 593 or id == 417 or id == 487 or id ==  553 or id == 488 or id == 497 or id == 563 or id == 476 or id == 447 or id == 519 or id == 460 or id == 469 or id == 513 or id == 441 or id == 501 or id == 465 ) then 
  
               createProjectile ( getLocalPlayer(), 20, 15.58650970459, 1719.0345458984, 26.134944915771, 500, playervehicle ) 
  
               createProjectile ( getLocalPlayer(), 20, 237.6640625, 1696.4927978516, 26.089979171753, 500, playervehicle ) 
  
               createProjectile ( getLocalPlayer(), 20, 354.64459228516, 2028.2109375, 26.094778060913, 500, playervehicle ) 
  
               createProjectile ( getLocalPlayer(), 20, 188.35180664063, 2081.2719726563, 26.120576858521, 500, playervehicle ) 
  
               outputChatBox ( "Warning! SAM collision iminent!", thePlayer, 255, 0, 0 ) 
  
          end 
  
     else 
  
          if ( doesPlayerHaveJetpack ( thePlayer ) ) then 
  
               createProjectile ( getLocalPlayer(), 20, 15.58650970459, 1719.0345458984, 26.134944915771, 500, thePlayer ) 
  
               createProjectile ( getLocalPlayer(), 20, 237.6640625, 1696.4927978516, 26.089979171753, 500, thePlayer ) 
  
               createProjectile ( getLocalPlayer(), 20, 354.64459228516, 2028.2109375, 26.094778060913, 500, thePlayer ) 
  
               createProjectile ( getLocalPlayer(), 20, 188.35180664063, 2081.2719726563, 26.120576858521, 500, thePlayer ) 
  
               outputChatBox ( "Warning! SAM collision iminent!", thePlayer, 255, 0, 0 ) 
  
          end 
  
     end 
  
end 
  
  
addEventHandler ( "onClientColShapeHit", thePlayer, true ) 

XML:

 <meta> 
  <info author="MasterOfPuppets" description="Intruders go Kaboom" version="1" type="script" />  
  <script src="sam.lua" type="client" />  
  <script src="samserver.lua" type="server" />  
  </meta> 

any help is very appreciated

Link to comment

The second argument of addEventHandler is the point in the element tree that the handler is placed. You'll capture events that come from child or parent elements of that element. The 'source' of the onClientColShapeHit event is the colshape, not the player. As such, attaching the event to the player will mean the event is never triggered as the player is not a colshape. Either do what 50p says and add a check in the function (and change thePlayer to the root element) or change thePlayer to your colshape.

Link to comment

still doesnt work. and aslo, still no errors.

  
function onClientColShapeHit ( target, playervehicle, id ) 
  
     target = getLocalPlayer()    
   
     playervehicle = getPlayerOccupiedVehicle ( target ) 
  
     id = getVehicleID ( playervehicle ) 
      
     if ( target ) then 
  
          if ( playervehicle ) then 
  
               if ( id == 592 or id == 577 or id == 511 or id == 548 or id == 512 or id == 593 or id == 417 or id == 487 or id ==  553 or id == 488 or id == 497 or id == 563 or id == 476 or id == 447 or id == 519 or id == 460 or id == 469 or id == 513 or id == 441 or id == 501 or id == 465 ) then 
  
                    createProjectile ( target, 20, 15.58650970459, 1719.0345458984, 26.134944915771, 500, playervehicle ) 
  
                    createProjectile ( target, 20, 237.6640625, 1696.4927978516, 26.089979171753, 500, playervehicle ) 
  
                    createProjectile ( target, 20, 354.64459228516, 2028.2109375, 26.094778060913, 500, playervehicle ) 
  
                    createProjectile ( target, 20, 188.35180664063, 2081.2719726563, 26.120576858521, 500, playervehicle ) 
  
                    outputChatBox ( "Warning! SAM collision iminent!", target, 255, 0, 0 ) 
  
               end 
  
          else 
  
               if ( doesPlayerHaveJetpack ( target ) ) then 
  
                    createProjectile ( target, 20, 15.58650970459, 1719.0345458984, 26.134944915771, 500, target ) 
  
                    createProjectile ( target, 20, 237.6640625, 1696.4927978516, 26.089979171753, 500, target ) 
  
                    createProjectile ( target, 20, 354.64459228516, 2028.2109375, 26.094778060913, 500, target ) 
  
                    createProjectile ( target, 20, 188.35180664063, 2081.2719726563, 26.120576858521, 500, target ) 
  
                    outputChatBox ( "Warning! SAM collision iminent!", target, 255, 0, 0 ) 
  
               end 
  
          end 
  
     end 
  
end 
  
  
addEventHandler ( "onClientColShapeHit", deathSphere, true ) 
  
      

Link to comment
The documentation for onClientColShapeHit says that the parameters passed are 'element theElement, bool matchingDimension', you're using 'target, playervehicle, id' for some reason...

I wanted to mention it in my first post, somehow I've forgotten. Anyway, Vercetti, try the example ( http://development.mtasa.com/index.php? ... olShapeHit ) and don't forget to create sphere on client's side.

Link to comment

i think i kinda understand more about it now. but, i want to make the sams able to turn off and on. if i make that decision clientside then it will be up to the client to set up the colShpere, and im sure they dont want to get blown up when trying to intrude on the base lol. can you call something from another script in the resource?

Link to comment

Yea, that's how I set up my SAM sites. The colshape is created server-side. That way I want to keep the server-script in control. Whenever "something" is entering the colshape the server performs multiple checks before it sends a request to the client to actually fire the rockets. As soon as the client is finished it sends a request back to the server notifying other clients can create projectiles now (just to make sure there aren't 100 clients creating projectiles at the same time).

Here's a vid of the working SAM sites:

Link to comment

still nothing happens and still no errors. I dont know what the deal is. please someone give me info that i understand, not insert varialbe into the root element and setnode mumbojumbo. just please help me in english.

serverside

function samOn ( thePlayer ) 
  
     deathSphere = createColSphere ( 188.28005981445, 1941.6798095703, 17.673742294312, 100 ) 
  
     outputChatBox ( "You have activated the Area 69 SAM sites", thePlayer, 255, 0, 0 ) 
  
end 
  
function samOff ( thePlayer ) 
  
     destroyElement ( deathSphere ) 
  
     outputChatBox ( "You have disabled the Area 69 SAM sites", thePlayer, 255, 0, 0 ) 
  
end 
  
  
  
addCommandHandler ( "samon", samOn ) 
addCommandHandler ( "samoff", samOff ) 
  
  

clientside

  
  
function onClientColShapeHit ( deathSphere, true ) 
  
     target = getLocalPlayer()    
   
     playervehicle = getPlayerOccupiedVehicle ( target ) 
  
     id = getVehicleID ( playervehicle ) 
      
     if ( target ) then 
  
          if ( playervehicle ) then 
  
               if ( id == 592 or id == 577 or id == 511 or id == 548 or id == 512 or id == 593 or id == 417 or id == 487 or id ==  553 or id == 488 or id == 497 or id == 563 or id == 476 or id == 447 or id == 519 or id == 460 or id == 469 or id == 513 or id == 441 or id == 501 or id == 465 ) then 
  
                    createProjectile ( target, 20, 15.58650970459, 1719.0345458984, 26.134944915771, 500, playervehicle ) 
  
                    createProjectile ( target, 20, 237.6640625, 1696.4927978516, 26.089979171753, 500, playervehicle ) 
  
                    createProjectile ( target, 20, 354.64459228516, 2028.2109375, 26.094778060913, 500, playervehicle ) 
  
                    createProjectile ( target, 20, 188.35180664063, 2081.2719726563, 26.120576858521, 500, playervehicle ) 
  
                    outputChatBox ( "Warning! SAM collision iminent!", target, 255, 0, 0 ) 
  
               end 
  
          else 
  
               if ( doesPlayerHaveJetpack ( target ) ) then 
  
                    createProjectile ( target, 20, 15.58650970459, 1719.0345458984, 26.134944915771, 500, target ) 
  
                    createProjectile ( target, 20, 237.6640625, 1696.4927978516, 26.089979171753, 500, target ) 
  
                    createProjectile ( target, 20, 354.64459228516, 2028.2109375, 26.094778060913, 500, target ) 
  
                    createProjectile ( target, 20, 188.35180664063, 2081.2719726563, 26.120576858521, 500, target ) 
  
                    outputChatBox ( "Warning! SAM collision iminent!", target, 255, 0, 0 ) 
  
               end 
  
          end 
  
     end 
  
end 
  
  
  
  
      

Link to comment

Saying what we're saying in 'mumbojumbo' is not likely to get us to help. Which bits specifically don't you understand, don't get us to rewrite everything we've written targeted at a 5 year old.

Link to comment
  • 4 weeks later...

here it is. edit it to your use

serverside

local deathSphere = createColSphere ( X, Y, Z, Radius ) --Triggers rockets 
local warningSphere = createColSphere ( X, Y, Z, Radius ) --Triggers warning 
  
function enableSam ( thePlayer ) 
  
     setElementPosition ( deathSphere, X, Y, Z ) 
     setElementPosition ( warningSphere, X, Y, Z )    
     outputChatBox ( "You have enabled the SAM sites at (put place here)", thePlayer, 255, 0, 0 ) 
  
end 
  
  
  
function disableSam ( thePlayer ) 
  
     setElementPosition ( deathSphere, 0, 0, -9999 ) 
     setElementPosition ( warningSphere, 0, 0, -9999 ) 
     outputChatBox ( "You have disabled the SAM sites at(place here)", thePlayer, 255, 0, 0 ) 
  
end 
  
  
  
function samSite ( thePlayer, matchingDimension ) 
  
          veh = getPlayerOccupiedVehicle ( thePlayer )      
          id = getVehicleID ( veh ) 
               if ( id == 592 or id == 577 or id == 511 or id == 548 or id == 512 or id == 593 or id == 425 or id == 520 or id == 417 or id == 487 or id == 553 or id == 488 or id == 497 or id == 563 or id == 476 or id == 447 or id == 519 or id == 460 or id == 469 or id == 513 or id == 464 or id == 501 or id == 465 ) then 
                    triggerClientEvent ( thePlayer, "onSamTrigger", getRootElement() ) 
                    outputChatBox ( "Surface to air missiles have been fired!", thePlayer, 255, 0, 0 ) 
               end 
      
  
end 
  
function samWarn ( thePlayer, matchingDimension ) 
  
   veh = getPlayerOccupiedVehicle ( thePlayer )      
   id = getVehicleID ( veh ) 
        if ( id == 592 or id == 577 or id == 511 or id == 548 or id == 512 or id == 593 or id == 425 or id == 520 or id == 417 or id == 487 or id == 553 or id == 488 or id == 497 or id == 563 or id == 476 or id == 447 or id == 519 or id == 460 or id == 469 or id == 513 or id == 464 or id == 501 or id == 465 ) then   
             outputChatBox ( "Warning! (place here) has SAM sites activated! Turn back!", thePlayer, 255, 0, 0 ) 
        end 
end 
  
function jetpackTrigger ( thePlayer, matchingDimension ) 
  
     if ( doesPlayerHaveJetPack ( thePlayer ) ) then 
          outputChatBox ( "Warning! (place here) will kill you with telepathy if you go in with a jetpack!", thePlayer, 255, 0, 0 ) 
     end 
  
end 
  
  
function jetpackWarn ( thePlayer, matchingDimension ) 
  
     if ( doesPlayerHaveJetPack ( thePlayer ) ) then 
          triggerClientEvent ( thePlayer, "onSamTrigger", getRootElement() ) 
          outputChatBox ( "I wasn't lying about the telepathy death. Enjoy the fireworks!", thePlayer, 255, 0, 0 ) 
          killPlayer ( thePlayer ) 
  
  
     end 
  
end 
  
           
  
  
addCommandHandler ( "activatesam", enableSam ) 
addCommandHandler ( "deactivatesam", disableSam ) 
addEventHandler ( "onColShapeHit", deathSphere, samSite ) 
addEventHandler ( "onColShapeHit", warningSphere, samWarn ) 
addEventHandler ( "onColShapeHit", deathSphere, jetpackWarn ) 
addEventHandler ( "onColShapeHit", warningSphere, jetpackTrigger ) 

clientside:

function samTrigger ( thePlayer ) 
  
     
  
  
               createProjectile ( getLocalPlayer(), 20, X, Y, Z, 50, getLocalPlayer() ) 
  
               createProjectile ( getLocalPlayer(), 20, X, Y, Z, 50, getLocalPlayer() ) 
  
               createProjectile ( getLocalPlayer(), 20, X, Y, Z, 50, getLocalPlayer() ) 
  
               createProjectile ( getLocalPlayer(), 20, X, Y, Z, 50, getLocalPlayer() ) 
  
               createProjectile ( getLocalPlayer(), 20, X, Y, Z, 50, getLocalPlayer() ) 
  
               createProjectile ( getLocalPlayer(), 20, X, Y, Z, 50, getLocalPlayer() ) 
  
               createProjectile ( getLocalPlayer(), 20, X, Y, Z, 50, getLocalPlayer() ) 
  
               createProjectile ( getLocalPlayer(), 20, X, Y, Z, 50, getLocalPlayer() ) 
  
               createProjectile ( getLocalPlayer(), 20, X, Y, Z, 50, getLocalPlayer() ) 
  
               createProjectile ( getLocalPlayer(), 20, X, Y, Z, 50, getLocalPlayer() ) 
  
               createProjectile ( getLocalPlayer(), 20, X, Y, Z, 50, getLocalPlayer() ) 
  
               createProjectile ( getLocalPlayer(), 20, X, Y, Z, 50, getLocalPlayer() ) 
  
  
  
end 
addEvent ( "onSamTrigger", true ) 
  
addEventHandler ( "onSamTrigger", getRootElement(), samTrigger ) 

Link to comment

If you want to shoot at a player while he is in the death sphere simply toggle the sphere on and off (moving it from -9999 to XYZ back and forth) every x seconds. Since your script detects hit events the sam will fire every time the player is still in the death sphere area.

Link to comment

sorry but i am really struggling to understand this scripting stuff

im not sure where to set the coordinates for the position of the sam site

i want to put it on the air craft carrier in easter bay but i dont seem to be getting anywhere

could u possibly show me what i need to change

sorry if im wasting your time and theres no need to reply if your busy as im sure ill figure it out eventualy

thanx for the help so far vercetti 10 10 :D:D

Link to comment

First what you need to do is set yourself as an admin on a test server run off your computer. then go to where you want the center of the spheres to be. open your admin control panel and take note of your X, Y, Z coordinates. the radius is measured in meters for colspheres. you kind of have to estimate how large the rocket field should be. if you make it too big, people just flying near the complex will be shot at. if you make it too small, people will be able to get in, so tinker around with the radius a bit. as for the warning sphere, make its radius bigger than the trigger sphere. set the XYZ coordinates the same though. as for the createProjectile's every createprojectile makes a rocket for one person in the intruding aircraft. so if you have a full maverick for instance, one createProjectile should make four rockets. you can add as many as you like as well as delete as many, but keep lag in mind when you add them. you dont want to overload the client. as for XYZ, what i did was i made three rockets fire from every sam site at area 51. but you can do things different. you can set the XYZ for the rockets wherever you like, maybe put three on every corner of the complex. record the XYZ of all four corners and add about 15 units to the Z position for each. then add about 5 Z units for every rocet above it. as for the commands activate sam and deactivate sam, leave deactivate sam to 0, 0, -9999. but put the xyz to activate sam to wherever your colSpheres are. this moves the colSphere to and from the area to simulate activation and deactivation, just in case you want to fly in. then just put the name of the place in and then your good.

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