Jump to content

Some scripts I created


cokacola

Recommended Posts

Hey, thought I'd create a topic to release a few scripts I've created for my LAN server.

Some of them probably need a bit of work or could be made a bit prettier(or maybe commented..) but they're fun at least.

Littlebird Weapons

I replaced my Sparrow with a littlebird and created some weapons for it with limited ammo.

This is probably better with the actual littlebird model, so if you'd like me to turn this script into a resource with the littlebird model, let me know and I will.

use O to switch weapons between the minigun and the missiles.

Left ALT to fire.

Problems:

Well, I used the ammo available in the actual minigun object for the ammo limit. So, when you run out it seems to reload the minigun when you run out of ammo. Can probably be fixed so it doesn't do that.

CODE

Serverside:

function initVehicle(veh) 
    setElementData(veh,"a51.littlebird.gunAmmo",1000) 
    setElementData(veh,"a51.littlebird.missileAmmo",30) 
    setElementData(veh,"a51.littlebird.selectedWeapon",1) --1 = gun, 2 = missiles 
    setElementData(veh,"a51.littlebird.hasInit",true) 
     
    triggerClientEvent("cl_a51LittlebirdInit", getRootElement(), veh) 
end 
  
function switchWeapon(plr) 
    local veh = getPedOccupiedVehicle(plr) 
    if(getElementType(plr) ~= "player" or not veh or not getElementData(veh, "a51.littlebird.hasInit") or getVehicleOccupant(veh) ~= plr) then 
        return 
    end 
     
    local cwep = getElementData(veh,"a51.littlebird.selectedWeapon") 
    if(cwep == 1) then 
        outputChatBox("Rockets Selected",plr) 
        setElementData(veh,"a51.littlebird.selectedWeapon",2) 
    else 
        outputChatBox("Minigun Selected",plr) 
        setElementData(veh,"a51.littlebird.selectedWeapon",1) 
    end 
end 
  
  
function vehicleEnter(plr,seat,jacked) 
    if(not getElementData(source, "a51.littlebird.hasInit") or seat ~= 0) then 
        return 
    end 
     
    if(not getElementData(source, "a51.littlebird.hasInit")) then 
        initVehicle(source) 
    end 
     
    bindKey(plr,"o","down",switchWeapon) 
     
end 
addEventHandler("onVehicleEnter",getRootElement(),vehicleEnter) 
  
function vehicleLeave(plr,seat,jacker) 
    if(not getElementData(source, "a51.littlebird.hasInit")) then 
        return 
    end 
    unbindKey(plr,"o","down",switchWeapon) 
    --unbindKey(plr,"alt","down",fireWeapon) 
end 
addEventHandler("onVehicleExit",getRootElement(),vehicleLeave) 
  
function slb(plr,cmd) 
    local x,y,z = getElementPosition(plr) 
    x = x - 5 
    y = y - 5 
    local v = createVehicle(469,x,y,z,0,0,263.28314208984) 
     
    initVehicle(v) 
end 
addCommandHandler("slb",slb) 
  
  
  
function myrot(plr) 
    local rx,ry,rz = getElementRotation(plr) 
    outputChatBox(rx..","..ry..","..rz,plr) 
end 
addCommandHandler("myrot",myrot) 

Client:

local lbData = {} 
  
function fireWeapon(key,keystate,veh) 
    if(not getElementData(veh, "a51.littlebird.hasInit") or getVehicleOccupant(veh) ~= getLocalPlayer()) then 
        return 
    end 
     
    local cwep = getElementData(veh,"a51.littlebird.selectedWeapon") 
    if(cwep == 1) then 
        local firing = "ready" 
        if(keystate == "down") then 
            firing = "firing" 
        end 
         
        setWeaponState(lbData[veh]["gunLeft"],firing) 
        setWeaponState(lbData[veh]["gunRight"],firing) 
    elseif(keystate == "down") then 
        local ammo = getElementData(veh,"a51.littlebird.missileAmmo") 
        if(ammo < 1) then 
            return 
        end 
         
        local x,y,z = getElementPosition(veh) 
        local rx,ry,rz = getElementRotation(veh) 
        createProjectile(veh, 19, x+5,y+5,z-2, 1.0, nil) 
        createProjectile(veh, 19, x+5,y-5,z-2, 1.0, nil) 
         
        setElementData(veh,"a51.littlebird.missileAmmo",ammo-1) 
    end 
end 
  
addEventHandler("onClientVehicleEnter", getRootElement(), 
    function(thePlayer, seat) 
        if thePlayer == getLocalPlayer() then 
            local veh = getPedOccupiedVehicle(thePlayer) 
            if(veh and getElementData(veh, "a51.littlebird.hasInit") and getVehicleOccupant(veh) == getLocalPlayer()) then 
                bindKey("lalt","both",fireWeapon, veh) 
            end 
        end 
    end 
) 
  
function attachRotationAdjusted ( from, to ) 
    -- Note: Objects being attached to ('to') should have at least two of their rotations set to zero 
    --       Objects being attached ('from') should have at least one of their rotations set to zero 
    -- Otherwise it will look all funny 
  
    local frPosX, frPosY, frPosZ = getElementPosition( from ) 
    local frRotX, frRotY, frRotZ = getElementRotation( from ) 
    local toPosX, toPosY, toPosZ = getElementPosition( to ) 
    local toRotX, toRotY, toRotZ = getElementRotation( to ) 
    local offsetPosX = frPosX - toPosX 
    local offsetPosY = frPosY - toPosY 
    local offsetPosZ = frPosZ - toPosZ 
    local offsetRotX = frRotX - toRotX 
    local offsetRotY = frRotY - toRotY 
    local offsetRotZ = frRotZ - toRotZ 
  
    offsetPosX, offsetPosY, offsetPosZ = applyInverseRotation ( offsetPosX, offsetPosY, offsetPosZ, toRotX, toRotY, toRotZ ) 
  
    attachElements( from, to, offsetPosX, offsetPosY, offsetPosZ, offsetRotX, offsetRotY, offsetRotZ ) 
end 
  
  
  
function applyInverseRotation ( x,y,z, rx,ry,rz ) 
    local DEG2RAD = (math.pi * 2) / 360 
    rx = rx * DEG2RAD 
    ry = ry * DEG2RAD 
    rz = rz * DEG2RAD 
  
    local tempY = y 
    y =  math.cos ( rx ) * tempY + math.sin ( rx ) * z 
    z = -math.sin ( rx ) * tempY + math.cos ( rx ) * z 
  
    local tempX = x 
    x =  math.cos ( ry ) * tempX - math.sin ( ry ) * z 
    z =  math.sin ( ry ) * tempX + math.cos ( ry ) * z 
  
    tempX = x 
    x =  math.cos ( rz ) * tempX + math.sin ( rz ) * y 
    y = -math.sin ( rz ) * tempX + math.cos ( rz ) * y 
  
    return x, y, z 
end 
  
function initVehicle(veh) 
    local x,y,z = getElementPosition(veh) 
    local rx,ry,rz = getElementRotation(veh) 
     
    local gunLeft = createWeapon("minigun",x,y,z) 
    local gunRight = createWeapon("minigun",x,y,z) 
     
    setWeaponClipAmmo(gunLeft,1000) 
    setWeaponClipAmmo(gunRight,1000) 
     
    setElementRotation(gunLeft,0,0,-
    setElementRotation(gunRight,0,0,-
     
    setElementPosition(gunLeft,x,y+1,z-1) 
    setElementPosition(gunRight,x,y-1,z-1) 
     
    setElementCollisionsEnabled(gunLeft,false) 
    setElementCollisionsEnabled(gunRight,false) 
     
    attachRotationAdjusted(gunLeft,veh) 
    attachRotationAdjusted(gunRight,veh) 
    --attachElements(gunRight,veh,1,1,0,rx,ry,rz) 
     
    setElementAlpha(gunLeft,0) 
    setElementAlpha(gunRight,0) 
     
    lbData[veh] = {} 
    lbData[veh]["gunLeft"] = gunLeft 
    lbData[veh]["gunRight"] = gunRight 
     
    bindKey("lalt","both",fireWeapon, veh) 
end 
addEvent("cl_a51LittlebirdInit", true) 
addEventHandler("cl_a51LittlebirdInit",getLocalPlayer(),initVehicle) 
  
  
  
local screenWidth, screenHeight = guiGetScreenSize ( ) 
local root = getRootElement () 
function updateCamera () 
    local veh = getPedOccupiedVehicle(getLocalPlayer()) 
    if(veh) then 
        local splr = getVehicleOccupant(veh) 
        if(splr == getLocalPlayer() and getElementData(veh, "a51.littlebird.hasInit")) then 
            local cwep = getElementData(veh,"a51.littlebird.selectedWeapon") 
            local ammo = 0 
            if(cwep == 1) then 
                ammo = getWeaponClipAmmo(lbData[veh]["gunLeft"]) 
            else 
                ammo = getElementData(veh,"a51.littlebird.missileAmmo") 
            end 
            dxDrawText(ammo, 44, screenHeight - 41, screenWidth, screenHeight) 
        end 
    end 
end 
addEventHandler ( "onClientPreRender", root, updateCamera ) 

I'll post more as I find them.

I also have a fuel script that has a lot of the fuel stations in SA, but it's got XML files for the lua stations and server and clientside code so I guess like the littlebird above it'd probably work better as a resource.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...