kewizzle Posted March 23, 2017 Share Posted March 23, 2017 sorry i keep posting here im not a noob to scripting mta resources but im also not a god.. with that said i got an error on the second death and it said [18:10:05] ERROR: zombies\save\saver.lua:17: bad argument #1 to 'pairs' (table e xpected, got nil) and i lost all my weapons. local tempData = { } addEventHandler ( "onPlayerWasted", getRootElement(), function ( ) tempData [ source ] = { weapons = getWeaponsTable ( source ), skin = getElementModel ( source ) } end ) addEventHandler ( "onPlayerSpawn", getRootElement(), function ( ) if ( tempData [ source ] ) then setElementModel ( source, tempData [ source ].skin ) for weapon, ammo in pairs ( tempData [ source ].weapons ) do giveWeapon ( source, weapon, ammo, true ) end end end ) function getWeaponsTable ( thePlayer ) local weapons = { } local hasAnyWeapon = false for slot = 0, 12 do local weapon = getPedWeapon ( thePlayer, slot ) if ( weapon > 0 ) then local ammo = getPedTotalAmmo ( thePlayer, slot ) if ( ammo > 0 ) then weapons [ weapon ] = ammo hasAnyWeapon = true end end end if ( hasAnyWeapon ) then return weapons end end (yes i got this script from someone else.) Link to comment
itHyperoX Posted March 24, 2017 Share Posted March 24, 2017 addEventHandler("onPlayerSpawn",root,function () local account = getPlayerAccount(source) if (account) and not (isGuestAccount(account)) then local weapons = getAccountData(account, "weapns") if (weapons) and (fromJSON(weapons)) then takeAllWeapons(source) for weapon, ammo in pairs(fromJSON(weapons)) do giveWeapon(source, weapon, ammo, true) end end end end) addEventHandler("onPlayerWasted",root,function () local account = getPlayerAccount(source) if (account) and not (isGuestAccount(account)) then local weapons = getAllPedWeapon(source) setAccountData(account, "weapns", toJSON(weapons)) end end) function getAllPedWeapon(thePed) local weapons = { } for slot=1, 12 do local weapon = getPedWeapon(thePed, slot) local ammo = getPedTotalAmmo(thePed, slot) if (weapon > 0) and (ammo > 0) then weapons[weapon] = ammo end end return weapons end Link to comment
kewizzle Posted March 24, 2017 Author Share Posted March 24, 2017 (edited) doesnt work it works when i die once but then if i die again i lose all my weapons. Edited March 24, 2017 by kewizzle Link to comment
marty000123 Posted March 24, 2017 Share Posted March 24, 2017 Are u using a custom death script? Link to comment
Anubhav Posted March 24, 2017 Share Posted March 24, 2017 (edited) local tempData = { } addEventHandler ( "onPlayerWasted", getRootElement(), function ( ) tempData [ source ] = { weapons = getWeaponsTable ( source ), skin = getElementModel ( source ) } end ) addEventHandler ( "onPlayerSpawn", getRootElement(), function ( ) if ( tempData [ source ] ) then setElementModel ( source, tempData [ source ].skin ) for weapon, ammo in pairs ( tempData [ source ].weapons ) do giveWeapon ( source, weapon, ammo, true ) end tempData[ source ] = nil end end ) function getWeaponsTable ( thePlayer ) local weapons = { } local hasAnyWeapon = false for slot = 0, 12 do local weapon = getPedWeapon ( thePlayer, slot ) if ( weapon > 0 ) then local ammo = getPedTotalAmmo ( thePlayer, slot ) if ( ammo > 0 ) then weapons [ weapon ] = ammo hasAnyWeapon = true end end end if ( hasAnyWeapon ) then return weapons end end Edited March 24, 2017 by Anubhav Link to comment
NeXuS™ Posted March 24, 2017 Share Posted March 24, 2017 (edited) Set the highlight to LUA @Anubhav. Edited March 24, 2017 by NeXuS™ Link to comment
itHyperoX Posted March 24, 2017 Share Posted March 24, 2017 replace with mine. Thats 100% works. Link to comment
kewizzle Posted March 24, 2017 Author Share Posted March 24, 2017 neither script works, if youd like join my server and test for yourself. It's in my sig. this is my spawn script aswell. outputServerLog ( "***Spawn Script Loaded ***" ) local spawnX, spawnY, spawnZ = math.random(-694,-679), math.random(951,963), 17 function joinHandler() spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) outputChatBox("#FF00DC"..getPlayerName(source).." #ff0000Welcome To K#ff4000e#ff7f00w#ffbf00i#ffff00z#00ff00z#00ff80l#00ffffe#0080ff'#0000ffs Zombie Server, :O :O. Press \"F9\" For HELP", source, r, g, b, true) end function deathHandler() spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) end addEventHandler("onPlayerJoin", getRootElement(), joinHandler) addEventHandler("onPlayerWasted", getRootElement(), deathHandler) function giveWeaponsOnSpawn ( theSpawnpont, theTeam ) getammo = getPedTotalAmmo ( source, 2 ) if (getammo <= 14) then giveWeapon ( source, 22, 15 ) end end addEventHandler ( "onPlayerSpawn", getRootElement(), giveWeaponsOnSpawn ) I dont think it would bother it because even if my ammo is >= 15 it still doesnt work lol. Link to comment
kewizzle Posted March 25, 2017 Author Share Posted March 25, 2017 i think i found the problem, if you dont pickup any new weapons after you die you lose the old ones when you die again. Anyone know why this could be? Link to comment
Anubhav Posted March 27, 2017 Share Posted March 27, 2017 If you dont have any weapons when you die, it won't give you any weapon when you spawn, be it 1st 2nd or 3rd. Link to comment
kewizzle Posted March 27, 2017 Author Share Posted March 27, 2017 1 hour ago, Anubhav said: If you dont have any weapons when you die, it won't give you any weapon when you spawn, be it 1st 2nd or 3rd. i know that but when i die with the weapons i spawned with the first time i died then they disappear. Link to comment
Anubhav Posted March 27, 2017 Share Posted March 27, 2017 So you want the weapons on first death to be saved for all NEXT deaths? Link to comment
kewizzle Posted March 27, 2017 Author Share Posted March 27, 2017 12 hours ago, Anubhav said: So you want the weapons on first death to be saved for all NEXT deaths? yeah Link to comment
kewizzle Posted March 27, 2017 Author Share Posted March 27, 2017 Tried scripting this but does not work. addEventHandler ( "onPlayerWasted", getRootElement(), function() gun0 = getPedWeapon ( source, 0 ) gun1 = getPedWeapon ( source, 1 ) gun2 = getPedWeapon ( source, 2 ) gun2a = getPedTotalAmmo ( source, 2 ) gun3 = getPedWeapon ( source, 3 ) gun3a = getPedTotalAmmo ( source, 3 ) gun4 = getPedWeapon ( source, 4 ) gun4a = getPedTotalAmmo ( source, 4 ) gun5 = getPedWeapon ( source, 5 ) gun5a = getPedTotalAmmo ( source, 5 ) gun6 = getPedWeapon ( source, 6 ) gun6a = getPedTotalAmmo ( source, 6 ) gun7 = getPedWeapon ( source, 7 ) gun7a = getPedTotalAmmo ( source, 7 ) gun8 = getPedWeapon ( source, 8 ) gun8a = getPedTotalAmmo ( source, 8 ) gun9 = getPedWeapon ( source, 9 ) gun9a = getPedTotalAmmo ( source, 9 ) gun10 = getPedWeapon ( source, 10 ) gun11 = getPedWeapon ( source, 11 ) gun12 = getPedWeapon ( source, 12 ) addEventHandler ( "onPlayerSpawn", getRootElement(), function() giveWeapon( source, gun0, 1) giveWeapon( source, gun1, 1) giveWeapon( source, gun2, gun2a) giveWeapon( source, gun3, gun3a) giveWeapon( source, gun4, gun4a) giveWeapon( source, gun5, gun5a) giveWeapon( source, gun6, gun6a) giveWeapon( source, gun7, gun7a) giveWeapon( source, gun8, gun8a) giveWeapon( source, gun9, gun9a) giveWeapon( source, gun10, 1) giveWeapon( source, gun11, 1) giveWeapon( source, gun12, 1) end) end) Link to comment
NeXuS™ Posted March 28, 2017 Share Posted March 28, 2017 Added to TODO list, going to do it today for ya. 1 Link to comment
kewizzle Posted March 28, 2017 Author Share Posted March 28, 2017 1 hour ago, NeXuS™ said: Added to TODO list, going to do it today for ya. thank you so much once this issue is done then i should be good. I have literally tried coding it and tried using other resources and peoples code and nothing worked at all. I literally tried everyones code and resource and coded it in a few different ways and nothing. LOL all it did is add more ammo to my pistol on spawn. If you get this to work i would be happy lol. Link to comment
NeXuS™ Posted March 28, 2017 Share Posted March 28, 2017 Meanwhile I'm gone, could you express what should the script do at all? Link to comment
kewizzle Posted March 28, 2017 Author Share Posted March 28, 2017 1 hour ago, NeXuS™ said: Meanwhile I'm gone, could you express what should the script do at all? I have a zombie server, in this server you can collect weapons when zombies have died, you spawn with 15 colt 45 ammo if your ammo is <= 14. When you spawn you're supposed to still have all the weapons and ammo you picked up from dead zombies so you can sell it all in the shop for $1 per bullet. Players are supposed to save up their ammo to sell and make cash. I got all this coded however, in my server weapons we're saving when onPlayerWasted when they died, but if the player dies a second time without collecting any more ammo they will lose all the guns and that isnt supposed to happen. I wan't the script to save all the players weapons on death everytime and respawn with the ammo and guns they picked up while killing zombies. Basically onPlayerWasted save the weapons in each slot and when onPlayerSpawn returns the weapons the player had when he died with the correct ammo. Now i dont know if any of my scripts will effect anything but ill send you my onPlayerSpawn script i currently have for the giveWeapon when they have <= 14 colt 45 ammo outputServerLog ( "***Spawn Script Loaded ***" ) local PlayersTeam = createTeam ( "Players" ) setTeamFriendlyFire ( PlayersTeam, false ) local spawnX, spawnY, spawnZ = math.random(-694,-679), math.random(951,963), 17 function joinHandler() spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) setPlayerTeam(source, PlayersTeam ) outputChatBox("#FF00DC"..getPlayerName(source).." #ff0000Welcome To K#ff4000e#ff7f00w#ffbf00i#ffff00z#00ff00z#00ff80l#00ffffe#0080ff'#0000ffs Zombie Server, :O :O. Press \"F9\" For HELP", source, r, g, b, true) end function deathHandler() spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) end addEventHandler("onPlayerWasted", getRootElement(), deathHandler) function giveWeaponsOnSpawn ( theSpawnpont, theTeam ) getammo = getPedTotalAmmo ( source, 2 ) if (getammo <= 14) then giveWeapon ( source, 22, 15 ) end end addEventHandler ( "onPlayerSpawn", getRootElement(), giveWeaponsOnSpawn ) addEventHandler ( "onPlayerLogin", getRootElement(), joinHandler ) the file for this is <script src="AZZ/spawns.lua" /> Link to comment
Ayush Rathore Posted March 28, 2017 Share Posted March 28, 2017 3 hours ago, kewizzle said: I have a zombie server, in this server you can collect weapons when zombies have died, you spawn with 15 colt 45 ammo if your ammo is <= 14. When you spawn you're supposed to still have all the weapons and ammo you picked up from dead zombies so you can sell it all in the shop for $1 per bullet. Players are supposed to save up their ammo to sell and make cash. I got all this coded however, in my server weapons we're saving when onPlayerWasted when they died, but if the player dies a second time without collecting any more ammo they will lose all the guns and that isnt supposed to happen. I wan't the script to save all the players weapons on death everytime and respawn with the ammo and guns they picked up while killing zombies. Basically onPlayerWasted save the weapons in each slot and when onPlayerSpawn returns the weapons the player had when he died with the correct ammo. Now i dont know if any of my scripts will effect anything but ill send you my onPlayerSpawn script i currently have for the giveWeapon when they have <= 14 colt 45 ammo outputServerLog ( "***Spawn Script Loaded ***" ) local PlayersTeam = createTeam ( "Players" ) setTeamFriendlyFire ( PlayersTeam, false ) local spawnX, spawnY, spawnZ = math.random(-694,-679), math.random(951,963), 17 function joinHandler() spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) setPlayerTeam(source, PlayersTeam ) outputChatBox("#FF00DC"..getPlayerName(source).." #ff0000Welcome To K#ff4000e#ff7f00w#ffbf00i#ffff00z#00ff00z#00ff80l#00ffffe#0080ff'#0000ffs Zombie Server, :O :O. Press \"F9\" For HELP", source, r, g, b, true) end function deathHandler() spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) end addEventHandler("onPlayerWasted", getRootElement(), deathHandler) function giveWeaponsOnSpawn ( theSpawnpont, theTeam ) getammo = getPedTotalAmmo ( source, 2 ) if (getammo <= 14) then giveWeapon ( source, 22, 15 ) end end addEventHandler ( "onPlayerSpawn", getRootElement(), giveWeaponsOnSpawn ) addEventHandler ( "onPlayerLogin", getRootElement(), joinHandler ) the file for this is <script src="AZZ/spawns.lua" /> MY : WeaponSaver.lua addEventHandler("onPlayerWasted", root, function() local weapons = getWeaponsOfPlayers(source) setElementData(source,"isDead",true) setElementData(source,"tWeapons",weapons) end ) addEventHandler("onPlayerSpawn", root, function () local weapons = getElementData(source,"tWeapons") setElementData(source,"isDead",false) if (weapons) then giveWeaponsOfPlayer(source, weapons) end end ) function getWeaponsOfPlayer(player) local weaponSlots = 12 local weaponsTable = {} for slot=1, weaponSlots do local weapon = getPedWeapon( source, slot ) local ammo = getPedTotalAmmo( source, slot ) if (weapon > 0 and ammo > 0) then weaponsTable[weapon] = ammo end end return toJSON(weaponsTable) end function giveWeaponsOfPlayer(player, weapons) if (weapons and weapons ~= "") then for weapon, ammo in pairs(fromJSON(weapons)) do if (weapon and ammo) then giveWeapon(player, tonumber(weapon), tonumber(ammo)) end end end end addEventHandler( "onPlayerLogin",root, function( ) local acc = getPlayerAccount( source ) if acc then local weap = getAccountData( acc,'Player:weapons' ) if weap then giveWeaponsOfPlayer(source, weap) end end end ) addEventHandler( "onPlayerQuit",root, function( ) local acc = getPlayerAccount( source ) if acc and not isGuestAccount( acc ) then if getElementData(source,"isDead") == true then local weap = getElementData(source,"tWeapons") setAccountData( acc,"Player:weapons",weap ) else local weap = getWeaponsOfPlayer(source) setAccountData( acc,"Player:weapons",weap ) end end end ) P.S : Your spawn.lua outputServerLog ( "***Spawn Script Loaded ***" ) local PlayersTeam = createTeam ( "Players" ) setTeamFriendlyFire ( PlayersTeam, false ) local spawnX, spawnY, spawnZ = math.random(-694,-679), math.random(951,963), 17 function joinHandler() spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) setPlayerTeam(source, PlayersTeam ) outputChatBox("#FF00DC"..getPlayerName(source).." #ff0000Welcome To K#ff4000e#ff7f00w#ffbf00i#ffff00z#00ff00z#00ff80l#00ffffe#0080ff'#0000ffs Zombie Server, :O :O. Press \"F9\" For HELP", source, r, g, b, true) end addEventHandler ( "onPlayerLogin", getRootElement(), joinHandler ) function deathHandler() setTimer( function(source) spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) end,2000,1,source) end addEventHandler("onPlayerWasted", getRootElement(), deathHandler) enjoy and please like if it fits your need:) 1 Link to comment
kewizzle Posted March 28, 2017 Author Share Posted March 28, 2017 (edited) 6 hours ago, Ayush Rathore said: MY : WeaponSaver.lua addEventHandler("onPlayerWasted", root, function() local weapons = getWeaponsOfPlayers(source) setElementData(source,"isDead",true) setElementData(source,"tWeapons",weapons) end ) addEventHandler("onPlayerSpawn", root, function () local weapons = getElementData(source,"tWeapons") setElementData(source,"isDead",false) if (weapons) then giveWeaponsOfPlayer(source, weapons) end end ) function getWeaponsOfPlayer(player) local weaponSlots = 12 local weaponsTable = {} for slot=1, weaponSlots do local weapon = getPedWeapon( source, slot ) local ammo = getPedTotalAmmo( source, slot ) if (weapon > 0 and ammo > 0) then weaponsTable[weapon] = ammo end end return toJSON(weaponsTable) end function giveWeaponsOfPlayer(player, weapons) if (weapons and weapons ~= "") then for weapon, ammo in pairs(fromJSON(weapons)) do if (weapon and ammo) then giveWeapon(player, tonumber(weapon), tonumber(ammo)) end end end end addEventHandler( "onPlayerLogin",root, function( ) local acc = getPlayerAccount( source ) if acc then local weap = getAccountData( acc,'Player:weapons' ) if weap then giveWeaponsOfPlayer(source, weap) end end end ) addEventHandler( "onPlayerQuit",root, function( ) local acc = getPlayerAccount( source ) if acc and not isGuestAccount( acc ) then if getElementData(source,"isDead") == true then local weap = getElementData(source,"tWeapons") setAccountData( acc,"Player:weapons",weap ) else local weap = getWeaponsOfPlayer(source) setAccountData( acc,"Player:weapons",weap ) end end end ) P.S : Your spawn.lua outputServerLog ( "***Spawn Script Loaded ***" ) local PlayersTeam = createTeam ( "Players" ) setTeamFriendlyFire ( PlayersTeam, false ) local spawnX, spawnY, spawnZ = math.random(-694,-679), math.random(951,963), 17 function joinHandler() spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) setPlayerTeam(source, PlayersTeam ) outputChatBox("#FF00DC"..getPlayerName(source).." #ff0000Welcome To K#ff4000e#ff7f00w#ffbf00i#ffff00z#00ff00z#00ff80l#00ffffe#0080ff'#0000ffs Zombie Server, :O :O. Press \"F9\" For HELP", source, r, g, b, true) end addEventHandler ( "onPlayerLogin", getRootElement(), joinHandler ) function deathHandler() setTimer( function(source) spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) end,2000,1,source) end addEventHandler("onPlayerWasted", getRootElement(), deathHandler) enjoy and please like if it fits your need:) it works but my player doesnt spawn with a colt 45 when ammo is below 15. ill add this to on player spawn and let you know if it works EDIT: it did not. getammo = getPedTotalAmmo ( source, 2 ) if (getammo <= 14) then giveWeapon ( source, 22, 15 ) end end Edited March 28, 2017 by kewizzle Link to comment
kewizzle Posted March 28, 2017 Author Share Posted March 28, 2017 i got it working! outputServerLog ( "***Spawn Script Loaded ***" ) local PlayersTeam = createTeam ( "Players" ) setTeamFriendlyFire ( PlayersTeam, false ) local spawnX, spawnY, spawnZ = math.random(-694,-679), math.random(951,963), 15 function joinHandler() spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) setPlayerTeam(source, PlayersTeam ) outputChatBox("#FF00DC"..getPlayerName(source).." #ff0000Welcome To K#ff4000e#ff7f00w#ffbf00i#ffff00z#00ff00z#00ff80l#00ffffe#0080ff'#0000ffs Zombie Server, :O :O. Press \"F9\" For HELP", source, r, g, b, true) end addEventHandler ( "onPlayerLogin", getRootElement(), joinHandler ) function deathHandler() setTimer( function(source) spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) getammo = getPedTotalAmmo ( source, 2 ) if (getammo <= 14) then giveWeapon ( source, 22, 15 ) end end,1000,1,source) end addEventHandler("onPlayerWasted", getRootElement(), deathHandler) thanks all! Link to comment
Ayush Rathore Posted March 29, 2017 Share Posted March 29, 2017 16 hours ago, kewizzle said: i got it working! outputServerLog ( "***Spawn Script Loaded ***" ) local PlayersTeam = createTeam ( "Players" ) setTeamFriendlyFire ( PlayersTeam, false ) local spawnX, spawnY, spawnZ = math.random(-694,-679), math.random(951,963), 15 function joinHandler() spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) setPlayerTeam(source, PlayersTeam ) outputChatBox("#FF00DC"..getPlayerName(source).." #ff0000Welcome To K#ff4000e#ff7f00w#ffbf00i#ffff00z#00ff00z#00ff80l#00ffffe#0080ff'#0000ffs Zombie Server, :O :O. Press \"F9\" For HELP", source, r, g, b, true) end addEventHandler ( "onPlayerLogin", getRootElement(), joinHandler ) function deathHandler() setTimer( function(source) spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) getammo = getPedTotalAmmo ( source, 2 ) if (getammo <= 14) then giveWeapon ( source, 22, 15 ) end end,1000,1,source) end addEventHandler("onPlayerWasted", getRootElement(), deathHandler) thanks all! Your welcome Happy Scripting 1 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