Imposter Posted March 14, 2013 Share Posted March 14, 2013 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. Thanks, NooP Link to comment
novo Posted March 14, 2013 Share Posted March 14, 2013 Create the pickups client-side and then trigger an event at server-side for creating a col sphere. Then you just need to create a pickup handling function and to use https://wiki.multitheftauto.com/wiki/OnColShapeHit Add me to skype if you need more help: radio.habbek I will help you without problem. Link to comment
Castillo Posted March 14, 2013 Share Posted March 14, 2013 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
Imposter Posted March 15, 2013 Author Share Posted March 15, 2013 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! 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
Castillo Posted March 15, 2013 Share Posted March 15, 2013 No, it won't be synchronized, for that, you need to create the weapon on all clients, set their state on all clients, and so on. Link to comment
Imposter Posted March 15, 2013 Author Share Posted March 15, 2013 That would be quite difficult D: since the necessary events do not exist or I don't know which ones to use, would you give me a hand with the handlers? So far I know I can use OnClientPlayerDamage for player damage, but for vehicle damage I don't know what to use. Thanks again. >_> Link to comment
Castillo Posted March 15, 2013 Share Posted March 15, 2013 Why would you need to use "onClientPlayerDamage"? Link to comment
Imposter Posted March 15, 2013 Author Share Posted March 15, 2013 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 but I don't know how to synchronize it, if you would help me out, I would be really really happy. Link to comment
Castillo Posted March 15, 2013 Share Posted March 15, 2013 No, you need to create the weapon on every client, that way, it'll damage vehicles. Link to comment
Imposter Posted March 15, 2013 Author Share Posted March 15, 2013 (edited) 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 March 15, 2013 by Guest Link to comment
Castillo Posted March 15, 2013 Share Posted March 15, 2013 What you must do is, trigger the event to everyone, send the vehicle element, attach it to the vehicle. Link to comment
Imposter Posted March 15, 2013 Author Share Posted March 15, 2013 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. Link to comment
Castillo Posted March 15, 2013 Share Posted March 15, 2013 I mean the vehicle, car as you say. Link to comment
Cadu12 Posted March 15, 2013 Share Posted March 15, 2013 createWeapon has already sync, the wiki should update. Link to comment
Moderators IIYAMA Posted March 15, 2013 Moderators Share Posted March 15, 2013 Sync between client and server. Not yet. But yes, you can make them synced by scripting it. Link to comment
Imposter Posted March 15, 2013 Author Share Posted March 15, 2013 createWeapon has already sync, the wiki should update. Does it? 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 IIYAMA Posted March 15, 2013 Moderators Share Posted March 15, 2013 After I created my vehicle weapons, it wasn't synced. If it is, let me know. Then I have to change my scripts too. Link to comment
Imposter Posted March 15, 2013 Author Share Posted March 15, 2013 Well that is helpful. If you think my code is right, lemme know. Link to comment
Cadu12 Posted March 15, 2013 Share Posted March 15, 2013 Use createWeapon with server-side, not client-side. If you are on server-side, it'll be sync. Link to comment
Imposter Posted March 15, 2013 Author Share Posted March 15, 2013 Use createWeapon with server-side, not client-side. If you are on server-side, it'll be sync. It is also a server side feature? D: I thought it was clientside Link to comment
Moderators IIYAMA Posted March 15, 2013 Moderators Share Posted March 15, 2013 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
Imposter Posted March 15, 2013 Author Share Posted March 15, 2013 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
Cadu12 Posted March 15, 2013 Share Posted March 15, 2013 https://code.google.com/p/mtasa-blue/so ... ail?r=4872 As I said, it has already sync, server-side. Link to comment
Moderators IIYAMA Posted March 15, 2013 Moderators Share Posted March 15, 2013 https://code.google.com/p/mtasa-blue/source/detail?r=4872As I said, it has already sync, server-side. Error: [string "theWeapon = createWeapon("minigun", 0, 0, 0..."]:1: attempt to call global 'createWeapon' (a nil value) Well then they are wrong..... >version uptodate< Link to comment
Cadu12 Posted March 15, 2013 Share Posted March 15, 2013 Download latest version, https://nightly.multitheftauto.com/ Try use "" in your resource meta, should it work. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now