Advertisement
HR_Shaft

Setup Weapons for stock PC/CE maps for SAPP

Sep 27th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.46 KB | None | 0 0
  1. -- Setup Weapons for stock PC/CE maps for SAPP
  2. -- by H® Shaft
  3.  
  4. -- Allows server admins to setup primary and secondary weapons per map, and grenade counts per map.  See line 78 - load tables to modify.
  5. -- WILL work with custom CE maps which have stock weapon sets
  6.  
  7. -- sapp api version
  8. api_version = "1.8.0.0"
  9.  
  10. -- do not edit --
  11. game_started = false
  12.  
  13. function OnScriptLoad()
  14.     register_callback(cb['EVENT_GAME_START'], "NewGame")
  15.     register_callback(cb['EVENT_GAME_END'], "GameEnd")
  16.     register_callback(cb['EVENT_SPAWN'], "OnSpawn")
  17.     map_name = get_var(0,"$map")
  18.     Load_Tables()
  19. end
  20.  
  21. function OnScriptUnload()
  22.     primary_weapon = {}
  23.     secondary_weapon = {}
  24.     frag_count = {}
  25.     plasma_count = {}
  26. end
  27.  
  28. function NewGame()
  29.     game_started = true
  30.     map_name = get_var(0,"$map")
  31.     Load_Tables()
  32. end
  33.  
  34. function GameEnd()
  35.     game_started = false
  36. end
  37.  
  38. function OnSpawn(PlayerIndex)
  39.     if player_alive(PlayerIndex) and game_started then
  40.         -- destroy existing weapons
  41.         local player_object = get_dynamic_player(PlayerIndex)
  42.         for i = 0,3 do
  43.             local weapID = read_dword(player_object + 0x2F8 + i*4)
  44.             if weapID ~= 0xFFFFFFFF then
  45.                 destroy_object(weapID)
  46.             end
  47.         end
  48.         -- initiate timer to assign scripted weapons
  49.         gameweap = timer(33, "AssignGameWeapons", PlayerIndex)
  50.     end
  51. end
  52.  
  53. function AssignGameWeapons(PlayerIndex)
  54.     if player_alive(PlayerIndex) and game_started then
  55.         local player_object = get_dynamic_player(PlayerIndex)
  56.         local player_static = get_player(PlayerIndex)
  57.         local x,y,z = read_vector3d(player_object + 0x5C)
  58.         local Z = z+0.5
  59.         -- grenades
  60.         safe_write(true)
  61.         write_word(player_object + 0x31E, frag_count[map_name])
  62.         write_word(player_object + 0x31F, plasma_count[map_name])
  63.         safe_write(false)
  64.        
  65.         -- create and assign weapons
  66.         if secondary_weapon[map_name] ~= nil then
  67.             local secondary_id = spawn_object("weap", secondary_weapon[map_name],x,y,Z)
  68.             assign_weapon(secondary_id, PlayerIndex)
  69.         end
  70.         if primary_weapon[map_name] ~= nil then
  71.             local primary_id = spawn_object("weap", primary_weapon[map_name],x,y,Z)
  72.             assign_weapon(primary_id, PlayerIndex)
  73.         end
  74.        
  75.     end
  76.     return false       
  77. end
  78.  
  79. function Load_Tables()
  80.     -- WEAPON NAME list of weapon tag names (stock PC/CE weapons)
  81.     PLASMA_PISTOL = "weapons\\plasma pistol\\plasma pistol"
  82.     NEEDLER = "weapons\\needler\\mp_needler"
  83.     SHOTGUN = "weapons\\shotgun\\shotgun"
  84.     ASSAULT_RIFLE = "weapons\\assault rifle\\assault rifle"
  85.     FLAME_THROWER = "weapons\\flamethrower\\flamethrower"
  86.     PISTOL = "weapons\\pistol\\pistol"
  87.     PLASMA_RIFLE = "weapons\\plasma rifle\\plasma rifle"
  88.     PLASMA_CANNON = "weapons\\plasma_cannon\\plasma_cannon"
  89.     ROCKET_LAUNCHER = "weapons\\rocket launcher\\rocket launcher"
  90.     SNIPER_RIFLE = "weapons\\sniper rifle\\sniper rifle"
  91.     DISABLED = "nil"
  92.    
  93.     -- first weapon: specify WEAPON NAME (as listed above/UPPERCASE) for each map, example: SHOTGUN
  94.     -- each map in this table, must be separated with a comma
  95.     primary_weapon = {
  96.         beavercreek     =   SHOTGUN,
  97.         bloodgulch      =   PISTOL,
  98.         boardingaction  =   SNIPER_RIFLE,
  99.         carousel        =   ASSAULT_RIFLE,
  100.         chillout        =   PLASMA_RIFLE,
  101.         damnation       =   PISTOL,
  102.         dangercanyon    =   PISTOL,
  103.         deathisland     =   PISTOL,
  104.         gephyrophobia   =   PISTOL,
  105.         hangemhigh      =   PISTOL,
  106.         icefields       =   PISTOL,
  107.         infinity        =   PISTOL,
  108.         longest         =   PISTOL,
  109.         prisoner        =   ROCKET_LAUNCHER,
  110.         putput          =   SHOTGUN,
  111.         ratrace         =   ASSAULT_RIFLE,
  112.         sidewinder      =   PISTOL,
  113.         timberland      =   PISTOL,
  114.         wizard          =   SHOTGUN,
  115.     }
  116.    
  117.     --second weapon: specify WEAPON NAME (as listed above) for each map, example: SHOTGUN
  118.     -- to disable a secondary weapon for this map, use the weapon name: DISABLED  (Do not use for primary weapon)
  119.     -- each map in this table, must be separated with a comma
  120.     secondary_weapon = {
  121.         beavercreek     =   NEEDLER,
  122.         bloodgulch      =   ASSAULT_RIFLE,
  123.         boardingaction  =   PISTOL,
  124.         carousel        =   PLASMA_RIFLE,
  125.         chillout        =   SHOTGUN,
  126.         damnation       =   PLASMA_PISTOL,
  127.         dangercanyon    =   ASSAULT_RIFLE,
  128.         deathisland     =   ASSAULT_RIFLE,
  129.         gephyrophobia   =   ASSAULT_RIFLE,
  130.         hangemhigh      =   SHOTGUN,
  131.         icefields       =   ASSAULT_RIFLE,
  132.         infinity        =   ASSAULT_RIFLE,
  133.         longest         =   PLASMA_PISTOL,
  134.         prisoner        =   DISABLED,
  135.         putput          =   ASSAULT_RIFLE,
  136.         ratrace         =   FLAME_THROWER,
  137.         sidewinder      =   ASSAULT_RIFLE,
  138.         timberland      =   ASSAULT_RIFLE,
  139.         wizard          =   PLASMA_PISTOL,
  140.     }
  141.    
  142.     -- specify the number of frag grenades when player spawns
  143.     -- map name         # count
  144.     -- each map in this table, must be separated with a comma
  145.    
  146.     frag_count = {
  147.         beavercreek     =   2,
  148.         beavercreek     =   0,
  149.         bloodgulch      =   2,
  150.         boardingaction  =   2,
  151.         carousel        =   1,
  152.         chillout        =   0,
  153.         damnation       =   1,
  154.         dangercanyon    =   2,
  155.         deathisland     =   4,
  156.         gephyrophobia   =   2,
  157.         hangemhigh      =   1,
  158.         icefields       =   2,
  159.         infinity        =   4,
  160.         longest         =   1,
  161.         prisoner        =   2,
  162.         putput          =   0,
  163.         ratrace         =   1,
  164.         sidewinder      =   2,
  165.         timberland      =   2,
  166.         wizard          =   1,
  167.     }
  168.    
  169.     -- specify the number of plasma grenades when player spawns
  170.     -- map name         # count
  171.    
  172.     plasma_count = {
  173.         beavercreek     =   0,
  174.         bloodgulch      =   2,
  175.         boardingaction  =   2,
  176.         carousel        =   1,
  177.         chillout        =   0,
  178.         damnation       =   1,
  179.         dangercanyon    =   2,
  180.         deathisland     =   4,
  181.         gephyrophobia   =   2,
  182.         hangemhigh      =   1,
  183.         icefields       =   2,
  184.         infinity        =   4,
  185.         longest         =   1,
  186.         prisoner        =   2,
  187.         putput          =   2,
  188.         ratrace         =   1,
  189.         sidewinder      =   2,
  190.         timberland      =   2,
  191.         wizard          =   1, 
  192.     }
  193.  
  194. end
  195.  
  196. function OnError(Message)
  197.     print(debug.traceback())
  198. end
  199.  
  200. -- Created by H® Shaft
  201. -- Visit Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement