• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 0.X Auto recharge assassin stars on hands

fyalhed

Member
Joined
Nov 18, 2017
Messages
156
Reaction score
20
Why this script is not recharging assassin star on hands?

This script should work like this, when you shot the last assassin star u hand on hands, it recharge with how many u have in your backpack

I've changed doPlayerAddItem(cid,assassin_stars_itemID, ammo_count)
To doPlayerAddItem(cid, 2260, ammo_count)

Blank runes (2260) just for a test, with blank runes, when you shot the last assassin star it add blank runes that u have stars in your hands

But if i change to doPlayerAddItem(cid,assassin_stars_itemID, ammo_count), sounds like script doing nothing, i think is re-adding, but still on backpack, not on hands

Code:
local assassin_stars_itemID = 7368
local function refillAssassinStars(cid, ammo_count)
    if isPlayer(cid) then
        print(01001)
        doPlayerRemoveItem(cid, assassin_stars_itemID, ammo_count)
        doPlayerAddItem(cid, 2260, ammo_count)
        print(01002)
        print("Finished normally, ammo refilled.")
    end
end
local function autoRefillAssassinStars(cid)  
    -- find which hand has assassin stars equipped
    local hand_to_check = 0
    local left_hand = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
    local right_hand = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    if left_hand.uid ~= 0 and left_hand.itemid == assassin_stars_itemID then
        print(111)
        hand_to_check = CONST_SLOT_LEFT
    elseif right_hand.uid ~= 0 and right_hand.itemid == assassin_stars_itemID then
        print(222)
        hand_to_check = CONST_SLOT_RIGHT
    else
        print("ERROR -- This should be impossible to ever see.")
        if left_hand.uid ~= 0 then
            print("" .. left_hand.uid .. ", " .. left_hand.itemid .. "")
        else
            print("" .. left_hand.uid .. ", 0")
        end
        if right_hand.uid ~= 0 then
            print("" .. right_hand.uid .. ", " .. right_hand.itemid .. "")
        else
            print("" .. right_hand.uid .. ", 0")
        end
        return false
    end
   
    print(333)
    -- check if only 1 ammo left
    local ammo_in_slot = getPlayerSlotItem(cid, hand_to_check).type
    print(ammo_in_slot)
    if ammo_in_slot ~= 1 then
        print("Finished normally, ammo not refilled. (ammo in slot above 1)")
        return false
    end
   
    print(444)
    -- refill assassin stars
    local ammo_count = getPlayerItemCount(cid, assassin_stars_itemID) - 1
    print(ammo_count)
    ammo_count = ammo_count >= 100 and 100 or ammo_count
    print(ammo_count)
    if ammo_count > 0 then
        addEvent(refillAssassinStars, 1, cid, ammo_count)
    else
        print("Finished normally, ammo not refilled. (no ammo available for refill.)")
        return false
    end
    return true
end
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 18)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
function onGetFormulaValues(cid, level, skill, attack, factor)
    -- get attack mode
    local damagebase_min = wbdmg_distance_min
    local damagebase_max = wbdmg_distance_max
    if factor == 1.0 then -- player_fight_mode = offensive
        damagebase_min = damagebase_min * 3
        damagebase_max = damagebase_max * 3
    elseif factor == 2.0 then -- player_fight_mode = defensive
        damagebase_min = damagebase_min * 1
        damagebase_max = damagebase_max * 1
    else  -- player_fight_mode = balanced
        damagebase_min = damagebase_min * 2
        damagebase_max = damagebase_max * 2
    end
    min = ((damagebase_min) * (attack * 12) * (skill * 3)) * -0.10
    max = ((damagebase_max) * (attack * 12) * (skill * 3)) * -1.00
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onUseWeapon(cid, var)
    autoRefillAssassinStars(cid)
    return doCombat(cid, combat, var)
end

Anybody know how to fix this?
 
I am going to assume you wrote this from scratch?

See when you write a script you write out the basics of what it is suppose to do, when its working like you want it to then you start adding in things and test the new additions but you still test the things you already tested so that you know everything works with everything else.

When you write everything all out at once or write out things but don't test previous things you write, instead you just keep adding to the script, it makes it more time consuming and somewhat frustrating to trouble a script.
 
I am going to assume you wrote this from scratch?

See when you write a script you write out the basics of what it is suppose to do, when its working like you want it to then you start adding in things and test the new additions but you still test the things you already tested so that you know everything works with everything else.

When you write everything all out at once or write out things but don't test previous things you write, instead you just keep adding to the script, it makes it more time consuming and somewhat frustrating to trouble a script.

I'm sorry, i dont understand your point, everything was tested was you can see on prints, the problem is if i remove a item to add another, its works, but when i try to add the item assassin star id n try to add assassin star item id, looks like it even dont move
 
doPlayerAddItem(cid,assassin_stars_itemID, ammo_count) -- Your line?
doPlayerAddItem(cid, 7368, ammo_count) -- Thats not work to?
You dont need "local" for this function i think :eek: Just write ID - 7368

My fault its not about the item ID or variable

If i do:
Code:
local assassin_stars_itemID = 7368
local function refillAssassinStars(cid, ammo_count)
    if isPlayer(cid) then
        print(01001)
        doPlayerRemoveItem(cid, assassin_stars_itemID, ammo_count)
        doPlayerAddItem(cid, assassin_stars_itemID, ammo_count)
        print(01002)
        print("Finished normally, ammo refilled.")
    end
end
local function autoRefillAssassinStars(cid)  
    -- find which hand has assassin stars equipped
    local hand_to_check = 0
    local left_hand = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
    local right_hand = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    if left_hand.uid ~= 0 and left_hand.itemid == assassin_stars_itemID then
        print(111)
        hand_to_check = CONST_SLOT_LEFT
    elseif right_hand.uid ~= 0 and right_hand.itemid == assassin_stars_itemID then
        print(222)
        hand_to_check = CONST_SLOT_RIGHT
    else
        print("ERROR -- This should be impossible to ever see.")
        if left_hand.uid ~= 0 then
            print("" .. left_hand.uid .. ", " .. left_hand.itemid .. "")
        else
            print("" .. left_hand.uid .. ", 0")
        end
        if right_hand.uid ~= 0 then
            print("" .. right_hand.uid .. ", " .. right_hand.itemid .. "")
        else
            print("" .. right_hand.uid .. ", 0")
        end
        return false
    end
   
    print(333)
    -- check if only 1 ammo left
    local ammo_in_slot = getPlayerSlotItem(cid, hand_to_check).type
    print(ammo_in_slot)
    if ammo_in_slot ~= 1 then
        print("Finished normally, ammo not refilled. (ammo in slot above 1)")
        return false
    end
   
    print(444)
    -- refill assassin stars
    local ammo_count = getPlayerItemCount(cid, assassin_stars_itemID) - 1
    print(ammo_count)
    ammo_count = ammo_count >= 100 and 100 or ammo_count
    print(ammo_count)
    if ammo_count > 0 then
        addEvent(refillAssassinStars, 1, cid, ammo_count)
    else
        print("Finished normally, ammo not refilled. (no ammo available for refill.)")
        return false
    end
    return true
end
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 18)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
function onGetFormulaValues(cid, level, skill, attack, factor)
    -- get attack mode
    local damagebase_min = wbdmg_distance_min
    local damagebase_max = wbdmg_distance_max
    if factor == 1.0 then -- player_fight_mode = offensive
        damagebase_min = damagebase_min * 3
        damagebase_max = damagebase_max * 3
    elseif factor == 2.0 then -- player_fight_mode = defensive
        damagebase_min = damagebase_min * 1
        damagebase_max = damagebase_max * 1
    else  -- player_fight_mode = balanced
        damagebase_min = damagebase_min * 2
        damagebase_max = damagebase_max * 2
    end
    min = ((damagebase_min) * (attack * 12) * (skill * 3)) * -0.10
    max = ((damagebase_max) * (attack * 12) * (skill * 3)) * -1.00
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onUseWeapon(cid, var)
    autoRefillAssassinStars(cid)
    return doCombat(cid, combat, var)
end

Sometimes it's recharging, and sometimes not, and idk why the fuck


rechargded fine
Code:
111
333
1
444
69
69
1001
1002
Finished normally, ammo refilled.

next 1 assasssin star, not recharged, idk why
Code:
111
333
1
444
68
68
1001
1002
Finished normally, ammo refilled.

Did you guys know wtf is wrong?
 
Overwrite your script with this and check.

Lua:
local function autoAssassinStars(cid)
    local ammostatus = getPlayerSlotItem(cid, CONST_RIGHT_HAND).uid or getPlayerSlotItem(cid, CONST_LEFT_HAND).uid
    if ammostatus == 0 then
        return false
    end
    ammostatus = getPlayerSlotItem(cid, CONST_SLOT_RIGHT_HAND).type or getPlayerSlotItem(cid, CONST_SLOT_LEFT_HAND).type
    if ammostatus ~= 1 then
        return false
    end
  
    local ammoID = getPlayerSlotItem(cid, CONST_SLOT_RIGHT_HAND).itemid or getPlayerSlotItem(cid, CONST_SLOT_LEFT_HAND).itemid
    local ammobalance = getPlayerItemCount(cid, ammoID) - 1
    ammobalance = ammobalance >= 100 and 100 or ammobalance
    addEvent (
        function ()
            doPlayerRemoveItem(cid, ammoID, ammobalance)
            doPlayerAddItem(cid, ammoID, ammobalance)
        end, 1
    )
    return true
end

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 18)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
function onGetFormulaValues(cid, level, skill, attack, factor)
    -- get attack mode
    local damagebase_min = wbdmg_distance_min
    local damagebase_max = wbdmg_distance_max
    if factor == 1.0 then -- player_fight_mode = offensive
        damagebase_min = damagebase_min * 3
        damagebase_max = damagebase_max * 3
    elseif factor == 2.0 then -- player_fight_mode = defensive
        damagebase_min = damagebase_min * 1
        damagebase_max = damagebase_max * 1
    else  -- player_fight_mode = balanced
        damagebase_min = damagebase_min * 2
        damagebase_max = damagebase_max * 2
    end
    min = ((damagebase_min) * (attack * 12) * (skill * 3)) * -0.10
    max = ((damagebase_max) * (attack * 12) * (skill * 3)) * -1.00
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onUseWeapon(cid, var)
    autoAssassinStars(cid)
    return doCombat(cid, combat, var)
end
 
Overwrite your script with this and check.

Lua:
local function autoAssassinStars(cid)
    local ammostatus = getPlayerSlotItem(cid, CONST_RIGHT_HAND).uid or getPlayerSlotItem(cid, CONST_LEFT_HAND).uid
    if ammostatus == 0 then
        return false
    end
    ammostatus = getPlayerSlotItem(cid, CONST_SLOT_RIGHT_HAND).type or getPlayerSlotItem(cid, CONST_SLOT_LEFT_HAND).type
    if ammostatus ~= 1 then
        return false
    end
 
    local ammoID = getPlayerSlotItem(cid, CONST_SLOT_RIGHT_HAND).itemid or getPlayerSlotItem(cid, CONST_SLOT_LEFT_HAND).itemid
    local ammobalance = getPlayerItemCount(cid, ammoID) - 1
    ammobalance = ammobalance >= 100 and 100 or ammobalance
    addEvent (
        function ()
            doPlayerRemoveItem(cid, ammoID, ammobalance)
            doPlayerAddItem(cid, ammoID, ammobalance)
        end, 1
    )
    return true
end

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 18)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
function onGetFormulaValues(cid, level, skill, attack, factor)
    -- get attack mode
    local damagebase_min = wbdmg_distance_min
    local damagebase_max = wbdmg_distance_max
    if factor == 1.0 then -- player_fight_mode = offensive
        damagebase_min = damagebase_min * 3
        damagebase_max = damagebase_max * 3
    elseif factor == 2.0 then -- player_fight_mode = defensive
        damagebase_min = damagebase_min * 1
        damagebase_max = damagebase_max * 1
    else  -- player_fight_mode = balanced
        damagebase_min = damagebase_min * 2
        damagebase_max = damagebase_max * 2
    end
    min = ((damagebase_min) * (attack * 12) * (skill * 3)) * -0.10
    max = ((damagebase_max) * (attack * 12) * (skill * 3)) * -1.00
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onUseWeapon(cid, var)
    autoAssassinStars(cid)
    return doCombat(cid, combat, var)
end


No errrors, just not work :(
 
Back
Top