Jump to content

MTA.Castiel

Members
  • Posts

    30
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

MTA.Castiel's Achievements

Rat

Rat (9/54)

2

Reputation

  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
×
×
  • Create New...