louie999
-
Posts
13 -
Joined
-
Last visited
Posts posted by louie999
-
-
Ok, I think I kinda get how it works now. Tho, how would I update the turrets to newly joined players? should I just get all turret positions and create a turret for specifically the new player?
-
@Citizen, I don't think my safezone script is causing problems, I've tried my turret system with the safezone script turned off and it still gave me the same results. As for the scripts, I've changed it, I had a look at custom weapons(like Buffalo said) and it's also good , though I'm having a problem with this script tho, the turret(custom weapon) spawns fine but it does nothing, it was supposed to shoot when I go inside its colSphere, I've received errors also:
[2015-10-07 17:10:49] WARNING: Turret\Turret.lua:47: Bad argument @ 'getElementData' [Expected element at argument 1, got boolean] [2015-10-07 17:10:49] WARNING: Turret\Turret.lua:48: Bad argument @ 'getElementData' [Expected element at argument 1, got boolean] [2015-10-07 17:10:50] WARNING: Turret\Turret.lua:33: Bad argument @ 'getElementData' [Expected element at argument 1, got boolean] [2015-10-07 17:10:50] WARNING: Turret\Turret.lua:35: Bad argument @ 'setElementData' [Expected element at argument 1, got boolean] [2015-10-07 17:10:50] WARNING: Turret\Turret.lua:36: Bad argument @ 'triggerClientEvent' [Expected element at argument 3, got boolean]
Here's my turret code:
Turret.lua
-- Server Functions function spawnTurret(modelid, x, y, z, weaponType, isProj, range, xOffset, yOffset, zOffset) if (not x) or (not y) or (not z) or (not weaponType) then error("Missing arguments, turret spawning failed") end if not isProj then isProj = false end local range_col = createColSphere(x, y, z, range) local base = createObject(modelid, x, y, z) setElementData(range_col, "turret_part", true) triggerClientEvent(getRootElement(), "onTurretCreate", getRootElement(), x, y, z, base, range_col, weaponType, isProj, range, xOffset, yOffset, zOffset) end addEvent("customizeNewTurret", true) function SetTurretData(turret, base, range_col, weaponType, isProj, range, xOffset, yOffset, zOffset) setElementData(range_col, "parent", turret) setElementData(turret, "turret", true) setElementData(turret, "base", base) setElementData(turret, "range_col", range_col) setElementData(turret, "weaponType", weaponType) setElementData(turret, "isProj", isProj) attachElements(turret, base, xOffset, yOffset, zOffset) end function setTurretTarget(id, md) if getElementData(source, "turret_part") == true then local turret = getElementData(source, "parent") local isProj = getElementData(turret, "isProj") if not isProj then setElementData(turret, "target", id) triggerClientEvent(getRootElement(), "onSetTarget", turret, turret, id) else setElementData(turret, "target", id) triggerClientEvent(getRootElement(), "onSetTarget", turret, turret, id, true) end end end function stopTurret(id, md) if getElementData(source, "turret_part") == true then local turret = getElementData(source, "parent") local turret_target = getElementData(turret, "target") local isProj = getElementData(turret, "isProj") if id == turret_target then if isProj then triggerClientEvent(getRootElement(), "onIdle", turret, turret) else -- TODO end end end end function TurretKill(total_ammo, killer, killerWep, bodyP) if getElementData(killer, "turret") == true then triggerClientEvent(getRootElement(), "onIdle", killer, killer) end end -- Events addEventHandler("onColShapeHit", getRootElement(), setTurretTarget) addEventHandler("onColShapeLeave", getRootElement(), stopTurret) addEventHandler("customizeNewTurret", getRootElement(), SetTurretData) addEventHandler("onPlayerWasted", getRootElement(), TurretKill)
TurretClient.lua
-- Client Functions addEvent("onTurretCreate", true) function createNewTurret(x, y, z, base, range_col, weaponType, isProj, range, xOffset, yOffset, zOffset) local turret = createWeapon(weaponType, x, y, z) setWeaponFlags(turret, "instant_reload", true) triggerServerEvent("customizeNewTurret", turret, turret, base, range_col, weaponType, isProj, range, xOffset, yOffset, zOffset) end addEvent("onSetTarget", true) function SetTurretTarget(turret, target, isProj) if not isProj then setWeaponTarget(turret, target) setTimer(setWeaponState, math.random(1500, 2500), 1, turret, "firing") else --createProjectile() end end addEvent("onIdle", true) function SetTurretIdle(turret, isProj) if not isProj then setWeaponState(turret, "ready") setTimer(setWeaponState, math.random(1000, 2000), 1, turret, "reloading") end end function checkTurret() if getElementData(source, "isProj") == true then cancelEvent() end end -- Events addEventHandler("onTurretCreate", getRootElement(), createNewTurret) addEventHandler("onSetTarget", getRootElement(), SetTurretTarget) addEventHandler("onIdle", getRootElement(), SetTurretIdle) addEventHandler("onClientWeaponFire", getRootElement(), checkTurret)
Help please?
-
So I've been banging my head over this problem for awhile now, I can't seem to fix it. I've created a simple turret system but I can't seem to fix it's problem, it supposed to shoot anyone that comes inside its attack range(a ColSphere), it attacks me when I come inside the ColSphere but the problem is it doesn't do any damage(the shots), the only time the shots will ever do any damage is when I get out of the ColSphere. It's really better explained in a video.
So what happens here basically is:
I go inside the turret's range, it attacks me, rotates correctly, but does no damage. Then when I go out of its range then the shots do damage, doesn't rotate anymore, and basically just sits there shooting. Anyone can help me with this problem? (I will show codes if needed...)
Thanks in advance...
-
Try to give to them a Shotgun or an m4 and you will see hahaha
I already tried M4 and AK47 but it's still the same, as for shotgun, I need the bot to be able to attack mid-long range but a shotgun is only good for short range
-
Thanks guys for the answers, I think I'll go with triggerClientEvent for my safe zone script
-
Ok, so I tried it, I don't know if this happens only to me but the bots are a bit buggy D: they can't shoot accurately, they rarely hit me with guns, the only time I get hit if it's melee combat, even if I gave the bot a Minigun it still can't hit me...(it just keeps shooting at me, but no damage)
-
So I was making a safe zone system, I was just wondering, what is better, triggerClientEvent or setElementData?, my safe zone script works but I don't which of those is more efficient.
-
Yes!, whit this resource you can do it its called "slothbot" https://community.multitheftauto.com/in ... ils&id=672
And see how to use it here https://wiki.multitheftauto.com/wiki/Slothman/Slothbot
Thanks dude, I'll try and use it
-
@Dealman Nice turret
-
Is it possible to make like 5 bots for each alive player that will follow them, attack any enemy players/bots that get close and can also be commanded by the player on where to go?
Are there any functions that I can use to make this idea happen? I've searched in the wiki a bit by haven't found any function for bots...
-
Aye, it sure is possible. It all depends on how you want to set it up. Arguably making sure it's nicely synced between all clients would be the hardest part.
Basically you'll need to use onClientMouseMove to detect whenever the client is aiming the turret left, right, up or down. If you don't want to use the mouse, you can use getKeyState bound to either a timer or the renderer.
I wrote something somewhat similar a while ago, but it was for vehicles - but in general it follows the same principle. I'll see if I can dig it up.
Ah, nice to know it's possible, but could you give me a simple example on how to do it ?
-
Hi,
So, is it possible to script a usable turret? like the missile launchers in that Area69/Restricted area part, is it possible to make those usable by a player to shoot down aircraft/enemies ?
Thanks in advance...
Need help with my custom turret system
in Scripting
Posted
Hmm, I've created a turret(using custom weapons) tho, it's a bit buggy atm ._. Even if I go out of the turret's colSphere it still attacks me D: also, how can I easily make the turret miss sometimes? A minigun turret with 100% accuracy is a bit over powered... I've tried making a table that will contain all elements that enter the turret's colSphere.
Code:
TurretClient.lua