PiscioMastella
Members-
Posts
5 -
Joined
-
Last visited
Details
-
Gang
CaMEMErati
-
Location
Predappio
-
Occupation
Developer
PiscioMastella's Achievements
Vic (3/54)
2
Reputation
-
[Help/Bug?] CreatePed are invincible /w slothbot
PiscioMastella replied to PiscioMastella's topic in Scripting
Guys, thank you all! It seems to work... i didn't know i had to manage the life of bots as i saw they got killed sometimes... Still, i am a developer but never worked on Lua/MTA but i will be glad to help the community if i can -
[Help/Bug?] CreatePed are invincible /w slothbot
PiscioMastella replied to PiscioMastella's topic in Scripting
I have created a test script to try setting it manually... will post the code function registerDamage ( attacker, weapon, bodypart , loss ) local reamainingHealth = getElementHealth(source); outputChatBox("Reamaining health "..reamainingHealth) if(reamainingHealth > 0) then setElementHealth(source, reamainingHealth) else setElementHealth(source, 0) end end addEventHandler ( "onClientPedDamage", getRootElement(), registerDamage ) I also found out this code snippet in the slothbot server functions... can it be bugged? function aidamage(attacker, weapon, bodypart) if (isElement(attacker)) and (getElementData(source, "slothbot") == true) and (getElementData(source, "controller") == getLocalPlayer()) then if (getElementData(source, "target") ~= attacker) and (getElementType(attacker) == "player") then if getPlayerTeam(attacker) == false then if (getElementData(source, "status") ~= "following") then triggerServerEvent("onBotFindEnemy", source, attacker) else setElementData(source, "target", attacker) end elseif (getElementData(source, "BotTeam") ~= getPlayerTeam(attacker)) then if (getElementData(source, "status") ~= "following") then triggerServerEvent("onBotFindEnemy", source, attacker) else setElementData(source, "target", attacker) end else end elseif (getElementData(source, "target") ~= attacker) and (getElementType(attacker) == "ped") then if (getElementData(attacker, "BotTeam") == false) then if (getElementData(source, "status") ~= "following") then triggerServerEvent("onBotFindEnemy", source, attacker) else setElementData(source, "target", attacker) end elseif (getElementData(source, "BotTeam")) ~= (getElementData(attacker, "BotTeam")) then if (getElementData(source, "status") ~= "following") then triggerServerEvent("onBotFindEnemy", source, attacker) else setElementData(source, "target", attacker) end else --same team end end end if (isElement(attacker)) then local theTeam = getElementData(attacker, "BotTeam") if (isElement(theTeam)) then if (getTeamFriendlyFire(theTeam) == false) then if (getElementType(attacker) == "ped") then if (getElementData(attacker, "BotTeam") == theTeam) then cancelEvent() --cancel the event end elseif (getElementType(attacker) == "player") then if getPlayerTeam(attacker) == theTeam then cancelEvent() --cancel the event end end end end end end addEventHandler("onClientPedDamage", getRootElement(), aidamage) PS no way guys, some bots get killed sometimes other bots are invincible... -
[Help/Bug?] CreatePed are invincible /w slothbot
PiscioMastella replied to PiscioMastella's topic in Scripting
Hey, yes i already checked out but i don't have anything like that... but i can tell you that setElementHealth is not working (client side) -
[Help/Bug?] CreatePed are invincible /w slothbot
PiscioMastella replied to PiscioMastella's topic in Scripting
I used the "Code Snippet", sorry. As it seems i can't edit the topic i will repost it! Test vanilla script local weaponIds = {10, 22, 33} local started = false function initBotOnStreets(theResource) if(getResourceName(theResource) ~= "5bserver" or started) then return end outputDebugString("Spawno") createPed(136, 2320, -1737, 0) end addEventHandler ( "onResourceStart", getRootElement(), initBotOnStreets) Slothbot script local skinIds = {136} local weaponIds = { 22, 33} local botTeams = { createTeam("bots1"), createTeam("bots2"), createTeam("bots3") } local locations = { { name = "nearGroveSt", x = 2313, y = -1737, z = 2, botNumer = 5 }, { name = "nearGroveSt1", x = 2320, y = -1737, z = 0, botNumer = 5 }, { name = "nearGroveSt2", x = 2313, y = -1757, z = 0, botNumer = 5 }, { name = "nearGroveSt3", x = 2323, y = -1747, z = 0, botNumer = 5 } } local knownBots = {} local started = false function initBotOnStreets(theResource) if(getResourceName(theResource) ~= "bot-killers" or started) then return end started = true -- createPed(136, 2320, -1737, 0) for key, location in pairs(locations) do for i = 0, location["botNumer"] do local posX = math.random(location["x"] - 20, location["x"] + 20) local posY = math.random(location["y"] - 20, location["y"] + 20) local skinId = skinIds[ math.random( #skinIds ) ] local weaponId = weaponIds[ math.random( #weaponIds ) ] -- local theTeam = botTeams[ math.random( #botTeams ) ] local theTeam = nil local bot = exports.Slothbot:spawnBot(posX, posY, location["z"], 0, skinId, 0, 0, theTeam, weaponId, "hunting", nil) local id = location["name"].."_"..tostring(i) setElementData(bot, "id", id) setElementData(bot, "pascLocName", location["name"]) -- setElementData(bot, "slothbot", true) table.insert(knownBots, {id}) end end end function respawnStreetBot() local id = getElementData(source, "id") if(isValueInTable(knownBots, id, 1)) then local locationName = getElementData(source, "pascLocName") for key, location in pairs(locations) do if(locationName == location["name"]) then outputDebugString("Respawning "..id) local posX = math.random(location["x"] - 50, location["x"] + 50) local posY = math.random(location["y"] - 50, location["y"] + 50) local skinId = skinIds[ math.random( #skinIds ) ] local weaponId = weaponIds[ math.random( #weaponIds ) ] local theTeam = botTeams[ math.random( #botTeams ) ] local bot = exports.Slothbot:spawnBot(posX, posY, location["z"], 0, skinId, 0, 0, theTeam, weaponId, "hunting", nil) setElementData(bot, "id", id) setElementData(bot, "pascLocName", location["name"]) end end end end addEventHandler ( "onResourceStart", getRootElement(), initBotOnStreets) addEvent("onBotWasted", true) addEventHandler ( "onBotWasted", getRootElement(), respawnStreetBot ) Gamemode script local vehiclesToSpawn = {} local spawnpoints = { {-711,957,12.4,90}, {2005,1543,13.5,270}, {2485,-1667,13.3,0}, {-2405,-598,132.6,128}, } local vehicleDestroyTimers = {} local validSkins = {0, 1, 2, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312} local _validSkins = {102,284,249} local playerVehicles = {} local playersTeam = createTeam("Camerati"); local function spawn(player) if player and isElement(player) then local x,y,z,r = unpack(spawnpoints[math.random(1,#spawnpoints)]) --spawnPlayer(player,x+math.random(-3,3),y+math.random(-3,3),z,r,validSkins[math.random(1,#validSkins)],0,0) spawnPlayer(player,2485+(math.random(-10,10)),-1667+(math.random(-10,10)),13.3,0+(math.random(-10,10)),_validSkins[math.random(1,#_validSkins)] ,0,0) fadeCamera(player, true) setCameraTarget(player, player) showChat(player, true) giveWeapon ( player, 10, 200, true ) -- Gives dildo giveWeapon ( player, 31, 200, true ) -- Gives m4 giveWeapon ( player, 22, 200, true ) -- Gives m9 -- setPlayerTeam(player, playersTeam) end end local function onJoin() spawn(source) local accName = getAccountName ( getPlayerAccount ( source ) ) -- get his account name if not isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then outputChatBox("E' entrato un CaMEMErata "..getPlayerName(source)) end end local function onWasted() local t = tonumber(get("playerRespawnTime")) or 5000 setTimer(spawn,(t > 50 and t or 50),1,source) end local function destroyPlayerVehicles() local vehicles = playerVehicles[source] for _,vehicle in ipairs(vehicles) do if isElement(vehicle) then destroyElement(vehicle) end end playerVehicles[source] = nil end local function onEnter(player) local t = tonumber(get("vehicleRespawnTime")) or 60000 source.damageProof = false source.frozen = false local vehicledata = vehiclesToSpawn[source] setTimer(createNewVehicle,(t > 50 and t or 50),1,vehicledata) vehiclesToSpawn[source] = nil if not playerVehicles[player] then playerVehicles[player] = {} addEventHandler("onPlayerQuit",player,destroyPlayerVehicles) end table.insert(playerVehicles[player],source) removeEventHandler("onVehicleEnter",source,onEnter) end local function destroyVehicle(vehicle) if vehicle and isElement(vehicle) and getElementType(vehicle) == "vehicle" then destroyElement(vehicle) end end local function destroyTimer() if vehicleDestroyTimers[source] and isTimer(vehicleDestroyTimers[source]) then killTimer(vehicleDestroyTimers[source]) end removeEventHandler("onVehicleEnter",source,destroyTimer) end local function onExit() local t = tonumber(get("vehicleExpireTime")) or 600000 vehicleDestroyTimers[source] = setTimer(destroyVehicle,(t > 50 and t or 50),1,source) addEventHandler("onVehicleEnter",source,destroyTimer) end function createNewVehicle(vehicledata) local m,x,y,z,r = unpack(vehicledata) local vehicle = Vehicle(m,x,y,z,0,0,r) vehicle.damageProof = true vehicle.frozen = true vehiclesToSpawn[vehicle] = vehicledata addEventHandler("onVehicleEnter",vehicle,onEnter) addEventHandler("onVehicleExit",vehicle,onExit) end local function initScript() resetMapInfo() local players = getElementsByType("player") for _,player in ipairs(players) do spawn(player) end for _,vehicledata in ipairs(vehiclesToSpawn) do createNewVehicle(vehicledata) end addEventHandler("onPlayerJoin",root,onJoin) addEventHandler("onPlayerWasted",root,onWasted) end addEventHandler("onResourceStart",resourceRoot,initScript) PS I also tried using timers to manage the spawn but same problem... Othe two things: - the onClientPedDamage event gets the loss of health correctly - maybe the bug can be connected to the fact that when i go to the area (the spawn is at Groove Street and the bots spawn in the street near the gym) i see bots spawned in a certain position, maybe already fighting, but then disappear and reappear... (i suppose like a rendering problem) -
Hi guys, hope you are all good. I am scripting a pretty simple server based on the "play" gamemode, with a couple of mods and i would like to add some bots around the map (plus event/mission like on Arma/Dayz servers). I was scripting around using slothbot and i saw that sometimes the bots are invincible but i didn't give much importance to that because i had to clean my code. Then, i noticed that every bot was invincible. Thinking of a bug in my code, i removed my mods and tryied to create a ped using createPed but they are still invincible. I noted that the only way to kill them is using the knife (stealthkill). To develop the scripts i use a Windows PC meanwhile i have a "production" server based on Linux and it seems that bots get killed (sometimes) on the server. I also checked around and i aw a similar post but wasn't helpful. Other thing to note is that i do not manipulate health on any gameobject. Steps i tried to fix the bug: - reinstalling MTA - removing all teams from players/bots - deleting all server resources with a MTA clean install, creating only a simple resource to spawn a ped local weaponIds = {10, 22, 33} local started = false function initBotOnStreets(theResource) if(getResourceName(theResource) ~= "5bserver" or started) then return end outputDebugString("Spawno") createPed(136, 2320, -1737, 0) end addEventHandler ( "onResourceStart", getRootElement(), initBotOnStreets) - tried to play GTA and see if i could kill npcs This is my script (using slothbot) local skinIds = {136} local weaponIds = { 22, 33} local botTeams = { createTeam("bots1"), createTeam("bots2"), createTeam("bots3") } local locations = { { name = "nearGroveSt", x = 2313, y = -1737, z = 2, botNumer = 5 }, { name = "nearGroveSt1", x = 2320, y = -1737, z = 0, botNumer = 5 }, { name = "nearGroveSt2", x = 2313, y = -1757, z = 0, botNumer = 5 }, { name = "nearGroveSt3", x = 2323, y = -1747, z = 0, botNumer = 5 } } local knownBots = {} local started = false function initBotOnStreets(theResource) if(getResourceName(theResource) ~= "bot-killers" or started) then return end started = true -- createPed(136, 2320, -1737, 0) for key, location in pairs(locations) do for i = 0, location["botNumer"] do local posX = math.random(location["x"] - 20, location["x"] + 20) local posY = math.random(location["y"] - 20, location["y"] + 20) local skinId = skinIds[ math.random( #skinIds ) ] local weaponId = weaponIds[ math.random( #weaponIds ) ] -- local theTeam = botTeams[ math.random( #botTeams ) ] local theTeam = nil local bot = exports.Slothbot:spawnBot(posX, posY, location["z"], 0, skinId, 0, 0, theTeam, weaponId, "hunting", nil) local id = location["name"].."_"..tostring(i) setElementData(bot, "id", id) setElementData(bot, "pascLocName", location["name"]) -- setElementData(bot, "slothbot", true) table.insert(knownBots, {id}) end end end function respawnStreetBot() local id = getElementData(source, "id") if(isValueInTable(knownBots, id, 1)) then local locationName = getElementData(source, "pascLocName") for key, location in pairs(locations) do if(locationName == location["name"]) then outputDebugString("Respawning "..id) local posX = math.random(location["x"] - 50, location["x"] + 50) local posY = math.random(location["y"] - 50, location["y"] + 50) local skinId = skinIds[ math.random( #skinIds ) ] local weaponId = weaponIds[ math.random( #weaponIds ) ] local theTeam = botTeams[ math.random( #botTeams ) ] local bot = exports.Slothbot:spawnBot(posX, posY, location["z"], 0, skinId, 0, 0, theTeam, weaponId, "hunting", nil) setElementData(bot, "id", id) setElementData(bot, "pascLocName", location["name"]) end end end end addEventHandler ( "onResourceStart", getRootElement(), initBotOnStreets) addEvent("onBotWasted", true) addEventHandler ( "onBotWasted", getRootElement(), respawnStreetBot ) The gamemode script (pretty much the play gamemode with two or three lines changed): local vehiclesToSpawn = {} local spawnpoints = { {-711,957,12.4,90}, {2005,1543,13.5,270}, {2485,-1667,13.3,0}, {-2405,-598,132.6,128}, } local vehicleDestroyTimers = {} local validSkins = {0, 1, 2, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312} local _validSkins = {102,284,249} local playerVehicles = {} local playersTeam = createTeam("Camerati"); local function spawn(player) if player and isElement(player) then local x,y,z,r = unpack(spawnpoints[math.random(1,#spawnpoints)]) --spawnPlayer(player,x+math.random(-3,3),y+math.random(-3,3),z,r,validSkins[math.random(1,#validSkins)],0,0) spawnPlayer(player,2485+(math.random(-10,10)),-1667+(math.random(-10,10)),13.3,0+(math.random(-10,10)),_validSkins[math.random(1,#_validSkins)] ,0,0) fadeCamera(player, true) setCameraTarget(player, player) showChat(player, true) giveWeapon ( player, 10, 200, true ) -- Gives dildo giveWeapon ( player, 31, 200, true ) -- Gives m4 giveWeapon ( player, 22, 200, true ) -- Gives m9 -- setPlayerTeam(player, playersTeam) end end local function onJoin() spawn(source) local accName = getAccountName ( getPlayerAccount ( source ) ) -- get his account name if not isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then outputChatBox("E' entrato un CaMEMErata "..getPlayerName(source)) end end local function onWasted() local t = tonumber(get("playerRespawnTime")) or 5000 setTimer(spawn,(t > 50 and t or 50),1,source) end local function destroyPlayerVehicles() local vehicles = playerVehicles[source] for _,vehicle in ipairs(vehicles) do if isElement(vehicle) then destroyElement(vehicle) end end playerVehicles[source] = nil end local function onEnter(player) local t = tonumber(get("vehicleRespawnTime")) or 60000 source.damageProof = false source.frozen = false local vehicledata = vehiclesToSpawn[source] setTimer(createNewVehicle,(t > 50 and t or 50),1,vehicledata) vehiclesToSpawn[source] = nil if not playerVehicles[player] then playerVehicles[player] = {} addEventHandler("onPlayerQuit",player,destroyPlayerVehicles) end table.insert(playerVehicles[player],source) removeEventHandler("onVehicleEnter",source,onEnter) end local function destroyVehicle(vehicle) if vehicle and isElement(vehicle) and getElementType(vehicle) == "vehicle" then destroyElement(vehicle) end end local function destroyTimer() if vehicleDestroyTimers[source] and isTimer(vehicleDestroyTimers[source]) then killTimer(vehicleDestroyTimers[source]) end removeEventHandler("onVehicleEnter",source,destroyTimer) end local function onExit() local t = tonumber(get("vehicleExpireTime")) or 600000 vehicleDestroyTimers[source] = setTimer(destroyVehicle,(t > 50 and t or 50),1,source) addEventHandler("onVehicleEnter",source,destroyTimer) end function createNewVehicle(vehicledata) local m,x,y,z,r = unpack(vehicledata) local vehicle = Vehicle(m,x,y,z,0,0,r) vehicle.damageProof = true vehicle.frozen = true vehiclesToSpawn[vehicle] = vehicledata addEventHandler("onVehicleEnter",vehicle,onEnter) addEventHandler("onVehicleExit",vehicle,onExit) end local function initScript() resetMapInfo() local players = getElementsByType("player") for _,player in ipairs(players) do spawn(player) end for _,vehicledata in ipairs(vehiclesToSpawn) do createNewVehicle(vehicledata) end addEventHandler("onPlayerJoin",root,onJoin) addEventHandler("onPlayerWasted",root,onWasted) end addEventHandler("onResourceStart",resourceRoot,initScript) Does anyone have any idea about this? I have lost around 10h behind this without any success...