Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Weapon Spawn and Movement Detection --
- -- List of weapons we should print messages for when they spawn or move (enter as tagnames with quotes around the name and commas in between)
- monitored = {"weapons\\rocket launcher\\rocket launcher",
- }
- --[[
- List of weapon tags:
- weapons\\assault rifle\\assault rifle
- weapons\\ball\\ball
- weapons\\flag\\flag
- weapons\\flamethrower\\flamethrower
- weapons\\gravity rifle\\gravity rifle
- weapons\\needler\\mp_needler
- weapons\\pistol\\pistol
- weapons\\plasma pistol\\plasma pistol
- weapons\\plasma rifle\\plasma rifle
- weapons\\plasma_cannon\\plasma_cannon
- weapons\\rocket launcher\\rocket launcher
- weapons\\shotgun\\shotgun
- weapons\\sniper rifle\\sniper rifle
- --]]
- message_begin_game = false -- Set this to true if you want the spawn message to print when the weapons spawn at the beginning of the game (I've assumed you wouldn't want that, but I'll give you the option)
- spawn_message = " has spawned." -- Message printed when a weapon has spawned (begins with the name of the weapon)
- move_message = " has moved." -- Message printed when a weapon has moved (begins with the name of the weapon)
- function GetRequiredVersion()
- return 200
- end
- function OnScriptLoad(processId, game, persistent)
- end
- --[[
- function OnScriptUnload()
- end
- --]]
- function OnNewGame(map)
- if not message_begin_game then
- print_message = false
- registertimer(1000, "MessageDelay")
- end
- info = {} -- Stores information about the weapons we're tracking
- movement_timer = registertimer(100, "MovementTimer")
- end
- function MessageDelay(id, count)
- print_message = true
- return false
- end
- function MovementTimer(id, count)
- for objId,data in pairs(info) do
- local m_object = getobject(objId) -- check if the object still exists
- if m_object then
- if not info[objId].held then -- We will stop monitoring this weapon once it has been held
- -- Check if a player is holding this weapon
- for i = 0,15 do
- local m_player = getplayer(i)
- if m_player then -- If this player exists...
- local player_objId = readdword(m_player, 0x34)
- local m_object = getobject(player_objId)
- if m_object then -- If this player is alive...
- for slot = 0,3 do
- local weapId = readdword(m_object, 0x2F8 + (slot * 4))
- if weapId == objId then
- info[objId].held = true
- break
- end
- end
- if info[objId].held then break end
- end
- end
- end
- if not info[objId].held then -- Check again to make sure the weapon isn't being held
- if not info[objId].moved then -- If the weapon hasn't yet moved...
- -- Check if the weapon has moved
- local x, y, z = getobjectcoords(objId)
- local cushion = 0.2 -- Allow the weapon to move within a very small cushion before we send a message
- local dist = math.sqrt((x - data.spawn_x) ^ 2 + (y - data.spawn_y) ^ 2 + (z - data.spawn_z) ^ 2)
- if dist >= cushion then
- info[objId].moved = true
- say(capitalize(aoran(info[objId].name)) .. " " .. info[objId].name .. move_message)
- end
- end
- end
- end
- else
- info[objId] = nil -- If this object doesn't exist, nullify its key in the info table
- end
- end
- return true
- end
- function OnGameEnd(stage)
- if stage == 1 then
- removetimer(movement_timer)
- end
- end
- function OnObjectCreation(objId)
- local m_object = getobject(objId)
- local mapId = readdword(m_object)
- local tagname, tagtype = gettaginfo(mapId) -- Get the tagname and tagtype from the mapId
- if tagtype == "weap" then -- If this is a weapon...
- if table.find(monitored, tagname) then -- If this weapon tagname is in the monitored table...
- local weap_name = getnamefromtag(tagname)
- if print_message then
- say(capitalize(aoran(weap_name)) .. " " .. weap_name .. spawn_message) -- Say the message
- end
- -- Store information about this weapon
- local x, y, z = getobjectcoords(objId) -- Coordinates
- info[objId] = {}
- info[objId].spawn_x = x
- info[objId].spawn_y = y
- info[objId].spawn_z = z
- info[objId].name = weap_name -- Store the name of the weapon
- info[objId].moved = false -- Becomes true if the weapon moves from its spawn location
- info[objId].held = false -- Becomes true if a player picks up this weapon
- end
- end
- end
- -- A function to determine if "a" or "an" should be used; it's not perfect but it will work in this case
- function aoran(next_word)
- local vowels = {"A", "E", "I", "O", "U", "a", "e", "i", "o", "u"}
- local first = string.sub(next_word, 1, 1)
- if table.find(vowels, first) then
- return "an"
- else
- return "a"
- end
- end
- function capitalize(str)
- local first = string.sub(str, 1, 1)
- local rest = string.sub(str, 2, string.len(str))
- return string.upper(first) .. rest
- end
- function getnamefromtag(tag)
- if tag == "weapons\\assault rifle\\assault rifle" then
- return "Assault Rifle"
- elseif tag == "weapons\\ball\\ball" then
- return "Oddball"
- elseif tag == "weapons\\flag\\flag" then
- return "Flag"
- elseif tag == "weapons\\flamethrower\\flamethrower" then
- return "Flamethrower"
- elseif tag == "weapons\\gravity rifle\\gravity rifle" then
- return "Gravity Rifle"
- elseif tag == "weapons\\needler\\mp_needler" then
- return "Needler"
- elseif tag == "weapons\\pistol\\pistol" then
- return "Pistol"
- elseif tag == "weapons\\plasma pistol\\plasma pistol" then
- return "Plasma Pistol"
- elseif tag == "weapons\\plasma rifle\\plasma rifle" then
- return "Plasma Rifle"
- elseif tag == "weapons\\plasma_cannon\\plasma_cannon" then
- return "Fuel Rod"
- elseif tag == "weapons\\rocket launcher\\rocket launcher" then
- return "Rocket Launcher"
- elseif tag == "weapons\\shotgun\\shotgun" then
- return "Shotgun"
- elseif tag == "weapons\\sniper rifle\\sniper rifle" then
- return "Sniper Rifle"
- end
- end
- function table.find(t, val)
- for k,v in pairs(t) do
- if v == val then
- return k
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement