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

Xikini's Free Scripting Service. [0.3.7 & (0.3.6/0.4)]

Status
Not open for further replies.

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,788
Solutions
581
Reaction score
5,354
Doing quick (30 min or less) scripts for [0.3.7 & (0.3.6/0.4)]
I am not here to fix your broken scripts, although I will give advice if requested.
I am here for script requests of scripts not already available on the forum.
If you require support for your scripting issues please make a thread in the support section.

For clarity's sake,
I will script actionscripts, creaturescripts, globalevents, talkactions, movements, npcs for you.
I will not script spells, weapons, raids or monster scripts.
Additionally, source editing, websites and database queries are a no go as well.

Code:
How to make shorter links to posts.
https://otland.net/threads/234306/page-14#post-2330703
 
Last edited:
Hi!
The script of the event I already have.

When server starts, will set all globalstorage(getPlayersGuildId,0) -- > globalstorage(getPlayersGuildId) -> will be the counter storage

At the end of the event, he would have to get the largest globalStorage (getPlayerGuildId)

Here is the question: I should check the players that are online, and those with guild to check the largest globalstorage (getPlayerGuildId),
Is there any way to do this check? Thank you for answering my questions.
Definitely.
Lua:
for _, pid in ipairs(getPlayersOnline()) do
    print(getPlayerName(pid))
end
 
Hi, @Xikini!
I had an idea, see if you can create this script:

- If the player with vocation 9 and 10 attacks another player with the vocation {1,2,3,4,5,6,7,8}. The targets (Players with vocation 1-8) receive only 25% of the damage of the total damage.

(DAMAGE* 0.25) = FINAL DAMAGE.

Ex: Player with vocation 9 attack a player of vocation 6 with 4000 damage.
The player with vocation 6 receives only 1000 damage.

Its possible to make?

Thank you so much!
 
Hi, @Xikini!
I had an idea, see if you can create this script:

- If the player with vocation 9 and 10 attacks another player with the vocation {1,2,3,4,5,6,7,8}. The targets (Players with vocation 1-8) receive only 25% of the damage of the total damage.

(DAMAGE* 0.25) = FINAL DAMAGE.

Ex: Player with vocation 9 attack a player of vocation 6 with 4000 damage.
The player with vocation 6 receives only 1000 damage.

Its possible to make?

Thank you so much!
onStatsChange in the only function we currently have, and it only shows the final result being applied to the character, after all other sources of mitigation have been passed. (armor/shielding/et cetera.)

The only way to accurately adjust the damage being applied to the character, is from the damage sources themselves, and adjusting the values before they go through the sources regular calculations. (spells/weapons/monsters/et cetera)

If you search around, I've made 2-3 threads about this particular subject, and commented in countless others.

There's no way to automatically adjust the damage without a new function.
 
@Xikini
onStatsChange in the only function we currently have, and it only shows the final result being applied to the character, after all other sources of mitigation have been passed. (armor/shielding/et cetera.)

The only way to accurately adjust the damage being applied to the character, is from the damage sources themselves, and adjusting the values before they go through the sources regular calculations. (spells/weapons/monsters/et cetera)

If you search around, I've made 2-3 threads about this particular subject, and commented in countless others.

There's no way to automatically adjust the damage without a new function.

In that case, no problem. Many thanks for the explanation!!!
 
What kind of new function?
Because you are incorrect in your assumption ;)
They aren't assumptions Codex.
You cannot change onstatschange values. You can only allow or deny them.

The function you would require/need is one which grabs the values before calculations are done and allows you to return a new value to submit through.
 

You work with NPC? Because I need help with that:

"I would like a help in designing a script of an NPC that teleports all the players that are in party (as the title already says).
It would work as follows: The leader of the party would talk to the NPC and he would teleport all players to the local X.
Transcripts, to facilitate if someone is willing to do, would be:
player: hi
npc: I'm surprised you could have come here to challenge me (if you are the party leader)
npc: You are not leader of any party (if not a party leader)
player: challenge
npc: To challenge me, you must have a sacrifice, you have it?
player: yes
npc: Ok then. I hope you are prepared (if the player has the item would remove one item from id: CCCC and teleport all that had in party with him)
npc: You do not have the type of sacrifice that I would like (if the player does not have the item)

After teleporting the players, the npc would disappear for 10 minutes, to avoid that another party enters the place as well.
If it can be do, this npc would not open the NPC channel, it would be that neither in the old versions, to be able to avoid that more of a person talks to him at the same time.
Also a time script for fromPos area: XXXXXX toPos: YYYYYY that after 10 minutes, teleport all player in that área to the temple."

I made a thread and one user help me with the part that NPC teleport party members and just talk with the leader, but I don't know how to do the rest and where put it. If you can help me, I thank you in advance.
 
You work with NPC? Because I need help with that:

"I would like a help in designing a script of an NPC that teleports all the players that are in party (as the title already says).
It would work as follows: The leader of the party would talk to the NPC and he would teleport all players to the local X.
Transcripts, to facilitate if someone is willing to do, would be:
player: hi
npc: I'm surprised you could have come here to challenge me (if you are the party leader)
npc: You are not leader of any party (if not a party leader)
player: challenge
npc: To challenge me, you must have a sacrifice, you have it?
player: yes
npc: Ok then. I hope you are prepared (if the player has the item would remove one item from id: CCCC and teleport all that had in party with him)
npc: You do not have the type of sacrifice that I would like (if the player does not have the item)

After teleporting the players, the npc would disappear for 10 minutes, to avoid that another party enters the place as well.
If it can be do, this npc would not open the NPC channel, it would be that neither in the old versions, to be able to avoid that more of a person talks to him at the same time.
Also a time script for fromPos area: XXXXXX toPos: YYYYYY that after 10 minutes, teleport all player in that área to the temple."

I made a thread and one user help me with the part that NPC teleport party members and just talk with the leader, but I don't know how to do the rest and where put it. If you can help me, I thank you in advance.
Okay but shh. Don't tell @Werewolf . I'm supposed to be working on our server. ^.^

By the way, this was actually fun and helpful for me, since I didn't realise the lua-made function 'getPartyLeader(uid)' is actually broken.
So I had to create my own custom function just for this script.
Enjoy!


data/npc/test npc.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Test Npc" script="data/npc/scripts/test_npc.lua" walkinterval="500" floorchange="0">
   <health now="100" max="100"/>
   <look type="141" head="115" body="122" legs="116" feet="56" addons="0"/>
</npc>
data/npc/scripts/test_npc.lua
Lua:
local config = {
   teleport_position = {x = 1502, y = 1500, z = 1},
   sacrifice = 2160,
   amount = 10
}

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)       npcHandler:onCreatureAppear(cid)       end
function onCreatureDisappear(cid)     npcHandler:onCreatureDisappear(cid)       end
function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg)     end

function onThink()
   npcHandler:onThink()
end

local function checkPartyDetails(cid)
   -- 0 = no party
   -- 1 = in party
   -- 2 = party leader
   -- 3 = party leader only
   local party = getPlayerParty(cid)
   if party then
       if party == cid then
           local members = getPartyMembers(party)
           if #members > 1 then
               return 2
           else
               return 3
           end
       else
           return 1
       end
   end
   return 0
end

function greet(cid)
   local party_check = checkPartyDetails(cid)
   if party_check == 2 then
       npcHandler:setMessage(MESSAGE_GREET, "I'm surprised you have come here to (challenge) me.")
       talkState[cid] = 0
       return true
   elseif party_check == 3 then
       npcHandler:setMessage(MESSAGE_GREET, "Your party must contain more then yourself.")
   else
       npcHandler:setMessage(MESSAGE_GREET, "You are not the leader of any party.")
   end
   talkState[cid] = 0
   addEvent (
       function ()
           npcHandler:releaseFocus(cid)  
       end, 0
   )
   return true
end

local function teleport_party(cid, position)
   for _, pid in pairs(getPartyMembers(cid)) do
       doTeleportThing(pid, position)
   end
   return true
end

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
  
   local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  
   if checkPartyDetails(cid) ~= 2 then
       selfSay("Where has your party gone?! Come back when you've found them again.", cid)
       talkState[talkUser] = 0
       npcHandler:releaseFocus(cid)
       return true
   end
  
   if msgcontains(msg, "challenge") then
       selfSay("To challenge me, you must have a sacrifice, you have it? (10 crystal coins)", cid)
       talkState[talkUser] = 1
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
       if getPlayerItemCount(cid, config.sacrifice) >= config.amount then
           selfSay("Ok then. I hope you are prepared. Tell me when you are (ready).", cid)
           talkState[talkUser] = 2
       else
           selfSay("You do not have the type of sacrifice that I would like.", cid)
           talkState[talkUser] = 0  
       end
   elseif msgcontains(msg, "ready") and talkState[talkUser] == 2 then
       talkState[talkUser] = 0  
       if getPlayerItemCount(cid, config.sacrifice) >= config.amount then
           doPlayerRemoveItem(cid, config.sacrifice, config.amount)
           selfSay("So be it!", cid)
           teleport_party(cid, config.teleport_position)
           npcHandler:releaseFocus(cid)
           return true
       else
           selfSay("Where did your sacrifice go? Ask to (challenge) me again when you've got the sacrifice on you!", cid)
       end      
   end
  
   return true  
end


npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Okay but shh. Don't tell @Werewolf . I'm supposed to be working on our server.

Thanks alot, the NPC runs fine in talk only with the party leader and teleport party players.

You know how to make the NPC disappear and back after 10 minutes? I think it's made by addEvent, but as I said, I'm very beginner in script, and I don't know how to do that. I tried to do it by myself, but I got TFS crash.
I made like:
local pos_npc = getThingPos(getNpcId()) ---- in the end of local config
doRemoveCreature(getNpcId()) -------- after teleport_party(cid, config.teleport_position)
addEvent(doCreateNpc, 4*1000, "Armando", pos_npc) ----- doRemoveCreature(getNpcId())
 
Thanks alot, the NPC runs fine in talk only with the party leader and teleport party players.

You know how to make the NPC disappear and back after 10 minutes? I think it's made by addEvent, but as I said, I'm very beginner in script, and I don't know how to do that. I tried to do it by myself, but I got TFS crash.
I made like:
local pos_npc = getThingPos(getNpcId()) ---- in the end of local config
doRemoveCreature(getNpcId()) -------- after teleport_party(cid, config.teleport_position)
addEvent(doCreateNpc, 4*1000, "Armando", pos_npc) ----- doRemoveCreature(getNpcId())
Oh sorry. I completely forgot about the second part of your request.
That's fairly easy to do.. but I'd suggest against removing the npc.
Just setup a global_storage so nobody can talk to the npc, for 10 minutes.

Sorry, didn't test this one fully.
Couldn't be bothered to test the 10 minute waiting period. xP
L1Ot4J9.png

Lua:
local config = {
    -- for teleporting players out of specified area
    check_top_left = {x = 1000, y = 1000, z = 7},
    check_bottom_right = {x = 1000, y = 1000, z = 7},
 
    -- for teleporting players into area
    teleport_position = {x = 1502, y = 1500, z = 1},
    sacrifice = 2160,
    amount = 10,
    wait_time = 1000 * 60 * 10, -- 1000 * 60 * 10 = 10 minutes
    global_storage = 45001
}

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)       npcHandler:onCreatureAppear(cid)       end
function onCreatureDisappear(cid)     npcHandler:onCreatureDisappear(cid)       end
function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg)     end

function onThink()
    npcHandler:onThink()
end

local function checkPartyDetails(cid)
    -- 0 = no party
    -- 1 = in party
    -- 2 = party leader
    -- 3 = party leader only
    local party = getPlayerParty(cid)
    if party then
        if party == cid then
            local members = getPartyMembers(party)
            if #members > 1 then
                return 2
            else
                return 3
            end
        else
            return 1
        end
    end
    return 0
end

local function teleport_party(cid, position)
    for _, pid in pairs(getPartyMembers(cid)) do
        doTeleportThing(pid, position)
    end
    return true
end

local function teleportPlayersInAreaToTemple(topLeftPosition, botRightPosition)
    for _, pid in ipairs(getPlayersOnline()) do
        local pos = getThingPosition(pid)
        if pos.z <= topLeftPosition.z and pos.z >= botRightPosition.z then
            if pos.y >= topLeftPosition.y and pos.y <= botRightPosition.y then
                if pos.x >= topLeftPosition.x and pos.x <= botRightPosition.x then
                    doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
                end
            end
        end
    end
    return true
end

function greet(cid)
    local party_check = checkPartyDetails(cid)
    if party_check == 2 then
        npcHandler:setMessage(MESSAGE_GREET, "I'm surprised you have come here to (challenge) me.")
        talkState[cid] = 0
        return true
    elseif party_check == 3 then
        npcHandler:setMessage(MESSAGE_GREET, "Your party must contain more then yourself.")
    else
        npcHandler:setMessage(MESSAGE_GREET, "You are not the leader of any party.")
    end
    talkState[cid] = 0
    addEvent (
        function ()
            npcHandler:releaseFocus(cid)
        end, 0
    )
    return true
end

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
 
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
    if checkPartyDetails(cid) ~= 2 then
        selfSay("Where has your party gone?! Come back when you've found them again.", cid)
        talkState[talkUser] = 0
        npcHandler:releaseFocus(cid)
        return true
    end
 
    if msgcontains(msg, "challenge") then
        selfSay("To challenge me, you must have a sacrifice, you have it? (10 crystal coins)", cid)
        talkState[talkUser] = 1
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        if getPlayerItemCount(cid, 2160) >= 10 then
            selfSay("Ok then. I hope you are prepared. Tell me when you are (ready).", cid)
            talkState[talkUser] = 2
        else
            selfSay("You do not have the type of sacrifice that I would like.", cid)
            talkState[talkUser] = 0 
        end
    elseif msgcontains(msg, "ready") and talkState[talkUser] == 2 then
        talkState[talkUser] = 0 
        if getPlayerItemCount(cid, 2160) >= 10 then
            local cur_time = os.time()
            if getGlobalStorageValue(config.global_storage) > cur_time then
                selfSay("Another party has already challenged me. Try again in " .. config.wait_time / 60000 .. " minutes.", cid)
                npcHandler:releaseFocus(cid)
                return true
            end
            doPlayerRemoveItem(cid, config.sacrifice, config.amount)
            selfSay("So be it!", cid)
            setGlobalStorageValue(config.global_storage, cur_time + config.wait_time / 1000)
            teleport_party(cid, config.teleport_position)
            addEvent(teleportPlayersInAreaToTemple, config.wait_time - 100, config.check_top_left, config.check_bottom_right)
            npcHandler:releaseFocus(cid)
            return true
        else
            selfSay("Where did your sacrifice go? Ask to (challenge) me again when you've got the sacrifice on you!", cid)
        end     
    end
 
    return true 
end


npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
0.3.6 have a party share experience but i would like to have it working like

when 4 different voc - 20% more experience
other than that ^ - 10% more experience

can you help with that?
 
0.3.6 have a party share experience but i would like to have it working like

when 4 different voc - 20% more experience
other than that ^ - 10% more experience

can you help with that?
There's no function to check if shared experience in enabled, and there's no creature event that checks when you gain experience.
There's only two ways I can think of to modify experience gained.. but since there's no way to determine when shared experience in enabled.. these options would not work as intended.

If someone does know of such a function, I'd love to know about it though.
 
You can edit it in the source...

party.cpp

Code:
void Party::shareExperience(double experience, bool fromMonster, bool multiplied)
{
    double shareExperience = (experience / (double)(memberList.size() + 1));
    if(experience > (double)g_config.getNumber(ConfigManager::EXTRA_PARTY_LIMIT))
        shareExperience += (experience * (double)(g_config.getNumber(ConfigManager::EXTRA_PARTY_PERCENT) / 100));
    double tmpExperience = shareExperience;
    leader->onGainSharedExperience(tmpExperience, fromMonster, multiplied);
    for(PlayerVector::iterator it = memberList.begin(); it != memberList.end(); ++it)
    {
        tmpExperience = shareExperience;
        (*it)->onGainSharedExperience(tmpExperience, fromMonster, multiplied);
    }
}

Oh sorry. I completely forgot about the second part of your request.
That's fairly easy to do.. but I'd suggest against removing the npc.
Just setup a global_storage so nobody can talk to the npc, for 10 minutes.

Sorry, didn't test this one fully.
Couldn't be bothered to test the 10 minute waiting period. xP
L1Ot4J9.png

Lua:
local config = {
    -- for teleporting players out of specified area
    check_top_left = {x = 1000, y = 1000, z = 7},
    check_bottom_right = {x = 1000, y = 1000, z = 7},
 
    -- for teleporting players into area
    teleport_position = {x = 1502, y = 1500, z = 1},
    sacrifice = 2160,
    amount = 10,
    wait_time = 1000 * 60 * 10, -- 1000 * 60 * 10 = 10 minutes
    global_storage = 45001
}

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)       npcHandler:onCreatureAppear(cid)       end
function onCreatureDisappear(cid)     npcHandler:onCreatureDisappear(cid)       end
function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg)     end

function onThink()
    npcHandler:onThink()
end

local function checkPartyDetails(cid)
    -- 0 = no party
    -- 1 = in party
    -- 2 = party leader
    -- 3 = party leader only
    local party = getPlayerParty(cid)
    if party then
        if party == cid then
            local members = getPartyMembers(party)
            if #members > 1 then
                return 2
            else
                return 3
            end
        else
            return 1
        end
    end
    return 0
end

local function teleport_party(cid, position)
    for _, pid in pairs(getPartyMembers(cid)) do
        doTeleportThing(pid, position)
    end
    return true
end

local function teleportPlayersInAreaToTemple(topLeftPosition, botRightPosition)
    for _, pid in ipairs(getPlayersOnline()) do
        local pos = getThingPosition(pid)
        if pos.z <= topLeftPosition.z and pos.z >= botRightPosition.z then
            if pos.y >= topLeftPosition.y and pos.y <= botRightPosition.y then
                if pos.x >= topLeftPosition.x and pos.x <= botRightPosition.x then
                    doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
                end
            end
        end
    end
    return true
end

function greet(cid)
    local party_check = checkPartyDetails(cid)
    if party_check == 2 then
        npcHandler:setMessage(MESSAGE_GREET, "I'm surprised you have come here to (challenge) me.")
        talkState[cid] = 0
        return true
    elseif party_check == 3 then
        npcHandler:setMessage(MESSAGE_GREET, "Your party must contain more then yourself.")
    else
        npcHandler:setMessage(MESSAGE_GREET, "You are not the leader of any party.")
    end
    talkState[cid] = 0
    addEvent (
        function ()
            npcHandler:releaseFocus(cid)
        end, 0
    )
    return true
end

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
 
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
    if checkPartyDetails(cid) ~= 2 then
        selfSay("Where has your party gone?! Come back when you've found them again.", cid)
        talkState[talkUser] = 0
        npcHandler:releaseFocus(cid)
        return true
    end
 
    if msgcontains(msg, "challenge") then
        selfSay("To challenge me, you must have a sacrifice, you have it? (10 crystal coins)", cid)
        talkState[talkUser] = 1
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        if getPlayerItemCount(cid, 2160) >= 10 then
            selfSay("Ok then. I hope you are prepared. Tell me when you are (ready).", cid)
            talkState[talkUser] = 2
        else
            selfSay("You do not have the type of sacrifice that I would like.", cid)
            talkState[talkUser] = 0
        end
    elseif msgcontains(msg, "ready") and talkState[talkUser] == 2 then
        talkState[talkUser] = 0
        if getPlayerItemCount(cid, 2160) >= 10 then
            local cur_time = os.time()
            if getGlobalStorageValue(config.global_storage) > cur_time then
                selfSay("Another party has already challenged me. Try again in " .. config.wait_time / 60000 .. " minutes.", cid)
                npcHandler:releaseFocus(cid)
                return true
            end
            doPlayerRemoveItem(cid, config.sacrifice, config.amount)
            selfSay("So be it!", cid)
            setGlobalStorageValue(config.global_storage, cur_time + config.wait_time / 1000)
            teleport_party(cid, config.teleport_position)
            addEvent(teleportPlayersInAreaToTemple, config.wait_time - 100, config.check_top_left, config.check_bottom_right)
            npcHandler:releaseFocus(cid)
            return true
        else
            selfSay("Where did your sacrifice go? Ask to (challenge) me again when you've got the sacrifice on you!", cid)
        end  
    end
 
    return true
end


npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

There is not need to set a global storage for something like this. Just do something like this:
Lua:
local cooldown = {}
cooldown[1] = 1
addEvent(removeCooldown, 1000)

function removeCooldown()
cooldown[1] = nil
end

That way the database wont be accessed everytime someone tries to talk to the npc.

Lua:
local config = {
    -- for teleporting players out of specified area
    check_top_left = {x = 1000, y = 1000, z = 7},
    check_bottom_right = {x = 1000, y = 1000, z = 7},
    -- for teleporting players into area
    teleport_position = {x = 1502, y = 1500, z = 1},
    sacrifice = 2160,
    amount = 10,
    wait_time = 1000 * 60 * 10, -- 1000 * 60 * 10 = 10 minutes
}
cooldown = {}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid)       npcHandler:onCreatureAppear(cid)       end
function onCreatureDisappear(cid)     npcHandler:onCreatureDisappear(cid)       end
function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg)     end
function onThink()
    npcHandler:onThink()
end
local function checkPartyDetails(cid)
    -- 0 = no party
    -- 1 = in party
    -- 2 = party leader
    -- 3 = party leader only
    local party = getPlayerParty(cid)
    if party then
        if party == cid then
            local members = getPartyMembers(party)
            if #members > 1 then
                return 2
            else
                return 3
            end
        else
            return 1
        end
    end
    return 0
end
local function teleport_party(cid, position)
    for _, pid in pairs(getPartyMembers(cid)) do
        doTeleportThing(pid, position)
    end
    return true
end
local function teleportPlayersInAreaToTemple(topLeftPosition, botRightPosition)
    for _, pid in ipairs(getPlayersOnline()) do
        local pos = getThingPosition(pid)
        if pos.z <= topLeftPosition.z and pos.z >= botRightPosition.z then
            if pos.y >= topLeftPosition.y and pos.y <= botRightPosition.y then
                if pos.x >= topLeftPosition.x and pos.x <= botRightPosition.x then
                    doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
                end
            end
        end
    end
    return true
end
function greet(cid)
    local party_check = checkPartyDetails(cid)
    if party_check == 2 then
        npcHandler:setMessage(MESSAGE_GREET, "I'm surprised you have come here to (challenge) me.")
        talkState[cid] = 0
        return true
    elseif party_check == 3 then
        npcHandler:setMessage(MESSAGE_GREET, "Your party must contain more then yourself.")
    else
        npcHandler:setMessage(MESSAGE_GREET, "You are not the leader of any party.")
    end
    talkState[cid] = 0
    addEvent (
        function ()
            npcHandler:releaseFocus(cid)
        end, 0
    )
    return true
end
function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if checkPartyDetails(cid) ~= 2 then
        selfSay("Where has your party gone?! Come back when you've found them again.", cid)
        talkState[talkUser] = 0
        npcHandler:releaseFocus(cid)
        return true
    end
    if msgcontains(msg, "challenge") then
        selfSay("To challenge me, you must have a sacrifice, you have it? (10 crystal coins)", cid)
        talkState[talkUser] = 1
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        if getPlayerItemCount(cid, 2160) >= 10 then
            selfSay("Ok then. I hope you are prepared. Tell me when you are (ready).", cid)
            talkState[talkUser] = 2
        else
            selfSay("You do not have the type of sacrifice that I would like.", cid)
            talkState[talkUser] = 0
        end
    elseif msgcontains(msg, "ready") and talkState[talkUser] == 2 then
        talkState[talkUser] = 0
        if getPlayerItemCount(cid, 2160) >= 10 then
            local cur_time = os.time()
            if cooldown[1] ~= nil then
                selfSay("Another party has already challenged me. Try again in " .. config.wait_time / 60000 .. " minutes.", cid)
                npcHandler:releaseFocus(cid)
                return true
            end
            doPlayerRemoveItem(cid, config.sacrifice, config.amount)
            selfSay("So be it!", cid)
            cooldown[1] = 1
            teleport_party(cid, config.teleport_position)
            addEvent(teleportPlayersInAreaToTemple, config.wait_time - 100, config.check_top_left, config.check_bottom_right)
            npcHandler:releaseFocus(cid)
            addEvent(removeCooldown, config.wait_time)
            return true
        else
            selfSay("Where did your sacrifice go? Ask to (challenge) me again when you've got the sacrifice on you!", cid)
        end  
    end
    return true
end
function removeCooldown()
    cooldown[1] = nil
end
npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited by a moderator:
Idk why, but your posts always get under my skin ._.
Maybe it's the way you always seem to sound condescending when you post, idk.
You can edit it in the source...

party.cpp

Code:
void Party::shareExperience(double experience, bool fromMonster, bool multiplied)
{
    double shareExperience = (experience / (double)(memberList.size() + 1));
    if(experience > (double)g_config.getNumber(ConfigManager::EXTRA_PARTY_LIMIT))
        shareExperience += (experience * (double)(g_config.getNumber(ConfigManager::EXTRA_PARTY_PERCENT) / 100));
    double tmpExperience = shareExperience;
    leader->onGainSharedExperience(tmpExperience, fromMonster, multiplied);
    for(PlayerVector::iterator it = memberList.begin(); it != memberList.end(); ++it)
    {
        tmpExperience = shareExperience;
        (*it)->onGainSharedExperience(tmpExperience, fromMonster, multiplied);
    }
}
The very first post in this thread that has had the general rules outlining what I can and cannot do.
I update it from time to time, but the rules have been the same since the thread began.
But yes, you can technically get everything done via source editing. Good job.
For clarity's sake,
I will script actionscripts, creaturescripts, globalevents, talkactions, movements, npcs for you.
I will not script spells, weapons, raids or monster scripts.
Additionally, source editing, websites and database queries are a no go as well.
There is not need to set a global storage for something like this. Just do something like this:
Lua:
local cooldown = {}
cooldown[1] = 1
addEvent(removeCooldown, 1000)

function removeCooldown()
cooldown[1] = nil
end

That way the database wont be accessed everytime someone tries to talk to the npc.

Lua:
local config = {
    -- for teleporting players out of specified area
    check_top_left = {x = 1000, y = 1000, z = 7},
    check_bottom_right = {x = 1000, y = 1000, z = 7},
    -- for teleporting players into area
    teleport_position = {x = 1502, y = 1500, z = 1},
    sacrifice = 2160,
    amount = 10,
    wait_time = 1000 * 60 * 10, -- 1000 * 60 * 10 = 10 minutes
}
cooldown = {}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid)       npcHandler:onCreatureAppear(cid)       end
function onCreatureDisappear(cid)     npcHandler:onCreatureDisappear(cid)       end
function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg)     end
function onThink()
    npcHandler:onThink()
end
local function checkPartyDetails(cid)
    -- 0 = no party
    -- 1 = in party
    -- 2 = party leader
    -- 3 = party leader only
    local party = getPlayerParty(cid)
    if party then
        if party == cid then
            local members = getPartyMembers(party)
            if #members > 1 then
                return 2
            else
                return 3
            end
        else
            return 1
        end
    end
    return 0
end
local function teleport_party(cid, position)
    for _, pid in pairs(getPartyMembers(cid)) do
        doTeleportThing(pid, position)
    end
    return true
end
local function teleportPlayersInAreaToTemple(topLeftPosition, botRightPosition)
    for _, pid in ipairs(getPlayersOnline()) do
        local pos = getThingPosition(pid)
        if pos.z <= topLeftPosition.z and pos.z >= botRightPosition.z then
            if pos.y >= topLeftPosition.y and pos.y <= botRightPosition.y then
                if pos.x >= topLeftPosition.x and pos.x <= botRightPosition.x then
                    doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
                end
            end
        end
    end
    return true
end
function greet(cid)
    local party_check = checkPartyDetails(cid)
    if party_check == 2 then
        npcHandler:setMessage(MESSAGE_GREET, "I'm surprised you have come here to (challenge) me.")
        talkState[cid] = 0
        return true
    elseif party_check == 3 then
        npcHandler:setMessage(MESSAGE_GREET, "Your party must contain more then yourself.")
    else
        npcHandler:setMessage(MESSAGE_GREET, "You are not the leader of any party.")
    end
    talkState[cid] = 0
    addEvent (
        function ()
            npcHandler:releaseFocus(cid)
        end, 0
    )
    return true
end
function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if checkPartyDetails(cid) ~= 2 then
        selfSay("Where has your party gone?! Come back when you've found them again.", cid)
        talkState[talkUser] = 0
        npcHandler:releaseFocus(cid)
        return true
    end
    if msgcontains(msg, "challenge") then
        selfSay("To challenge me, you must have a sacrifice, you have it? (10 crystal coins)", cid)
        talkState[talkUser] = 1
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        if getPlayerItemCount(cid, 2160) >= 10 then
            selfSay("Ok then. I hope you are prepared. Tell me when you are (ready).", cid)
            talkState[talkUser] = 2
        else
            selfSay("You do not have the type of sacrifice that I would like.", cid)
            talkState[talkUser] = 0
        end
    elseif msgcontains(msg, "ready") and talkState[talkUser] == 2 then
        talkState[talkUser] = 0
        if getPlayerItemCount(cid, 2160) >= 10 then
            local cur_time = os.time()
            if cooldown[1] ~= nil then
                selfSay("Another party has already challenged me. Try again in " .. config.wait_time / 60000 .. " minutes.", cid)
                npcHandler:releaseFocus(cid)
                return true
            end
            doPlayerRemoveItem(cid, config.sacrifice, config.amount)
            selfSay("So be it!", cid)
            cooldown[1] = 1
            teleport_party(cid, config.teleport_position)
            addEvent(teleportPlayersInAreaToTemple, config.wait_time - 100, config.check_top_left, config.check_bottom_right)
            npcHandler:releaseFocus(cid)
            addEvent(removeCooldown, config.wait_time)
            return true
        else
            selfSay("Where did your sacrifice go? Ask to (challenge) me again when you've got the sacrifice on you!", cid)
        end 
    end
    return true
end
function removeCooldown()
    cooldown[1] = nil
end
npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
If your going to be picky about how something is scripted, an array isn't required, and you didn't remove other unnecessary things such as 'local cur_time'.

I write these scripts so people who don't know how to script, can use and adjust them, and re-use the functions in other scripts.
Sure, I could not use global storages, but people understand them and don't need them explained.

In either case, thanks for the bump.
 
ahh ye it is source editing, thought u do it as well sorry mate

so I imagined something for ya :) how about team battle event like this:
Everyday at 19:30 there is information about starting event in 30 min and inform every 5 min about that:
"Team Battle Event starting in .... Write !join in order to take parcitipation in the event."
If someone write !join it counts everyone and create 2 (balanced as possible) teams and TP them to x and y places at the map where is pvp mode and nobody loose runes and items/lvl/skills while dying there.

Team A - everyone died
Team B - there are left few people
1:0 for team A and once again tp to x y places and start event in 5 min (for example) until team A or team B score 3 points

Everyone has 3 "lives" there, while 3rd dead - TP him to his normal town in "normal game" and he has everything the same as before the event.


THANK YOU !
 
Last edited:
ahh ye it is source editing, thought u do it as well sorry mate

so I imagined something for ya :) how about team battle event like this:
Everyday at 19:30 there is information about starting event in 30 min and inform every 5 min about that:
"Team Battle Event starting in .... Write !join in order to take parcitipation in the event."
If someone write !join it counts everyone and create 2 (balanced as possible) teams and TP them to x and y places at the map where is pvp mode and nobody loose runes and items/lvl/skills while dying there.

Team A - everyone died
Team B - there are left few people
1:0 for team A and once again tp to x y places and start event in 5 min (for example) until team A or team B score 3 points

Everyone has 3 "lives" there, while 3rd dead - TP him to his normal town in "normal game" and he has everything the same as before the event.


THANK YOU !
"/lvl/skills while dying there." You can just put pvp zone in the area, and they'll be teleported to their temple when they reach critical health and won't lose lvl/skills/blessings.

Creating the event itself should be easy, but stopping the supplies from being wasted.. I honestly can't think of any good way to do this.

If you want the event, with players still wasting supplies, I'll write it out for you.
 
"/lvl/skills while dying there." You can just put pvp zone in the area, and they'll be teleported to their temple when they reach critical health and won't lose lvl/skills/blessings.

Creating the event itself should be easy, but stopping the supplies from being wasted.. I honestly can't think of any good way to do this.

If you want the event, with players still wasting supplies, I'll write it out for you.

Would be cool if you write even that ! :)
Its hard to think.. How to script that items are infinite while in pvp zone? Maybe someone other have any idea?
 
Idk why, but your posts always get under my skin ._.
Maybe it's the way you always seem to sound condescending when you post, idk.

The very first post in this thread that has had the general rules outlining what I can and cannot do.
I update it from time to time, but the rules have been the same since the thread began.
But yes, you can technically get everything done via source editing. Good job.


If your going to be picky about how something is scripted, an array isn't required, and you didn't remove other unnecessary things such as 'local cur_time'.

I write these scripts so people who don't know how to script, can use and adjust them, and re-use the functions in other scripts.
Sure, I could not use global storages, but people understand them and don't need them explained.

In either case, thanks for the bump.

If I sound condescending to you, then you harbor resentment on your end. That's not my issue and my goal isn't to be condescending. I am not adequate enough at coding to be condescending, however, when I see a code that can be optimized a little better, even if it is a slight tweak, I try to point it out to help developers who are new understand when things should and shouldn't be used.

Storage values should only be used when trying to save information that needs to be accessible even after the "server" or memory is shutdown/erased.

I didn't post the source code for you to edit. I didn't know if the person requesting the party exp share changes knew where he could look into adding such a feature. So I was just pointing out where it was.
 
Hi, @Xikini !
Me again. Another question, see if its possible to make this:

- The player is equipping any ammo (spear or bolts/arrow).
- When the ammunition ends and the player have the same ammo in backpacks, the ammo equips automatically to the slot.

Its possible?

Thank you again bro!
 
Status
Not open for further replies.

Similar threads

Back
Top