Jump to content

فنكشن حفظ الاسلحه بعد الموت


Recommended Posts

السلام عليكم

لي 4 ايام اشتغل على متجر اسلحة وخلصته باقي ابيه لما يموت يحفظ الاسلحة يلي اشتراها

ولو قفل ورجع تبقى بالحساب

وش احتاج فنكشنات واكتبوا كل فنكشن وش حقه يسوي

:D

Link to comment
  
'onClientPlayerWasted' -- حدث لو اللاعب مات 
executeSQLQuery -- احفظ الاسلحة  
  
  
  
'onPlayerQuit' -- حدث اذا لاعب خرج  
executeSQLQuery -- احفظ الاسلحة  
  
  
'onPlayerLogin' --حدث اذا لاعب سجل 
executeSQLQuery -- احفظ الاسلحة  
  

Edited by Guest
Link to comment

لو تدوور بس في قسم دروس في البرمجة

في ناس الله يباركلهم عاملين شروحات كتيرة هاتستفاد منها :fadein:

ElementData

https://forum.multitheftauto.com/viewtopic.php?f=164&t=62041&hilit=data&sid=226c39d8dc682e81d37a34a0b1898c74

AccountData

https://forum.multitheftauto.com/viewtopic.php?f=164&t=62247&p=592815&hilit=data+account&sid=226c39d8dc682e81d37a34a0b1898c74#p592815

هاتحتاج في طريقك فنكشن يجيبلك اسلحة الاعب كلها

https://wiki.multitheftauto.com/wiki/GetPedWeapons

الحفظ بالأكونت داتا و الالمنت داتا سهل

ماتصعبهاش علي نفسك

Link to comment
  
'onClientPlayerWasted' -- حدث لو اللاعب مات 
executeSQLQuery -- احفظ الاسلحة  
triggerServerEvent -- سوي تريقر لل سيرفر 
giveWeapon -- نعطيه السلاح 
  
  
'onClientPlayerQuit' -- حدث اذا لاعب خرج  
executeSQLQuery -- احفظ الاسلحة  
  
  
'onClientPlayerJoin' --حدث اذا لاعب دخل 
triggerServerEvent -- سوي تريقر لل سيرفر 
giveWeapon -- نعطيه السلاح 
  
  

ليه كلنت للسيرفر مو لازم يقدر يسويه كلو سيرفر

مثال بسيط يحفظ لك السلاح الي الأيدي حقو 2

  
function saveAccount(source) 
    account = getPlayerAccount(source) 
    if account then 
            setAccountData(account, "WeaponID2", getPedWeapon(source, 2)) 
            setAccountData(account, "Ammo2", getPedTotalAmmo(source, 2)) 
        else 
            setAccountData(account, "WeaponID2", getPedWeapon(source, 2)) 
            setAccountData(account, "Ammo2", 100) 
    end 
end 
  
addEventHandler ( "onPlayerQuit", root, 
function() 
    local account = getPlayerAccount(source) 
    if account and not isGuestAccount(account) then 
        for slot = 1, 12 do 
            setAccountData(account, "WeaponID"..slot, getPedWeapon(source, slot)) 
            setAccountData(account, "Ammo"..slot, getPedTotalAmmo(source, slot)) 
        end 
    end 
    if not isGuestAccount(getPlayerAccount(source)) then     
        saveAccount(source) 
    end 
end) 
  
addEventHandler ( "onPlayerLogout", root, 
function () 
    local account = getPlayerAccount(source) 
    if account and not isGuestAccount(account) then 
        for slot = 1, 12 do 
            setAccountData(account, "WeaponID"..slot, getPedWeapon(source, slot)) 
            setAccountData(account, "Ammo"..slot, getPedTotalAmmo(source, slot)) 
        end 
    end 
    if not isGuestAccount(getPlayerAccount(source)) then 
        saveAccount(source) 
    end 
end) 
  
addEventHandler("onPlayerLogin", root, 
function(_, account) 
    for slot = 1, 12 do 
        local wep = getAccountData(account, "WeaponID"..slot) 
        local ammo = getAccountData(account, "Ammo"..slot) 
        if wep and ammo then 
            giveWeapon(source, wep, ammo) 
        end 
    end 
end) 
  
addEventHandler ( "onPlayerWasted", root, 
function () 
    local account = getPlayerAccount(source) 
    if account and not isGuestAccount(account) then 
        for slot = 1, 12 do 
            setAccountData(account, "WeaponID"..slot, getPedWeapon(source, slot)) 
            setAccountData(account, "Ammo"..slot, getPedTotalAmmo(source, slot)) 
        end 
    end 
end) 
  
addEventHandler("onPlayerSpawn", root, 
function() 
    local account = getPlayerAccount(source) 
    if account and not isGuestAccount(account) then 
        for slot = 1, 12 do 
            local wep = getAccountData(account, "WeaponID"..slot) 
            local ammo = getAccountData(account, "Ammo"..slot) 
            if wep and ammo then 
                giveWeapon(source, wep, ammo) 
            end 
        end 
    end 
end) 
Link to comment

ليه ما يحفظ السلاح

addEventHandler('onPlayerQuit',root,  
function()  
get =  getPlayerAccount(source) 
if not get or isGuestAccount(get) then return end 
setAccountData(get,'sss',getPedWeapons ( source )) 
end 
) 
addEventHandler('onPlayerLogin',root, 
function(aa) 
data = getAccountData(aa,'sss') 
if ( data ) then 
 giveWeapon(source, data ) 
 end 
 end 
 ) 

Link to comment
ليه ما يحفظ السلاح
addEventHandler('onPlayerQuit',root,  
function()  
get =  getPlayerAccount(source) 
if not get or isGuestAccount(get) then return end 
setAccountData(get,'sss',getPedWeapons ( source )) 
end 
) 
addEventHandler('onPlayerLogin',root, 
function() 
data = getAccountData(source,'sss') 
if ( data ) then 
 giveWeapon(source, data ) 
 end 
 end 
 ) 

addEventHandler('onPlayerQuit',root,  
function()  
get1 =  getPlayerAccount(source) 
if not get1 and isGuestAccount(get) then return end 
setAccountData(get1,'sss',getPedWeapon ( source )) 
end 
) 
addEventHandler('onPlayerLogin',root, 
function(aa) 
data = getAccountData(aa,'sss') 
if ( data ) then 
 giveWeapon(source, data ) 
 end 
 end 
 ) 

Link to comment

فيه مشكلة انه مايتعدل

جرب ذذ لو ماشتغل الي فوق

  
addEventHandler('onPlayerQuit',root, 
function() 
get1 =  getPlayerAccount(source) 
if not get1 and isGuestAccount(get1) then return end 
setAccountData(get1,'sss',getPedWeapon ( source )) 
end 
) 
addEventHandler('onPlayerLogin',root, 
function() 
data = getAccountData(source,'sss') 
if ( data ) then 
 giveWeapon(source, data ) 
 end 
 end 
 ) 
  

Edited by Guest
Link to comment
ليه ما يحفظ السلاح
addEventHandler('onPlayerQuit',root,  
function()  
get =  getPlayerAccount(source) 
if not get or isGuestAccount(get) then return end 
setAccountData(get,'sss',getPedWeapons ( source )) 
end 
) 
addEventHandler('onPlayerLogin',root, 
function(aa) 
data = getAccountData(aa,'sss') 
if ( data ) then 
 giveWeapon(source, data ) 
 end 
 end 
 ) 

addEventHandler('onPlayerQuit',root, 
function() 
get1 =  getPlayerAccount(source) 
if not get1 and isGuestAccount(get1) then return end 
setAccountData(get1,'sss',getPedWeapon ( source )) 
end 
) 
addEventHandler('onPlayerLogin',root, 
function() 
data = getAccountData(source,'sss') 
if ( data ) then 
 giveWeapon(source, data ) 
 end 
 end 
 ) 

Link to comment
ليه ما يحفظ السلاح
addEventHandler('onPlayerQuit',root,  
function()  
get =  getPlayerAccount(source) 
if not get or isGuestAccount(get) then return end 
setAccountData(get,'sss',getPedWeapons ( source )) 
end 
) 
addEventHandler('onPlayerLogin',root, 
function(aa) 
data = getAccountData(aa,'sss') 
if ( data ) then 
 giveWeapon(source, data ) 
 end 
 end 
 ) 

addEventHandler('onPlayerQuit',root, 
function() 
get1 =  getPlayerAccount(source) 
if not get1 and isGuestAccount(get1) then return end 
setAccountData(get1,'sss',getPedWeapon ( source )) 
end 
) 
addEventHandler('onPlayerLogin',root, 
function() 
data = getAccountData(source,'sss') 
if ( data ) then 
 giveWeapon(source, data ) 
 end 
 end 
 ) 

:lol::lol::lol:

شوف حقي مافي فرق

Link to comment
ليه ما يحفظ السلاح
addEventHandler('onPlayerQuit',root,  
function()  
get =  getPlayerAccount(source) 
if not get or isGuestAccount(get) then return end 
setAccountData(get,'sss',getPedWeapons ( source )) 
end 
) 
addEventHandler('onPlayerLogin',root, 
function(aa) 
data = getAccountData(aa,'sss') 
if ( data ) then 
 giveWeapon(source, data ) 
 end 
 end 
 ) 

addEventHandler('onPlayerQuit',root, 
function() 
get1 =  getPlayerAccount(source) 
if not get1 and isGuestAccount(get1) then return end 
setAccountData(get1,'sss',getPedWeapon ( source )) 
end 
) 
addEventHandler('onPlayerLogin',root, 
function() 
data = getAccountData(source,'sss') 
if ( data ) then 
 giveWeapon(source, data ) 
 end 
 end 
 ) 

:lol::lol::lol:

شوف حقي مافي فرق

isGuestAccount(get) 

شوف كودك

:|:|

Link to comment
  
addEventHandler('onPlayerQuit',root, 
function() 
get1 =  getPlayerAccount(source) 
if  get1 and not isGuestAccount(get1) then return end 
setAccountData(get1,'sss',getPedWeapon ( source )) 
end 
) 
addEventHandler('onPlayerLogin',root, 
function() 
data = getAccountData(source,'sss') 
if ( data ) then 
 giveWeapon(source, data ) 
 end 
 end 
 ) 
  

جرب ,,

Link to comment

or

  
  gc = {} 
        function getPedWeapons(ped) 
    local playerWeapons = {} 
    if ped and isElement(ped) and getElementType(ped) == "ped" or getElementType(ped) == "player" then 
        for i=2,9 do 
            local wep = getPedWeapon(ped,i) 
            if wep and wep ~= 0 then 
                table.insert(playerWeapons,wep) 
            end 
        end 
    else 
        return false 
    end 
    return playerWeapons 
end 
         
         
         
        addEventHandler('onPlayerQuit',root, 
        function() 
        gc = getPedWeapons(player) 
        for i,k in ipairs(gc) do 
        setAccountData(player,'sss',gc) 
        end 
        end 
        ) 
         
        addEventHandler('onPlayerLogin',root, 
    function() 
    data = getAccountData(player,'sss') 
    if ( data ) then 
    giveWeapon(player, data ) 
    end 
    end 
    ) 
  

Link to comment

function GetPlayerWeapons( Player ) 
    local Weapons = {} 
    for WeaponSlot = 1, 12 do 
        local Weapon = getPedWeapon( Player, WeaponSlot ) 
        if ( Weapon ~= 0 ) then 
            Weapons[WeaponSlot] = { ID = Weapon, Ammo = getPedTotalAmmo( Player, WeaponSlot ) } 
        end 
    end 
    return Weapons 
end 
  
function GivePlayerWeapons( Player, WeaponsTable ) 
    for WeaponSlot = 1, 12 do 
        local Weapon = WeaponsTable[WeaponSlot] or WeaponsTable[tostring( WeaponSlot )] 
        if ( Weapon ) then 
            giveWeapon( Player, Weapon["ID"], Weapon["Ammo"], true ) 
        end 
    end 
end 
  
local Players = getElementsByType( "player" ) 
for Index = 1, #Players do 
    local Player = Players[Index] 
    local PlayerAccount = getPlayerAccount( Player ) 
    takeAllWeapons( Player ) 
    if ( not isGuestAccount( PlayerAccount ) ) then 
        local Weapons = getAccountData( PlayerAccount, "Weapons" ) 
        if ( Weapons ) then 
            GivePlayerWeapons( Player, fromJSON( Weapons ) ) 
        end 
    end 
end 
  
addEventHandler( "onPlayerLogin", root, 
function( _, Account ) 
    takeAllWeapons( source ) 
    local Weapons = getAccountData( Account, "Weapons" ) 
    if ( Weapons ) then GivePlayerWeapons( source, fromJSON( Weapons ) ) end 
end ) 
  
function SavePlayerWeapons( Account, _, _, Player ) 
    local Boolean, Player = eventName == "onPlayerLogout", Player or source 
    Account = Boolean and Account or getPlayerAccount( Player ) 
    if ( Boolean or not isGuestAccount( Account ) ) then 
        setAccountData( Account, "Weapons", toJSON( GetPlayerWeapons( Player ) ) ) 
        if ( Boolean ) then takeAllWeapons( Player ) end 
    end 
end 
addEventHandler( "onPlayerLogout", root, SavePlayerWeapons ) 
addEventHandler( "onPlayerQuit", root, SavePlayerWeapons ) 
addEventHandler( "onResourceStop", resourceRoot, function() local Players = getElementsByType( "player" ) for Index = 1, #Players do SavePlayerWeapons( nil, nil, nil, Players[Index] ) end end ) 
  
addEventHandler( "onPlayerWasted", root, 
function() 
    local Weapons = GetPlayerWeapons( source ) 
    local function GiveWeaponsOnSpawn() GivePlayerWeapons( source, Weapons ) removeEventHandler( "onPlayerSpawn", source, GiveWeaponsOnSpawn ) end 
    addEventHandler( "onPlayerSpawn", source, GiveWeaponsOnSpawn ) 
end ) 
Edited by Guest
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...