• 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!

Lua Auto recharge assassin star on LUA SCRIPT

fyalhed

Member
Joined
Nov 18, 2017
Messages
156
Reaction score
20
I wanna make fair to paladins play without bots in my server..
Wanna use a script to when assassin star go to 0, auto it auto recharge

But idk how to do and dont find in anywhere here...

Is anybody here could help me to finish it?
Code:
local function autoRecharge(cid)
    -- CHECK IF HAVE 1 GOING TO 0 ASSASSIN STAR ON ONE OF 2 HANDS
    local ammobalance = getPlayerItemCount(cid, ammoID) - 1
    if(ammobalance >= 100) then ammobalance = 100 end

    addEvent (
        function ()
            print("RECHARGE")
            doPlayerRemoveItem(cid, ammoID, ammobalance)
            doPlayerAddItem(cid, ammoID, ammobalance)
            -- BUT FORCE IT TO GO TO HANDS
        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)
    autoRecharge(cid)
    return doCombat(cid, combat, var)
end
 
I wanna make fair to paladins play without bots in my server..
Wanna use a script to when assassin star go to 0, auto it auto recharge

But idk how to do and dont find in anywhere here...

Is anybody here could help me to finish it?
Code:
local function autoRecharge(cid)
    -- CHECK IF HAVE 1 GOING TO 0 ASSASSIN STAR ON ONE OF 2 HANDS
    local ammobalance = getPlayerItemCount(cid, ammoID) - 1
    if(ammobalance >= 100) then ammobalance = 100 end

    addEvent (
        function ()
            print("RECHARGE")
            doPlayerRemoveItem(cid, ammoID, ammobalance)
            doPlayerAddItem(cid, ammoID, ammobalance)
            -- BUT FORCE IT TO GO TO HANDS
        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)
    autoRecharge(cid)
    return doCombat(cid, combat, var)
end

First explain, what type of server you are creating war etc, if its war then just go to lua and remove this line.

DoPlayerRemoveItem

Your stars will be unlimited!
 
Lua:
local itemID = 7366
local function refillAssassinStars(cid, ammo_count)
    if isPlayer(cid) then
        doPlayerRemoveItem(cid, itemID, ammo_count)
        doPlayerAddItem(cid, itemID, ammo_count)
    end
end
local function autoRefillAssassinStars(cid) 
    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 == itemID then
        hand_to_check = CONST_SLOT_LEFT
    elseif right_hand.uid ~= 0 and right_hand.itemid == itemID then
        hand_to_check = CONST_SLOT_RIGHT
    end
   
    local ammo_in_slot = getPlayerSlotItem(cid, hand_to_check).type
    if ammo_in_slot ~= 1 then
        return false
    end

    local ammo_count = getPlayerItemCount(cid, itemID) 
    local count = getPlayerItemCount(cid, itemID) 
    ammo_count = ammo_count >= 100 and 100 or ammo_count
    if count > 1 then
        addEvent(refillAssassinStars, 1, cid, ammo_count)
    else
        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)
    min = 5
    max = 15
    return -min, -max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onUseWeapon(cid, var)
    autoRefillAssassinStars(cid)
    return doCombat(cid, combat, var)
end
 
Lua:
local itemID = 7366
local function refillAssassinStars(cid, ammo_count)
    if isPlayer(cid) then
        doPlayerRemoveItem(cid, itemID, ammo_count)
        doPlayerAddItem(cid, itemID, ammo_count)
    end
end
local function autoRefillAssassinStars(cid)
    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 == itemID then
        hand_to_check = CONST_SLOT_LEFT
    elseif right_hand.uid ~= 0 and right_hand.itemid == itemID then
        hand_to_check = CONST_SLOT_RIGHT
    end
  
    local ammo_in_slot = getPlayerSlotItem(cid, hand_to_check).type
    if ammo_in_slot ~= 1 then
        return false
    end

    local ammo_count = getPlayerItemCount(cid, itemID)
    local count = getPlayerItemCount(cid, itemID)
    ammo_count = ammo_count >= 100 and 100 or ammo_count
    if count > 1 then
        addEvent(refillAssassinStars, 1, cid, ammo_count)
    else
        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)
    min = 5
    max = 15
    return -min, -max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onUseWeapon(cid, var)
    autoRefillAssassinStars(cid)
    return doCombat(cid, combat, var)
end

Thank you bro!

No errors, but not work, just now recharge
 
Some time ago, i got this same problem...
I've tried to make exacly like it, but for small stones, should be nice, but i gave up.

I think the problem is, it's removing the item, addaing again, but not on hands, on backpack

Make some prints to test
 
Code:
local itemID = 7366
local function refillAssassinStars(cid, ammo_count)
    if isPlayer(cid) then
       print("RECHARGE")
        doPlayerRemoveItem(cid, itemID, ammo_count)
        doPlayerAddItem(cid, itemID, ammo_count)
    end
end
local function autoRefillAssassinStars(cid)
    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 == itemID then
        hand_to_check = CONST_SLOT_LEFT
    elseif right_hand.uid ~= 0 and right_hand.itemid == itemID then
        hand_to_check = CONST_SLOT_RIGHT
    end
    print(hand_to_check)
   
    local ammo_in_slot = getPlayerSlotItem(cid, hand_to_check).type
    print(ammo_in_slot)
    if ammo_in_slot ~= 1 then
        return false
    end
    local ammo_count = getPlayerItemCount(cid, itemID)
    local count = getPlayerItemCount(cid, itemID)
    ammo_count = ammo_count >= 100 and 100 or ammo_count
    if count > 1 then
        addEvent(refillAssassinStars, 1, cid, ammo_count)
    else
        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)
    min = 5
    max = 15
    return -min, -max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onUseWeapon(cid, var)
    autoRefillAssassinStars(cid)
    return doCombat(cid, combat, var)
end

4 shots with 2 assassin stars on hands until over to 0
(had 100 on backpack)

print
Code:
0
0
0
0
0
0
0
0
 
There is a wrong function in here?
Code:
    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 == itemID then
        hand_to_check = CONST_SLOT_LEFT
    elseif right_hand.uid ~= 0 and right_hand.itemid == itemID then
        hand_to_check = CONST_SLOT_RIGHT
    end
    print(hand_to_check)

Because hand_to_check is always returning 0, and bugging everything else, i think so
 
@buchaLL
TFS 0.X - Auto assassin star recharge

Your script is literally my script without the prints and changing the item name.
Great job.
Here's the original script before I started testing random stuff to find the issue and had him post the 'latest' portion into his thread.
Lua:
local function autoRefillAssassinStars(cid)
    local assassin_stars_itemID = 111111
 
    -- 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
        hand_to_check = CONST_SLOT_LEFT
    elseif right_hand.uid ~= 0 and right_hand.itemid == assassin_stars_itemID then
        hand_to_check = CONST_SLOT_RIGHT
    else
        return false
    end
 
    -- check if only 1 ammo left
    local ammo_count = getPlayerSlotItem(cid, hand_to_check).type
    if ammo_in_slot ~= 1 then
        return false
    end
 
    -- refill assassin stars
    local ammo_count = getPlayerItemCount(cid, assassin_stars_itemID) - 1
    ammo_count = ammo_count >= 100 and 100 or ammo_count
    addEvent (
        function ()
            doPlayerRemoveItem(cid, assassin_stars_itemID, ammo_count)
            doPlayerAddItem(cid, assassin_stars_itemID, ammo_count)
        end, 1
    )
    return true
end

@fyalhed

I already told you the problem months ago, but you literally only reply once every 1-3 days with the same stuff as above.
"Thank you bro! No errors, but not work, just now recharge"
I asked to teamviewer to test a few different work-arounds because your server doesn't work like my 0.3.7 .
Ignored that suggestion and continued to ask for help, so I told you to post the current script into your thread and get someone else to help.

So, like before, I'm going to tell you the issue.
The server is ignoring the item in your hand and removing then replacing the items from your backpack.
You can check this in 15 seconds by changing the itemid of items being given to the player to diamonds, or some other stackable item.

So yes, the script it working, just not as intended on your current server version.

So, like before, I'm going to tell you that a work-around is the easiest way to solve this issue.
First part is to refill the stars/stones when there are 2 or more left. Main reason being we can't be certain the items are going to disappear since they have a break chance.
Second part is to remove the stars/stones like we already are, then edit the item in the players hand directly to increase it's count.

Since there is at least 6 different ways to accomplish the second part, there is bound to be a work-around that will work for you.

------
To answer your question about it constantly printing 0000000000
It's because you have the wrong f*** item id in the script.
assassin stars == 7368
 
@buchaLL
TFS 0.X - Auto assassin star recharge

Your script is literally my script without the prints and changing the item name.
Great job.
Here's the original script before I started testing random stuff to find the issue and had him post the 'latest' portion into his thread.
Lua:
local function autoRefillAssassinStars(cid)
    local assassin_stars_itemID = 111111
 
    -- 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
        hand_to_check = CONST_SLOT_LEFT
    elseif right_hand.uid ~= 0 and right_hand.itemid == assassin_stars_itemID then
        hand_to_check = CONST_SLOT_RIGHT
    else
        return false
    end
 
    -- check if only 1 ammo left
    local ammo_count = getPlayerSlotItem(cid, hand_to_check).type
    if ammo_in_slot ~= 1 then
        return false
    end
 
    -- refill assassin stars
    local ammo_count = getPlayerItemCount(cid, assassin_stars_itemID) - 1
    ammo_count = ammo_count >= 100 and 100 or ammo_count
    addEvent (
        function ()
            doPlayerRemoveItem(cid, assassin_stars_itemID, ammo_count)
            doPlayerAddItem(cid, assassin_stars_itemID, ammo_count)
        end, 1
    )
    return true
end

@fyalhed

I already told you the problem months ago, but you literally only reply once every 1-3 days with the same stuff as above.
"Thank you bro! No errors, but not work, just now recharge"
I asked to teamviewer to test a few different work-arounds because your server doesn't work like my 0.3.7 .
Ignored that suggestion and continued to ask for help, so I told you to post the current script into your thread and get someone else to help.

So, like before, I'm going to tell you the issue.
The server is ignoring the item in your hand and removing then replacing the items from your backpack.
You can check this in 15 seconds by changing the itemid of items being given to the player to diamonds, or some other stackable item.

So yes, the script it working, just not as intended on your current server version.

So, like before, I'm going to tell you that a work-around is the easiest way to solve this issue.
First part is to refill the stars/stones when there are 2 or more left. Main reason being we can't be certain the items are going to disappear since they have a break chance.
Second part is to remove the stars/stones like we already are, then edit the item in the players hand directly to increase it's count.

Since there is at least 6 different ways to accomplish the second part, there is bound to be a work-around that will work for you.

------
To answer your question about it constantly printing 0000000000
It's because you have the wrong f*** item id in the script.
assassin stars == 7368


I'm so sorry xikini, to the long about the answers, for now i just make the server for me and my friends local, i cant be connected so much for now
I thought you had given up
TV not work in here

And thank you again to help with my dumbness XD

Guys with this feedback i tried more things, could you help me and the others who are trying to use the script?

50 stars on backpack, 3 on hands
tests:

2 codes

CODE 1
Code:
local itemID = 7368
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 18)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

local function autoRechargeDistanceHandWeapon(cid)
    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 == itemID then
        hand_to_check = CONST_SLOT_LEFT
    elseif right_hand.uid ~= 0 and right_hand.itemid == itemID then
        hand_to_check = CONST_SLOT_RIGHT
    end
    -- munição da mão
    local ammo_in_slot = getPlayerSlotItem(cid, hand_to_check).type
    -- ammo na mão não é == 1
    if ammo_in_slot > 3 then
        return false
    end
    local ammo_count = getPlayerItemCount(cid, itemID) - 1
    ammo_count = ammo_count >= 100 and 100 or ammo_count
    addEvent (
        function ()
            doPlayerRemoveItem(cid, itemID, ammo_count)
            doPlayerAddItem(cid, itemID, ammo_count)
        end, 1
    )
end

function onGetFormulaValues(cid, level, skill, attack, factor)
    min = 5
    max = 15
    return -min, -max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")


function onUseWeapon(cid, var)
    autoRechargeDistanceHandWeapon(cid)
    return doCombat(cid, combat, var)
end

results:
When i shot and the star broke, it recharge to the hands perfectlly
But if the star do not broke, it sounds like recharge, but to backpack, and the hands be empty


CODE 2
Code:
local itemID = 7368
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 18)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

local function autoRechargeDistanceHandWeapon(cid)
    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 == itemID then
        hand_to_check = CONST_SLOT_LEFT
    elseif right_hand.uid ~= 0 and right_hand.itemid == itemID then
        hand_to_check = CONST_SLOT_RIGHT
    end
    -- munição da mão
    local ammo_in_slot = getPlayerSlotItem(cid, hand_to_check).type
    -- ammo na mão não é == 1
    if ammo_in_slot > 3 then
        return false
    end
    -- gambiarra pq só ta refilando quando quebra o item na hora da refilada
    doPlayerRemoveItem(cid, itemID, 1)
    -- recharge, tirei o -1 no final, pq tem a gambiarra ali em cima
    local ammo_count = getPlayerItemCount(cid, itemID)
    ammo_count = ammo_count >= 100 and 100 or ammo_count
    addEvent (
        function ()
            doPlayerRemoveItem(cid, itemID, ammo_count)
            doPlayerAddItem(cid, itemID, ammo_count)
        end, 1
    )
end

function onGetFormulaValues(cid, level, skill, attack, factor)
    min = 5
    max = 15
    return -min, -max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")


function onUseWeapon(cid, var)
    autoRechargeDistanceHandWeapon(cid)
    return doCombat(cid, combat, var)
end

With this code, when i shot if the star dont broke, it duplicate the stars
If the stars broke, it work fine
 
Back
Top