Jump to content

[HELP] Custom pickups


Imposter

Recommended Posts

Hey guys, I wanted help with trying to add custom pickups to the race gamemode, I have looked at the edf and the lua files, I see where the scripter has put his, but I don't know how to put custom ones, when I put one, it seems to break, any help will be greatly appreciated. Hoping Castillo or 50p respond. :P

Thanks,

NooP

Link to comment

He's talking about adding more pickups to the race game mode.

@NooP:

At "race_client.lua":

g_ModelForPickupType = { nitro = 2221, repair = 2222, vehiclechange = 2223 } 

To add a new one, you do:

g_ModelForPickupType = { nitro = 2221, repair = 2222, vehiclechange = 2223, newname = 2224 } 

Same on "edf/edf.lua", "edf/edf_client.lua".

And on "edf/race.edf", you gotta change this line I think:

"type" type="selection:nitro,repair,vehiclechange" description="The type of pickup.  Can repair the vehicle, add a Nitro, or change the player's vehicle" default="nitro" /> 

To something like this:

"type" type="selection:nitro,repair,vehiclechange,newname" description="The type of pickup.  Can repair the vehicle, add a Nitro, or change the player's vehicle" default="nitro" /> 

And then on "race_server.lua":

addEvent('onPlayerPickUpRacePickup') 
addEvent('onPlayerPickUpRacePickupInternal', true) 
addEventHandler('onPlayerPickUpRacePickupInternal', g_Root, 
    function(pickupID, respawntime) 
        if checkClient( false, source, 'onPlayerPickUpRacePickupInternal' ) then return end 
        local pickup = g_Pickups[table.find(g_Pickups, 'id', pickupID)] 
        local vehicle = g_Vehicles[source] 
        if not pickup or not vehicle then return end 
        if respawntime and tonumber(respawntime) >= 50 then 
            table.insert(unloadedPickups, pickupID) 
            clientCall(g_Root, 'unloadPickup', pickupID) 
            TimerManager.createTimerFor("map"):setTimer(ServerLoadPickup, tonumber(respawntime), 1, pickupID) 
        end 
        if pickup.type == 'repair' then 
            fixVehicle(vehicle) 
        elseif pickup.type == 'nitro' then 
            addVehicleUpgrade(vehicle, 1010) 
        elseif pickup.type == 'vehiclechange' then 
            if getElementModel(vehicle) ~= tonumber(pickup.vehicle) then 
                clientCall(source, 'alignVehicleWithUp') 
                setVehicleID(vehicle, pickup.vehicle) 
                setVehiclePaintjobAndUpgrades(vehicle, pickup.paintjob, pickup.upgrades) 
                clientCall(source, 'vehicleChanging', g_MapOptions.classicchangez, tonumber(pickup.vehicle)) 
            end 
        end 
        triggerEvent('onPlayerPickUpRacePickup', source, pickupID, pickup.type, pickup.vehicle) 
    end 
) 

You make your new pickup type to do whatever you want.

Link to comment

Thanks so much, that is what I kinda did but it used to give code errors, I will try this out right now. :)

You are the best.

NooP

___________

Edit:

Thanks Castillo this works! :D I also have another question, last time I posted about creating weapons client side and shooting, if I did CreateWeapon, would this be synchronized? If not, could someone guide me on how to do it? Thanks again.

Link to comment
Why would you need to use "onClientPlayerDamage"?

Well I am not sure, I need to detect the damage the that is done by the weapons to any player or vehicle, since you know why I asked about the pickups, I am adding weapons to cars, and I've done that :P but I don't know how to synchronize it, if you would help me out, I would be really really happy. :)

Link to comment
No, you need to create the weapon on every client, that way, it'll damage vehicles.

Well I just tried to try that, and I got confused ... This is what I have...

race_server.lua

  
addEvent('onPlayerPickUpRacePickup') 
addEvent('onPlayerPickUpRacePickupInternal', true) 
addEventHandler('onPlayerPickUpRacePickupInternal', g_Root, 
    function(pickupID, respawntime) 
        if checkClient( false, source, 'onPlayerPickUpRacePickupInternal' ) then return end 
        local pickup = g_Pickups[table.find(g_Pickups, 'id', pickupID)] 
        local vehicle = g_Vehicles[source] 
        if not pickup or not vehicle then return end 
        if respawntime and tonumber(respawntime) >= 50 then 
            table.insert(unloadedPickups, pickupID) 
            clientCall(g_Root, 'unloadPickup', pickupID) 
            TimerManager.createTimerFor("map"):setTimer(ServerLoadPickup, tonumber(respawntime), 1, pickupID) 
        end 
        if pickup.type == 'nitro' then 
            addVehicleUpgrade(vehicle, 1010) 
        elseif pickup.type == 'minigun' then 
            outputChatBox("Giving Minigun...", source); 
            triggerClientEvent("removeVehicleWeapon", source); 
            triggerClientEvent("addVehicleWeapon", source, 362); 
        elseif pickup.type == 'vehiclechange' then 
            if getElementModel(vehicle) ~= tonumber(pickup.vehicle) then 
                clientCall(source, 'removeVehicleNitro') 
                setVehicleID(vehicle, pickup.vehicle) 
                if pickup.paintjob or pickup.upgrades then 
                    setVehiclePaintjobAndUpgrades(vehicle, pickup.paintjob, pickup.upgrades) 
                end 
            end 
        end 
        triggerEvent('onPlayerPickUpRacePickup', source, pickupID, pickup.type, pickup.vehicle) 
    end 
) 
  

weapon_client.lua

  
theCar = nil; 
theWeapon = nil; 
theWeaponFireTimer = nil; 
theWeaponSound = nil; 
  
function addVehicleWeapon(weaponID) 
    if (weaponID == 362) then 
        outputChatBox("A minigun will be added to your vehicle...") 
        theCar = getPedOccupiedVehicle(getLocalPlayer()); 
        local x, y, z = getElementPosition(theCar); 
        theWeapon = createWeapon("minigun", x, y, z); 
        if ((theCar) and (theWeapon)) then 
            attachElements(theWeapon, theCar, 0, 0, 0); 
            theWeaponFireTimer = setTimer(fireVehicleWeapon, 50, 0, true); 
            setWeaponOwner(theWeapon, getLocalPlayer()); 
            setWeaponAmmo(theWeapon, 500); 
        end 
    end 
end 
addEvent("addVehicleWeapon", true); 
addEventHandler("addVehicleWeapon", getRootElement(), addVehicleWeapon); 
  
function fireVehicleWeapon(isSoundEnabled) 
    if (theWeapon) then 
        if (getKeyState("lctrl") == true) then 
            --local rx, ry, rz = getElementRotation(theCar); 
            --setElementRotation(theWeapon, rx, ry, rz); 
            fireWeapon(theWeapon); 
            if (isSoundEnabled == true) then 
                local x, y, z = getElementPosition(theWeapon); 
                theWeaponSound = playSound3D("audio/minigun_base.mp3", x, y, z, false); 
            end 
        end 
    else 
        removeVehicleWeapon(); 
    end 
end 
  
function removeVehicleWeapon() 
    if (theWeapon) then 
        if (theWeaponFireTimer) then 
            killTimer(theWeaponFireTimer); 
        end 
        destroyElement(theWeapon); 
        outputChatBox("Removing weapon..."); 
    end 
end 
addEvent("removeVehicleWeapon", true); 
addEventHandler("removeVehicleWeapon", getRootElement(), removeVehicleWeapon); 
  
function onClientPlayerWasted() 
    if (theWeaponFireTimer) then 
        killTimer(theWeaponFireTimer); 
        if (theWeaponSound) then 
            stopSound(theWeaponSound); 
        end 
    end 
    destroyElement(theWeapon); 
end 
addEventHandler("onClientPlayerWasted", getLocalPlayer(), onClientPlayerWasted); 
  

I don't know what to do. D: I am guessing I need to use getElementsByType("player") to send the weapon to the clients and add it to a table so it can be removed when the client's upgrade is removed. How will I create it on the other clients too? I am so confused.

Edited by Guest
Link to comment
What you must do is, trigger the event to everyone, send the vehicle element, attach it to the vehicle.

By vehicle element, you mean the car? or the weapon? then attach it, ok. I will do that tomorrow morning since it is quite late now. Anyways, have a good night and thanks for your help. :D

Link to comment
createWeapon has already sync, the wiki should update.

Does it? :o

I just coded this, I am going to install MTA on my old computer to test it out today.

weapon_client.lua

  
function attachWeaponToVehicle(thePlayer, theWeaponID) 
    if (theWeaponID == 362) then 
        outputChatBox("A minigun will be added to your vehicle...") 
        theCar = getPedOccupiedVehicle(getLocalPlayer()); 
        local x, y, z = getElementPosition(theCar); 
        local hisWeapon = createWeapon("minigun", x, y, z); 
        if ((theCar) and (hisWeapon)) then 
            attachElements(hisWeapon, theCar, 0, 0, 0); 
            --theWeaponFireTimer = setTimer(fireVehicleWeapon, 50, 0, true); 
            setWeaponOwner(hisWeapon, getLocalPlayer()); 
            setElementData(hisWeapon, "owner", thePlayer); 
            setWeaponAmmo(hisWeapon, 500); 
            if (thePlayer == getLocalPlayer()) then 
                outputChatBox("Your minigun has been enabled!"); 
                bindKey("lctrl", "down", shootWeapon, hisWeapon, true) 
            end 
        end 
    elseif (theWeaponID == 359) then 
     
    end  
end 
addEvent("attachWeaponToVehicle", true); 
addEventHandler("attachWeaponToVehicle", getRootElement(), attachWeaponToVehicle); 
  
function shootWeapon(theKey, theKeyState, theWeapon, isSoundEnabled) 
    outputChatBox("FIRING!"); 
    if (theKeyState == "down") then 
        if (theWeapon) then 
            --local rx, ry, rz = getElementRotation(theCar); 
            --setElementRotation(theWeapon, rx, ry, rz); 
            fireWeapon(theWeapon); 
            if (isSoundEnabled == true) then 
                local x, y, z = getElementPosition(theWeapon); 
                theWeaponSound = playSound3D("audio/minigun_base.mp3", x, y, z, false); 
            end 
        else 
            --removeVehicleWeapon(); 
        end 
    end 
end 
  

race_server.lua

  
addEvent('onPlayerPickUpRacePickup') 
addEvent('onPlayerPickUpRacePickupInternal', true) 
addEventHandler('onPlayerPickUpRacePickupInternal', g_Root, 
    function(pickupID, respawntime) 
        if checkClient( false, source, 'onPlayerPickUpRacePickupInternal' ) then return end 
        local pickup = g_Pickups[table.find(g_Pickups, 'id', pickupID)] 
        local vehicle = g_Vehicles[source] 
        if not pickup or not vehicle then return end 
        if respawntime and tonumber(respawntime) >= 50 then 
            table.insert(unloadedPickups, pickupID) 
            clientCall(g_Root, 'unloadPickup', pickupID) 
            TimerManager.createTimerFor("map"):setTimer(ServerLoadPickup, tonumber(respawntime), 1, pickupID) 
        end 
        if pickup.type == 'nitro' then 
            addVehicleUpgrade(vehicle, 1010) 
        elseif pickup.type == 'minigun' then 
            --outputChatBox("Giving Minigun...", source); 
            --triggerClientEvent("removeVehicleWeapon", source); 
            --triggerClientEvent("addVehicleWeapon", source, 362 
            local thePlayers = getElementsByType("player"); 
            for theKey, thePlayer in ipairs(thePlayers) do 
                triggerClientEvent("attachWeaponToVehicle", thePlayer, source, 362); 
            end 
        elseif pickup.type == 'rl' then 
            --triggerClientEvent("removeVehicleWeapon", source); 
            --triggerClientEvent("addVehicleWeapon", source, 359); 
            local thePlayers = getElementsByType("player"); 
            for theKey, thePlayer in ipairs(thePlayers) do 
                triggerClientEvent("attachWeaponToVehicle", thePlayer, source, 359); 
            end 
        elseif pickup.type == 'vehiclechange' then 
            if getElementModel(vehicle) ~= tonumber(pickup.vehicle) then 
                clientCall(source, 'removeVehicleNitro') 
                setVehicleID(vehicle, pickup.vehicle) 
                if pickup.paintjob or pickup.upgrades then 
                    setVehiclePaintjobAndUpgrades(vehicle, pickup.paintjob, pickup.upgrades) 
                end 
            end 
        end 
        triggerEvent('onPlayerPickUpRacePickup', source, pickupID, pickup.type, pickup.vehicle) 
    end 
) 
  

Link to comment
  • Moderators
Sync between client and server. Not yet.

But yes, you can make them synced by scripting it.

It is client side..... that is why your script must sync them...

This can be done by:

- Global client table. -- client core

- ElementData -- client and server core

- Serverside table with server to client triggers. -- client and server core

Link to comment
Use createWeapon with server-side, not client-side. If you are on server-side, it'll be sync.

You can't, i just tried, it isnt serverside, also, could someone help me make the synchronization system? I was making one before but SolidSnake14 said if you make it on all the clients, it would sync, but I dont know, I've tried. If I did something wrong, can someone help me?

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...