Jump to content

Saving Weapons Script, doesn't work, where?


12p

Recommended Posts

I made a simple script to make players to save their weapons when they leave, and load their weapons when they login.

Someway it doesn't work, but I don't know why...

It doesn't look like having any problem while /debugscript 3

And it works at full with custom debug, too...

slots = { 1, 2, 3, 4, 5, 6 } 
function save.weapons ( ped, acc )  
    if not source then source = ped end 
    if not acc then acc = getPlayerAccount ( source ) end 
    takeAllWeapons ( ped ) 
    for i, s in ipairs ( slots ) do 
        setPedWeaponSlot ( source, s ) 
        local w = getPedWeapon ( source ) 
        local a = getPedTotalAmmo ( source, s ) 
        local a = a + getPedAmmoInClip ( source ) 
        setAccountData ( acc, "save:weapon"..tostring ( s ), w ) 
        setAccountData ( acc, "save:ammo"..tostring ( s ), a ) 
    end 
end 
  
function load.weapons ( ped, acc )  
    if not source then source = ped end 
    if not acc then acc = getPlayerAccount ( source ) end 
    if getAccountData ( acc, "save:name" ) then 
        for i, s in ipairs ( slots ) do 
            local w = getAccountData ( acc, "save:weapon"..tostring ( s ) ) 
            local a = getAccountData ( acc, "save:ammo"..tostring ( s ) ) 
            if w ~= 0 and a > 0 then giveWeapon ( source, w, a, false ) end 
        end 
    end 
end 
  

use

  
getPedWeaponSlot 
  

Link to comment

LoL. I was wrong on takeAllWeapons; it must be before loading weapons, not saving ^^. Gonna test and check what happens now.

EDIT: I'm getting a bit stupid or what? That was all the prob. (but weird, before I changed that code, it didn't work)...

EDIT 2: WTF It works ok when I have 1 weapon to save, but when I have more than 1 weapon, it saves only 1 weapon's ammo... O_o

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