Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Server
- local sCasingArray = {}
- function gCreateEjectedCase(lArray)
- sCasingArray = lArray
- for i,v in ipairs(sCasingArray) do
- local casingsObject = createObject(2061, sCasingArray[i][1], sCasingArray[i][2], sCasingArray[i][3]) -- Would need to be replaced with the owl object creation function, object name would be renamed to the serial.
- setObjectScale(casingsObject, 0.2)
- end
- end
- addEvent("ejectCase", true)
- addEventHandler("ejectCase", resourceRoot, gCreateEjectedCase)
- function gCreateWeapon(player, command, value, ammo, cases)
- if value ~= nil and ammo ~= nil then
- cases = tonumber(cases)
- if cases == 1 or cases == nil or cases == 0 then -- General idea, however, the admin command or the GUI should be changed to add this parameter.
- giveWeapon(player, tonumber(value), ammo, true)
- if cases == 1 then
- setElementData(player, "holdingCasesGun", 1) -- Would not be this way if weapons are elements on owl. A variable & function would be added to the weapons class.
- else
- setElementData(player, "holdingCasesGun", 0)
- end
- else
- outputChatBox("Cases must be either 1 or 0.")
- end
- else
- outputChatBox("USAGE: /creategun <ID> <ammo> <Does Not Eject Casings = 0 or 1, default = 0>", player)
- end
- end
- addCommandHandler("creategun", gCreateWeapon)
- -- Weapon stats would need to be saved as boolean in the database. Slight modification of items res may be required so that administrators can change weapons to automatically eject cases or not.
- -- I'm assuming Owl's weapons are stored as elements, and hence setElementData would be stored in each weapon's object's variables themselves rather than an unefficient setElementData which updates to all players.
- --Client
- Casing = {}
- Casing.__index = Casing
- prepTimer = nil -- Timer for calling the server trigger and garbage collection.
- sentArray = {} -- Array to be sent to server, one server trigger is better than looping or sending repetitive ones.
- curArray = {} -- Current array to contain the object list of all cases created (Don't know how to iterate through objects under the Casings class, would appreciate input).
- function Casing.create(x, y, z)
- if x ~= nil and y ~= nil and z ~= nil then -- Check valid co-ordinations.
- local _casing = {}
- setmetatable(_casing,Casing) -- Indexing the class.
- _casing.object = createObject(2061, x, y, z) -- Informal object creation on client side.
- curArray[#curArray+1] = _casing.object -- Assign the object element to the array.
- setObjectScale(_casing.object, 0.2) -- Set scale smaller.
- _casing.pos = {x, y, z} -- Store position.
- _casing.time = getTickCount() -- To be later used to ensure the time > 10 seconds since the last shot.
- sentArray[#sentArray+1] = {x,y,z} -- Co-ords in the array for the server sided creation.
- return _casing -- Returning the object. S/e.
- else
- outputDebugString("Res: ejectCasings | Error: Could not produce a casing due to invalid co-ords.")
- return false
- end
- end
- function Casing:recentlyFired(curTickCount)
- if curTickCount - self.time < 10000 then
- return true
- else
- return false
- end
- end
- function getSideOfPlayer()
- return localPlayer.matrix.position + localPlayer.matrix.right * math.random(.2,3)
- end
- function gEjectCases(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement)
- local currentGun = getPedWeapon(localPlayer)
- local casesEjected = getElementData(localPlayer, "holdingCasesGun") -- Would be different in Owl scripts assuming Owl's weapon scripts have a class.
- if casesEjected ~= 1 then
- local pVector = getSideOfPlayer() -- Getting the right side of the player.
- local x,y,z = pVector:getX(),pVector:getY(),pVector:getZ()
- z = getGroundPosition(x,y,z) -- Placing bullets on the ground.
- caseObj = Casing.create(x,y,z) -- Cannot be local, as it cannot be passed as an arg through setTimer.
- if isTimer(prepTimer) then
- killTimer(prepTimer) -- Prevent multiple timers.
- end
- prepTimer = setTimer(gPrepareCases, 10000, 1)
- end
- end
- addEventHandler("onClientPlayerWeaponFire", root, gEjectCases)
- function gPrepareCases()
- if caseObj:recentlyFired(getTickCount()) == false then
- triggerServerEvent("ejectCase", resourceRoot, sentArray)
- sentArray = {} -- Flush array with current objects.
- for i,v in ipairs(curArray) do
- destroyElement(curArray[i]) -- Don't know how to destroy all objects in a class. Would appreciate input on this for proper garbage collection.
- end
- curArray = {} -- Clear current array.
- else
- if isTimer(prepTimer) then
- killTimer(prepTimer)
- end
- setTimer(gPrepareCases, 10000, 1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement