-
Posts
200 -
Joined
-
Last visited
Everything posted by Cassandra
-
Alright managed to sync the ped but I still have a problem. The bot shoots in an awkward angle and I believe it's happening because of the animation or something. The rotation, the bot is facing is alright but the bot doesn't shoot at the player's body location. Server: local id = 0 addCommandHandler("createbot", function(player, command, skin) skin = skin or 28 local x, y, z = getElementPosition(player) id = id + 1 local bot = createPed(28, x, y, z) setElementData(bot, "bot.id", id) setElementData(bot, "bot.mode", "none") setElementData(bot, "bot.action", "none") setElementData(bot, "bot.animation", "none") setElementData(bot, "bot.clear", false) setElementData(bot, "bot.target", player) outputChatBox("Bot Created: " .. tostring(id), player) end) addCommandHandler("givewep", function(player, command, botid, weapon) botid = botid or 1 weapon = weapon or "Knife" local bot = botGet(botid) or outputChatBox("Invalid Bot.", player) local weaponid = getWeaponIDFromName(weapon) or outputChatBox("Invalid Weapon.", player) if(bot and weaponid) then giveWeapon(bot, weaponid, 99999, true) outputChatBox("Bot " .. tostring(botid) .. " given weapon " .. weapon, player) end end) addCommandHandler("setfollow", function(player, command, botid) botid = botid or 1 local bot = botGet(botid) or outputChatBox("Invalid Bot.", player) local x, y, z = getElementPosition(player) local rot = getPedRotation(player) if(bot) then setPedAnimation(bot) setElementData(bot, "bot.mode", "follow") outputChatBox("Bot " .. tostring(botid) .. " set to follow you", player) end end) addEventHandler("onResourceStart", resourceRoot, function() setTimer( function() local botid local px, py, pz local x, y, z local rot local dist local mode local action local animation local clear local target local health for _, bot in ipairs(getElementsByType("ped")) do botid = getElementData(bot, "bot.id") if(botid ~= false) then mode = getElementData(bot, "bot.mode") action = getElementData(bot, "bot.action") animation = getElementData(bot, "bot.animation") clear = getElementData(bot, "bot.clear") target = getElementData(bot, "bot.target") px, py, pz = getElementPosition(target) x, y, z = getElementPosition(bot) rot = findRotation(x, y, px, py) dist = getDistanceBetweenPoints3D(x, y, z, px, py, pz) health = getElementHealth(bot) setPedRotation(bot, rot) --setPedLookAt(bot, x, y, z) if((action == "none") and (animation ~= "none")) then outputChatBox("Playing no animation", target) setElementData(bot, "bot.animation", "none") setPedAnimation(bot) elseif(action == "run") then outputChatBox("Playing running animation", target) setElementData(bot, "bot.animation", "run") setPedAnimation(bot, "ped", "run_civi") elseif(action == "sprint") then outputChatBox("Playing sprinting animation", target) setElementData(bot, "bot.animation", "sprint") setPedAnimation(bot, "ped", "sprint_civi") end if(mode == "follow") then if(dist > 5 and dist < 30) then -- Running Range outputChatBox("Should Run", target) if(clear) then -- Path Clear outputChatBox("Running!", target) setElementData(bot, "bot.action", "run") end elseif(dist > 30) then outputChatBox("Should Sprint", target) if(clear) then outputChatBox("Sprinting!", target) setElementData(bot, "bot.action", "sprint") end else outputChatBox("Should shoot", target) setElementData(bot, "bot.action", "none") if(getPedWeapon(bot) > 0) then triggerClientEvent("cFire", bot) end end end end end end , 50, 0) end) function botGet(botid) for _, bot in ipairs(getElementsByType("ped")) do if(getElementData(bot, "bot.id") == tonumber(botid)) then return bot end end return nil end function findRotation(x1, y1, x2, y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end; return t; end Client: --[[addEventHandler("onClientPedDamage", root, function(attacker, weapon, bodypart) if(getElementData(attacker, "bot.id") ~= false) then if(weapon == getWeaponIDFromName("Knife")) then if(bodypart == 9) then setPedHeadless(source, true) else setElementHealth(source, getElementHealth(source) - 40) end end else if(bodypart == 9) then setPedHeadless(source, true) setElementHealth(source, 0) end end cancelEvent() end)--]] addEventHandler("onClientRender", root, function() local botid local px, py, pz local x, y, z for _, bot in ipairs(getElementsByType("ped")) do botid = getElementData(bot, "bot.id") px, py, pz = getElementPosition(localPlayer) x, y, z = getElementPosition(bot) if(botid ~= false) then local clearpath = isLineOfSightClear(px, py, pz, x, y, z, true, true, false, true, false, true, false) if(clearpath == false) then setElementData(bot, "bot.clear", false) else setElementData(bot, "bot.clear", true) end end end end) addEvent("cFire", true) addEventHandler("cFire", root, function() setPedControlState(source, "fire", true) setTimer(setPedControlState, 800, 1, source, "fire", false) end)
-
Because greater than 0 equals any number which is greater than 0. Even 100000000. You have to set it less than or equals to.
-
setTimer( function (player) for _, player in ipairs(getElementsByType("player")) do local getPoints = tonumber(getElementData(player,'arrestPoints')) if (getPoints>0) then setPlayerWantedLevel(player,1) elseif (getPoints>300) then setPlayerWantedLevel(player,2) elseif (getPoints>900) then setPlayerWantedLevel(player,3) elseif (getPoints>1500) then setPlayerWantedLevel(player,4) elseif (getPoints>2300) then setPlayerWantedLevel(player,5) elseif (getPoints>2750) then setPlayerWantedLevel(player,6) end end end, 1000, 0 ) getElementData returns a string so you have to convert it to a number.
-
Sorry for posting repeatedly but how do you sync ped's control state?
-
Yes, but I would keep that on the same function.
-
Could you possibly show me an example/point me on the right direction on how to sync this? addEventHandler("onClientRender", root, function() local botid for _, bot in ipairs(getElementsByType("ped")) do botid = getElementData(bot, "bot.id") if(botid ~= false) then local px, py, pz = getElementPosition(localPlayer) local x, y, z = getElementPosition(bot) local rot = findRotation(x, y, px, py) local dist = getDistanceBetweenPoints3D(x, y, z, px, py, pz) local mode = getElementData(bot, "bot.mode") local running = getPedControlState(bot, "forwards") local sprinting = getPedControlState(bot, "sprint") local jumping = getPedControlState(bot, "jump") local health = getElementHealth(bot) local clearpath = isLineOfSightClear(px, py, pz, x, y, z, true, true, false, true, false, true, false) if((clearpath == false) and (jumping == false) and ((getTickCount() - lastjumptime) < (500/getGameSpeed()))) then outputChatBox("Jump!") setPedAnimation(bot) setPedControlState(bot, "jump", true) end if((getTickCount() - lastjumptime) > (500/getGameSpeed())) then setPedControlState(bot, "jump", false) lastjumptime = getTickCount() end if(health < 1) then setTimer(destroyElement, 2000, 1, bot) end if(mode == "follow") then setPedRotation(bot, rot) setPedLookAt(bot, px, py, pz) -- Sprinting = Running and Sprinting -- Running = Running if(dist < 1) then -- If they are too close. if((running) or (running and sprinting)) then -- If they are either running or sprinting. --Stop them. outputChatBox("Should stop") setPedControlState(bot, "sprint", false) setPedControlState(bot, "forwards", false) end setPedControlState(bot, "fire", true) elseif(dist > 15.0) then -- If they are too far. if(sprinting == false) then -- If they are not sprinting. --Sprint! outputChatBox("Should sprint.") setPedControlState(bot, "sprint", true) setPedControlState(bot, "forwards", true) end setPedControlState(bot, "fire", false) else -- If they are not too close or too far. if((running and sprinting) or (running == false)) then -- If they are sprinting or idle. --Run! outputChatBox("Should run.") setPedControlState(bot, "sprint", false) setPedControlState(bot, "forwards", true) end setPedControlState(bot, "fire", false) end end end end end)
-
I know but how will it sync between other players if the code is executed clientside only?
-
Post your problems in the support section which is this: viewforum.php?f=105 This section is for Non-Help MTA Discussions.
-
Set the damage property of the weapon using the function above.
-
getPedControlState But isn't it clientside?
-
Maybe you can use callRemote and transfer the data on a web site and fetchRemote the data from that website to all other servers.
-
Well, I want to sync the ped's position, rotation, animation and control state. How will I go about doing that?
-
you know any? I have some when playing with shaders.
-
As well as custom shaders.
-
Your code didn't make any sense. function givePlayerItem(player, cmd, target, item, amount) local targetid = getPlayerFromName(target) or outputChatBox("Player not found", player) setElementData(targetid, "item." .. item, amount) end addCommandHandler ("giveitem", givePlayerItem) Check out the MTA Wiki. It helps.
-
Thanks guys, I've updated the link.
-
Vehicle Saver This is a simple resource which allows you to create vehicles which is saved and loaded and does not conflict with the gamemode resource and other vehicles created using createVehicle. It has two commands and those are /createveh and /removeveh which are used to create or remove vehicle. /createveh takes the model as the argument while /removeveh takes the id of the vehicle needed to be removed. P.S. This is my first script. Download Link: https://community.multitheftauto.com/index.php?p= ... includes=1
-
Well, it says Does it still supports vehicles or objects?
-
Is there any way? Basically, I am creating a vehicle which will move from one point to another and will be invisible. I want the camera to be attached on that vehicle so if the vehicle moves, the camera moves along with it.
-
It is not like a real timer, your onClientRender is your timer. getTickCount() is just a value you can use. Every time your pc creates a render value, it request the join machine time. This is a Sample with frames, not tickCount. But tickCount is preciser in scripting. local startFrame = 0 local frame = 0 frame = frame + 1 if frame-startFrame > 3 then --no 1 - 0 = 1 startFrame = frame end outputChatBox(frame) --1 --------- frame = frame + 1 if frame-startFrame > 3 then -- no 2 - 0 = 2 startFrame = frame end outputChatBox(frame) --2 --------- frame = frame + 1 if frame-startFrame > 3 then -- no 3 - 0 = 3 startFrame = frame end outputChatBox(frame) --3 --------- frame = frame + 1 if frame-startFrame > 3 then -- yes!!!!!! 4 - 0 = 4 startFrame = frame end outputChatBox(frame) --4 --------- and now: frame = frame + 1 if frame-startFrame > 3 then -- no the som is now: 5 - 4 = -3 .. is -1 higher than 3? startFrame = frame end outputChatBox(frame .. " " .. startFrame) --5 4 --------- Woah thanks for the explanation. Finally understood how it works. Kudos to you.
-
And to start it I will use this code right? lastjumptime = getTickCount()
-
Gotcha. How would I go about checking if the timer is running or not?
-
Thanks a lot. I will try it and post the results. Edit: What's the 300 for?
-
Well thanks for that. How can I fix the timer problem?
-
I don't understand.