Jump to content

MTA.Castiel

Members
  • Posts

    30
  • Joined

  • Last visited

Everything posted by MTA.Castiel

  1. Good day, community. I've tried getting our projectiles ( rocket_left and rocket_right ) to fire directly to the crosshair by manipulating it's velocity with the crosshair's on-screen positioning values. Then ran into some "vector" errors. So I restored the code back to working / test functionality as seen below. The question is, which would be the best way to achieve something like this? The screen positioning for the crosshair is a Vector2, while the projectile's velocity arguments require Vector3 if I'm not mistaken. I haven't really got an idea of how to work out the math on this. Quite a challenge, this one. So any bit of recommendations will be appreciated Reasoning: Having the rockets focused to the exact crosshair point would allow for better accuracy when firing at targets close range, or where ever the crosshair hits. -- mark them function vCrosshair( ) if (localPlayer.vehicle) then local matrix = localPlayer.vehicle.matrix local startPos = matrix:transformPosition( 0, 0, 0 ) local endPos = matrix:transformPosition( 0, 200, 0 ) local hit, x, y, z = processLineOfSight( startPos, endPos, true, true, true, false, false, false, false, true, localPlayer.vehicle ) local hitPos = Vector3( x, y, z ) local endPos = hit and hitPos or endPos local csrPos = Vector2( getScreenFromWorldPosition ( endPos ) ) if (csrPos.length > 0) then if (hit) then dxDrawText( "•", csrPos - Vector2 ( 1/2, 1/2), 1, 1, tocolor( 0, 255, 0, 255 ), 2, "default-bold" ) else dxDrawText( "•", csrPos - Vector2 ( 1/2, 1/2), 1, 1, tocolor( 0, 255, 0 , 255 ), 2, "default-bold" ) end end end end addEventHandler( "onClientRender", root, vCrosshair ) -- send the gifts from uncle sam function vMissile( ) local vehicle = localPlayer.vehicle if (vehicle) then local matrix = localPlayer.vehicle.matrix local startPos = matrix:transformPosition( 0, 0, 0 ) local endPos = matrix:transformPosition( 0, 200, 0 ) local hit, x, y, z = processLineOfSight( startPos, endPos, true, true, true, false, false, false, false, true, localPlayer.vehicle ) local hitPos = Vector3( x, y, z ) local endPos = hit and hitPos or endPos local csrPos = Vector2( getScreenFromWorldPosition ( endPos ) ) local rx, ry, rz = rotation local vx, vy, vz = velocity local rocket_left = createProjectile( vehicle, 19, vehicle.matrix.position + vehicle.matrix.right * - 3, rotation, velocity ) local rocket_right = createProjectile( vehicle, 19, vehicle.matrix.position + vehicle.matrix.right * 3, rotation, velocity ) end end addCommandHandler( "shoot", vMissile )
  2. It sounds like it could actually work but I'm getting an error on the "vehicleDamage" function. When Bobby's vehicle is shot, it shows - Bad argument @ 'getElementType' [Expected element at argument 1, got number '30']
  3. Hello community. I need to create some type of feature that rewards a player (attacker) for every kill. But before i could do so, I ran into a little issue, I need to figure out how to properly detect the attacker's source. Example: If i were to directly shoot and kill a player named Bobby with an Ak-47, script should return: Castiel killed Bobby (Ak-47) (Torso) (attacker element found) The Problem: If Bobby's sitting in a vehicle (driver seat or passanger seat) and i directly shoot the vehicle instead of Bobby (PED), the vehicle explodes, kills Bobbly. script returns: Bobby died. (attacker element not found) What would be the best way to detect the attacker in such an event, if even possible? function playerWasted_reward ( ammo, attacker, weapon, bodypart ) if ( attacker ) and ( attacker ~= source ) then local tempString if ( getElementType ( attacker ) == "player" ) then tempString = getPlayerName ( attacker ).." killed "..getPlayerName ( source ).." ("..getWeaponNameFromID ( weapon )..")" elseif ( getElementType ( attacker ) == "vehicle" ) then tempString = getPlayerName ( getVehicleController ( attacker ) ).." killed "..getPlayerName ( source ).." ("..getWeaponNameFromID ( weapon )..")" end if ( bodypart == 9 ) then -- give a special reward for headshots tempString = tempString.." (Headshot)" else -- give him / her a normal reward tempString = tempString.." ("..getBodyPartName ( bodypart )..")" end outputChatBox ( tempString ) -- if no attacker found then else else outputChatBox ( getPlayerName ( source ) .. " died." ) end end addEventHandler( "onPlayerWasted", getRootElement( ), playerWasted_reward )
  4. Hi there, I'm trying to trigger a client side event for every team player but excluding myself, within the team. I've tried a bunch of things, can't seem to figure it out at this point. The code we're using today is only intended for test purposes. Our client event "runOurClientEvent" is currently being triggered for everyone in the team, including myself. function teamChatZm( message, messageType ) local thePlayer = getPlayerName( source ) if messageType == 2 then -- Teamsay local playerTeam = getPlayerTeam( source ) if ( playerTeam ) then local teamPlayers = getPlayersInTeam( playerTeam ) cancelEvent() outputChatBox( "*Message type: " .. messageType .. " from: " .. thePlayer ) outputChatBox( "Castiel has triggered a client side event.", teamPlayers, 0, 255, 0, true ) -- trigger an event for the other team players only if ( teamPlayers[source] == source ) then return else triggerClientEvent ( "runOurClientEvent", root ) end end end end addEventHandler("onPlayerChat", root, teamChatZm)
  5. @AngelAlpha This one has done the trick, i just needed to add the cancelEvent ( ) onto it like so: Many many thanks! ? -- Blank message patch if ( message:gsub(" ", "") == "" ) then outputChatBox( "Invalid text input." ) cancelEvent ( ) return end
  6. Good afternoon, I'm trying to remove blank text (space) inputs from our chats. The code we're modifying today is used in the 'Freeroam' resource (server-side). The main aim is to use a minimum of 1 character per message, and so if it's not a letter or a digit or a symbol, we don't output the message. I had trouble with the image link but I'll text the example below: 1. Example of the correct output message > CHAT: Castiel: Hello World. 2. Example of the blank output (space/s) > CHAT: Castiel: 3. Example of (spaces) used between words > CHAT: Castiel: Hello World . If someone could assist me on this one, i would really appreciate it. ? addEventHandler('onPlayerChat', root, function(msg, type) -- blank message patch if ( msg == " " ) then outputChatBox( "Invalid text input." ) return end if type == 0 then cancelEvent() if not hasObjectPermissionTo(source, "command.kick") and not hasObjectPermissionTo(source, "command.mute") then if chatTime[source] and chatTime[source] + tonumber(get("*chat/mainChatDelay")) > getTickCount() then outputChatBox("Stop spamming main chat!", source, 255, 0, 0) return else chatTime[source] = getTickCount() end if get("*chat/blockRepeatMessages") == "true" and lastChatMessage[source] and lastChatMessage[source] == msg then outputChatBox("Stop repeating yourself!", source, 255, 0, 0) return else lastChatMessage[source] = msg end end if isElement(source) then local r, g, b = getPlayerNametagColor(source) outputChatBox(getPlayerName(source) .. ': #FFFFFF' .. stripHex(msg), root, r, g, b, true) outputServerLog( "CHAT: " .. getPlayerName(source) .. ": " .. msg ) end end end )
  7. Hi Shady, thanks for getting back to me on this one, much appreciated. ? I've tested the code it but it still hasn't done the trick. I have however managed to get it working with a different method, i just needed more time to work it out. --------------------------- -- Head Moving --------------------------- local scrX, scrY = guiGetScreenSize( ) setTimer( function( ) if not ( getKeyState ( "mouse2" ) == true ) then local x, y, z = getWorldFromScreenPosition( scrX / 2, scrY / 2, 15 ) setPedLookAt( localPlayer, x, y, z, 3000, 1000, nil ) end end, 100, 0 ) function focusOnTarget( button, press ) if isPedInVehicle( localPlayer ) then return end if ( press and button == "mouse2" ) then setPedLookAt( localPlayer, 0, 0, 0, 0, 0, nil ) end end addEventHandler( "onClientKey", root, focusOnTarget )
  8. With this simple bit of code, we are able to move our ped's head ?? in the direction we choose to move the mouse ?️. The only thing i dont like is how the head moves while the ped is aiming around. I need to force the head to look at where i'm aiming. I tried using the weapon muzzle position as the forced lookAt position but i'm not sure why it's not working. --------------------------- -- Head Moving --------------------------- local scrX, scrY = guiGetScreenSize ( ) setTimer( function() if not isPedAiming(localPlayer) then local x, y, z = getWorldFromScreenPosition( scrX / 2, scrY / 2, 15) setPedLookAt(localPlayer, x, y, z, 3000, 1000, nil) else local sx, sy, sz = getPedWeaponMuzzlePosition(localPlayer) setPedLookAt(localPlayer, sx, sy, sz, 0, 0, nil) end end, 120, 0) --------------------------- -- Functions --------------------------- function isPedAiming (thePedToCheck) if isElement(thePedToCheck) then if getElementType(thePedToCheck) == "player" or getElementType(thePedToCheck) == "ped" then if getPedTask(thePedToCheck, "secondary", 0) == "TASK_SIMPLE_USE_GUN" or isPedDoingGangDriveby(thePedToCheck) then return true end end end return false end
  9. Thats perfect, many thanks Shady. ?
  10. Hi there, ? how do we calculate the distance from a player to the ground? - In this case for example, we're flying a helicopter so the ground may be anything below us such as the roof top of a tall building or a mountain top or a hill. In the example code below when i output the 'z' coordinate it doesn't compensate for anything else below the player, rather acts as a measurement of how high or low i seem to be from 0 (water level). function outputGroundDis ( ) local x, y, z = getElementPosition ( localPlayer ) outputChatBox ( math.floor ( z ) ) if math.floor ( z ) == 100 then --triggerEvent ( "heightWarning", localPlayer ) outputChatBox ( "event triggered" ) end end setTimer ( outputGroundDis, 1000, 0 )
  11. Alright that solved my problem ? thank you AngelAlpha ?
  12. Hi, there seems to be a problem triggering the server event from the client side (gui button). - "Bad source element @'triggerServerEvent' [element is clientside]" I previously had it set "triggerServerEvent("toggleEngine", localPlayer )" but it does nothing, what's the problem? -- Client local theButton = guiCreateButton(100, 200, 80, 40, "Toggle Engine On/Off", false) function handleButton (button,state) if ( button == "left" and state == "up" ) then if ( source == theButton ) then triggerServerEvent("toggleEngine", source ) outputDebugString ( tostring ( source ) .. " clicked." ) end end end addEventHandler("onClientGUIClick", theButton, handleButton) -- Server function switchEngine ( playerSource ) local theVehicle = getPedOccupiedVehicle ( playerSource ) if theVehicle and getVehicleController ( theVehicle ) == playerSource then local state = getVehicleEngineState ( theVehicle ) setVehicleEngineState ( theVehicle, not state ) end end addEvent("toggleEngine", true) addCommandHandler ("engine", switchEngine )
  13. Hi there im working on a bit of code but i need a bit of guidance on this idea. To keep things as short and simple, I was thinking of a way to play multiple sounds using a single function - "multi_sounds" instead of having to make another function for each of the sounds. So all you'll need to do in this case is type /win cops or /win robbers and bob's your uncle. I just need the barebones of how it should be done, so i can continue from there. I just can't figure out where to start. We got client and server: -- CLIENT function cops() local sound = playSound("sirens.mp3") setSoundVolume(sound, 1) setSoundMaxDistance(sound, 100) end addEvent("playcops", true) addEventHandler("playcops", getRootElement(), cops) function robbers() local sound = playSound("gangsters.mp3") setSoundVolume(sound, 1) setSoundMaxDistance(sound, 100) end addEvent("playrobbers", true) addEventHandler("playrobbers", getRootElement(), robbers) -- SERVER function multi_sounds ( player ) --triggerClientEvent(player, "playcops", player) triggerClientEvent(player, "playrobbers", player) end addCommandHandler("win", multi_sounds)
  14. I see now, okay i got it ? Thank you for the link to tutorialspoint as well. ?
  15. Well i can for example use: string.gsub("abcdefg69hijklmn7opqrs0tuvw71xyz72", "[^%d]", "") But that returns all the digits inside the string resulting in a value of "69707172". I'm only having difficulty getting the first 4 of them which in this "randomly generated string" is suppose to be "6970". Still clueless as to how it should be done @ IIYAMA
  16. Hello, im trying to output a 4 digit code from a random string but there is some error so i change > local theFoundCode = string.find(theCodeString, "%d%d%d%d") to local theFoundCode = string.find(theCodeString, "%d") and now it output "8". I'm trying to use string.find and seek "6970" inside of "abcdefg69hijklmn7opqrs0tuvw71xyz72", how to actually do this? function seekCode(theSource) for index, player in ipairs (getElementsByType("player")) do local theCodeString = "abcdefg69hijklmn7opqrs0tuvw71xyz72" if theCodeString then local theFoundCode = string.find(theCodeString, "%d") outputChatBox( "The code is: " .. theCodeString .. " - FOUND: " .. theFoundCode, theSource) else outputChatBox( "n/a", theSource) end end end setTimer(seekCode, 1500, 0)
  17. Hey there Hrk. I am a beginner scripter myself, i put a little code together you might find useful. --------------------------- -- Visz (Client) --------------------------- function viszFunc() toggleControl("next_weapon", false ) toggleControl("previous_weapon", false ) toggleControl("vehicle_fire", false) toggleControl("vehicle_secondary_fire", false) setPedFrozen(localPlayer, true ) outputChatBox("viszlek he") end addEvent("visz", true) addEventHandler("visz", localPlayer, viszFunc) function cleanUP() toggleControl("next_weapon", true ) toggleControl("previous_weapon", true ) toggleControl("vehicle_fire", true) toggleControl("vehicle_secondary_fire", true) setPedFrozen(localPlayer, false ) end addEventHandler("onClientResourceStart", resourceRoot, cleanUP) --------------------------- -- Visz (Server) --------------------------- function viszCommand(playerSource, commandName) triggerClientEvent(playerSource, "visz", playerSource) end addCommandHandler("visz", viszCommand)
  18. The PING still seems to update inconsistently
  19. Hi, i need a little help with this ? I'm trying to have the PING update every second the same way FPS does using the same or similar type of method. local sx_, sy_ = guiGetScreenSize() local sx, sy = sx_/1280, sy_/720 local screenW, screenH = guiGetScreenSize() --------------------------- -- Draw PING --------------------------- addEventHandler('onClientRender', root, function() local ping = getPlayerPing(localPlayer) --local currentTick = getTickCount() --local elapsedTime = currentTick - lastTick --if elapsedTime >= 1000 then --return ping --end dxDrawText("PING: "..ping, 1180*sx, 620*sy, 0*sx, 0*sy, tocolor(255, 255, 255), 1*sx, 1*sy, "default-bold", "center", "top", false, false, false, true, false) end) --------------------------- -- Draw FPS --------------------------- local FPSLimit, lastTick, framesRendered, FPS = 60, getTickCount(), 1, 1 addEventHandler('onClientRender', root, function() local currentTick = getTickCount() local elapsedTime = currentTick - lastTick if elapsedTime >= 1000 then FPS = framesRendered lastTick = currentTick framesRendered = 1 else framesRendered = framesRendered + 1 end if FPS > FPSLimit then FPS = FPSLimit end dxDrawText("FPS: "..FPS, 1280*sx, 620*sy, 0*sx, 0*sy, tocolor(255, 255, 255), 1*sx, 1*sy, "default-bold", "center", "top", false, false, false, true, false) end)
  20. Hey there! ?? I've recently adjusted a function called - dxDrawTextOnElement which i found on MTA's Wiki, to have a shadow behind each text but here seems to be an issue somewhere. When i draw certain texts (with certain text lengths) for example: "Shadow Text" and it reaches the left side of the screen, it appears that the text and the shadow clamp together in a single pixel. After moving the text a pixel further off screen the text shadow is seen back in it's correct position again. ? When i draw the text with 1 extra character, for example: "Shadow Texts", when it reaches the left side of the screen, its able to move off screen without any issue while maintaining it's position. While wring the above post, i been brain storming possible causes: • Missing an appropriate offset function • Text Bounding Box • Screen Bounding Box I'm not exactly sure on how to approach these, but here's where we are: - Screenshot: https://imgur.com/a/SwDdUh0 function dxDrawTextOnElement(TheElement,text,height,distance,R,G,B,alpha,size,font,...) local x, y, z = getPedBonePosition(TheElement, 5) local x2, y2, z2 = getCameraMatrix() local distance = distance or 150 local height = height or 1 if (isLineOfSightClear(x, y, z+2, x2, y2, z2, ...)) then local sx, sy = getScreenFromWorldPosition(x, y, z+height) if(sx) and (sy) then local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) if(distanceBetweenPoints < distance) then dxDrawText(text, sx+2, sy+2, sx, sy, tocolor(0, 0, 0, alpha or 255), size or 1, font or "arial", "center", "center") dxDrawText(text, sx, sy, sx, sy, tocolor(R or 255, G or 255, B or 255, alpha or 255), size or 1, font or "arial", "center", "center") end end end end local testPed = createPed(285, -2307.353, -1611.631, 483.889) --test ped at the top of Mount Chilade addEventHandler("onClientRender", getRootElement(), function() dxDrawTextOnElement(testPed, "Text Shadow", 0.5, 50, 255, 255, 255, 255, 1, "pricedown") dxDrawTextOnElement(testPed, "Text Shadows", -0.5, 50, 255, 255, 255, 255, 1, "pricedown") end)
  21. @Burak5312 Although the code looks more a bit more than my array of setTimers ? Your method on fading sound using the Animate function really helped a lot. I didn't actually know about it since Srslyyyy quoted it, but it was great working from this example thanks man i appreciate it ? ? local test = playSound("music.wav", true) setSoundVolume(test, 1.0) local anims, builtins = {}, {"Linear", "InQuad", "OutQuad", "InOutQuad", "OutInQuad", "InElastic", "OutElastic", "InOutElastic", "OutInElastic", "InBack", "OutBack", "InOutBack", "OutInBack", "InBounce", "OutBounce", "InOutBounce", "OutInBounce", "SineCurve", "CosineCurve"} function table.find(t, v) for k, a in ipairs(t) do if a == v then return k end end return false end function animate(f, t, easing, duration, onChange, onEnd) assert(type(f) == "number", "Bad argument @ 'animate' [expected number at argument 1, got "..type(f).."]") assert(type(t) == "number", "Bad argument @ 'animate' [expected number at argument 2, got "..type(t).."]") assert(type(easing) == "string" or (type(easing) == "number" and (easing >= 1 or easing <= #builtins)), "Bad argument @ 'animate' [Invalid easing at argument 3]") assert(type(duration) == "number", "Bad argument @ 'animate' [expected number at argument 4, got "..type(duration).."]") assert(type(onChange) == "function", "Bad argument @ 'animate' [expected function at argument 5, got "..type(onChange).."]") table.insert(anims, {from = f, to = t, easing = table.find(builtins, easing) and easing or builtins[easing], duration = duration, start = getTickCount( ), onChange = onChange, onEnd = onEnd}) return #anims end function destroyAnimation(a) if anims[a] then table.remove(anims, a) end end addEventHandler("onClientRender", root, function( ) local now = getTickCount( ) for k,v in ipairs(anims) do v.onChange(interpolateBetween(v.from, 0, 0, v.to, 0, 0, (now - v.start) / v.duration, v.easing)) if now >= v.start+v.duration then if type(v.onEnd) == "function" then v.onEnd( ) end table.remove(anims, k) end end end) function fadeOutSound(sound, fadeTime) animate(1.0, 0, 1, fadeTime, function(volumeValue) setSoundVolume(sound, volumeValue) if(sound and getSoundVolume(sound) == 0) then stopSound(sound) end end) end addCommandHandler("fadesound", function() fadeOutSound(test, 3000) -- Completely mute in 3 seconds end)
  22. Alright so there's a fade now and it's quite short, also the fade starts as soon as the song starts then stays silent, I don't think the setTimer for the fadeSound belongs within the playMusic function
  23. @TheManTheMythTheLegend I don't really understand how your method is suppose to work, here's what I've followed on: local soundVolume = 1 function playMusic() if soundVolume > 0 then soundVolume = soundVolume - 0.1 end song = playSound("music/track.mp3", true) setSoundVolume(song, soundVolume) end addCommandHandler("pmusic", playMusic) function stopMusic() setTimer(function() if isElement(song) then destroyElement(song) end end, 100*10, 1 ) end addCommandHandler("smusic", stopMusic)
  24. Hi there. ? Below is a simple client-side code that allows us to play a song by command. For our stopMusic function I've made an array of setTimer's to bring down the volume ? before stopping the song completely, ? thus achieving a fadeout effect. It works alright but i feel like there must be a much cleaner or simplified way of doing this: Which would be the best? ? function playMusic() song = playSound("music/track_05.mp3", true) setSoundVolume(song, 1) end addCommandHandler("pmusic", playMusic) function stopMusic() setTimer(function() if isElement(song) then setSoundVolume(song, 0.95) end end, 100, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.90) end end, 200, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.85) end end, 300, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.80) end end, 400, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.75) end end, 500, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.70) end end, 600, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.65) end end, 700, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.60) end end, 800, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.55) end end, 900, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.50) end end, 1000, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.45) end end, 1100, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.40) end end, 1200, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.35) end end, 1300, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.30) end end, 1400, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.25) end end, 1500, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.20) end end, 1600, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.15) end end, 1700, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.10) end end, 1800, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.09) end end, 1900, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.08) end end, 2000, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.07) end end, 2100, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.06) end end, 2200, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.05) end end, 2300, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.04) end end, 2400, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.03) end end, 2500, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.02) end end, 2600, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0.01) end end, 2700, 1) setTimer(function() if isElement(song) then setSoundVolume(song, 0) end end, 2800, 1) setTimer(function() if isElement(song) then --Destroy the sound element destroyElement(song) end end, 2900, 1) end addCommandHandler("smusic", stopMusic)
  25. Thanks @eoL|Shady, i really appreciate your assistance! ?
×
×
  • Create New...