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

Scripter Itutorial scripting service

Itutorial

Board Moderator
Staff member
Board Moderator
Joined
Dec 23, 2014
Messages
2,477
Solutions
69
Reaction score
1,136
Post any script you need any TFS distro, however, I will not do any distros under 0.3.6.

I will NOT do source edits.
 
TFS 1.2
You don't have much information what can you do or any conditions what for you do so i just go with this:

My next system after skilltree is: npc system 4.0 (don't dwell too much on that name xD)

What should it be able to do:
When player chooses npc as an attack target, it will pop up a modal window.
On this modal window attach a config table.
first choices should be first keys of the table.
if conversation continues on the first choice it will replace the the key with keys inside the table it had under the first key.
the conversation length is dynamical.
also at the end of or start of the choices, player is somehow notified is the choice something new for him.
Each table has its own checks it has to pass.
Checks:
1. storage value(s) must be met
2. player has to have these item(s) as equipment or in bag.

Example table:
Code:
npcSystem4 = {
["Who are you?"] = {
    d_answer = "I am xxxx, etc" 
},
["what is this place?"] = {
     d_answer = "....text...",
    ["What happened here?"] = {
         d_answer = "...text..."
    }
},
["can i help you with something?"] = {
    m_any_storage_s = {{storage, value},}, --default value is -1 if nil
    answer = "  ....text...."
},
["where can i find what you looking for?"] = {
    m_any_storage_s = {{storage, value},{storage, value},},
    answer = "..text..."
}
-- well good enuf for example i guess
}
m_any_storage_s = match any storage success, this means if one of these storage values matches with player, this choice will be added to modal window.
m_any_storage_f = match any storage fail, this means if one of these storage values matches with player, this choice will be not added to modal window.
fails, will be always checked first.

If you can do that it would save me a day if not 2.
 
So pretty much you want the npcs to be used through modal windows?
 
Yeah, but its pretty simple to make... Just going to be time consuming. Because he has to make all the of modal windows inside creaturescripts.
I would suggest naming the files after the npcs.

The best I can do is make a function for you to use... Other then that you will have to take the time to make them.

Code:
--Name: can be anything
--id: start with 0xFF then each modal window in the script add an F so: 0xFFF, 0xFFFF
--title: title --param
--msg: What you want the NPC to say. --param
--cid: Ignore
--choice: Option to say to NPC. --param
--button: Enter button --param
--button2: Exit button --param
--storageKey = storage number to check
--storage: Optional: modal window will only popup if player has the storage value == storage
--choice2-5: Optional, you do not have to enter these unless you want more choices --params

function npcModalWindow(cid, name, id, title, msg, choice, button, button2, storageKey, storage, choice2, choice3, choice4, choice5)
local name = ModalWindow(id, title, msg)
name:addChoice(0x00, choice)
if choice2 then
name:addChoice(0x01, choice2)
end
if choice3 then
name:addChoice(0x02, choice3)
end
if choice4 then
name:addChoice(0x03, choice3)
end
if choice5 then
name:addChoice(0x04, choice4)
end
name:addButton(0x01, button)
name:addButton(0x02, button2)

if storageKey then
    if storage then
        if getPlayerStorageValue(cid, storageKey) == storage then
            name:sendToPlayer(cid)
        end
    end
else
    name:sendToPlayer(cid)
end
end
 
Last edited by a moderator:
The best I can do is make a function for you to use... Other then that you will have to take the time to make them.

Code:
--Name: can be anything
--id: start with 0xFF then each modal window in the script add an F so: 0xFFF, 0xFFFF
--title: title --param
--msg: What you want the NPC to say. --param
--cid: Ignore
--choice: Option to say to NPC. --param
--button: Enter button --param
--button2: Exit button --param
--storageKey = storage number to check
--storage: Optional: modal window will only popup if player has the storage value == storage
--choice2-5: Optional, you do not have to enter these unless you want more choices --params

function npcModalWindow(cid, name, id, title, msg, choice, button, button2, storageKey, storage, choice2, choice3, choice4, choice5)
local name = ModalWindow(id, title, msg)
name:addChoice(0x00, choice)
if choice2 then
name:addChoice(0x01, choice2)
end
if choice3 then
name:addChoice(0x02, choice3)
end
if choice4 then
name:addChoice(0x03, choice3)
end
if choice5 then
name:addChoice(0x04, choice4)
end
name:addButton(0x01, button)
name:addButton(0x02, button2)

if storageKey then
    if storage then
        if getPlayerStorageValue(cid, storageKey) == storage then
            name:sendToPlayer(cid)
        end
    end
else
    name:sendToPlayer(cid)
end
end
thats what I ment.
Make a all the functions work smoothly with config table.
Each uppertable represent a individual NPC.
So in the npc callback I could write this: table[npc:getName()] and automatically generates the correct conversations.

Yeah it is somewhat easy, but it is time consuming none the less, I just created skillTree system with modalwindows. took me entire day to get it working and then 1 more day to perfect it.

But keep the table config clean. I dont want to start placing unqiue ID;s there or whatever, these should be generated automatically on server startup.

I like where you going though, I didnt think of making better function for modalWindows, i used the basic one xD Made it much more trickier to generate correct information with just modalWindow, button id choice id.

Because he has to make all the of modal windows inside creaturescripts.
No, i just fill out the table, and the new modal window is automatically generated.
 
Isnt better to use player:getStorageValue than getPlayerStorageValue(cid) I know its in compat, but reduces some ticks :P
 
Isnt better to use player:getStorageValue than getPlayerStorageValue(cid) I know its in compat, but reduces some ticks :p
I don't think it really matters, although I dont even have the second function xD (i deleted all the useless TFS compat functions aka entire compat.lua file (and lib folders))
 
I don't think it really matters, although I dont even have the second function xD (i deleted all the useless TFS compat functions aka entire compat.lua file (and lib folders))
Doesnt matter at all, but always better to use real functions. Thats just an "interface", and maybe at some point u wont have that compat lib (just as you do now :) )
 
Alright, you could do something like this...


NPC_modals


The npcModals.lua put inside your server file just right in front with the executable.

Then im sure you will figure it out from there.
 
Alright, you could do something like this...


NPC_modals


The npcModals.lua put inside your server file just right in front with the executable.

Then im sure you will figure it out from there.
well you missed the point or i just suck at explaining what I want xD
because this is not dynamical enough.
I guess i just make the system my own.
 
Its true I kinda get the idea but not really...Its just at the level were u cant get it....

I think he is saying:

1) scipt checks players storage's
2) Puts new choices in the modal window depending on the storages it calls
--So if player has storage 40100 == 1 then it adds a new choice
--if player has storage 40101 == 1 then it adds another choice

The only problem is I can't just make a general script like that.... How do I go about it?

if choice1 then
if enter then
another window? or a script

I am just not sure. I am going to deem this script impossible as requested.
 
Last edited by a moderator:
I think he is saying:

1) scipt checks players storage's
2) Puts new choices in the modal window depending on the storages it calls
--So if player has storage 40100 == 1 then it adds a new choice
--if player has storage 40101 == 1 then it adds another choice
Exactly!
impossible as requested
xD not really. that's why I said it takes day if not 2. it requires lot of code writing.
 
Exactly!

xD not really. that's why I said it takes day if not 2. it requires lot of code writing.
guess you better get started then :p
I also have no idea what you're asking for. I made a system for trading with an npc in a modalwindow, allowing limited money and items for each individual npc, but I never bothered making a communication system in the modalwindows because the interface just isn't all that friendly.
 
In NPC file just do:
Code:
local config = {
[41000] = {choiceid = 0x00, text = "text to send"},
[41001] = {choiceid = 0x01, text = "text to send"}
}

local window = ModalWindow(0xFF, "NPC", "msg")

for i = 1, #config do
if getPlayerStorageValue(cid, config[i]) == 1 then
window:addChoice(config[i].choiceid, config[i].text)
end

Easiest way to implement new choices by storage.
 
Last edited:
guess you better get started then :p
I also have no idea what you're asking for. I made a system for trading with an npc in a modalwindow, allowing limited money and items for each individual npc, but I never bothered making a communication system in the modalwindows because the interface just isn't all that friendly.
well the npc update wont come that soon. I got some more important things to do before.
But when I release patch 0.1.4.1 then the skillTree system with modal windows I'm using is very similar to what I plan for npc communication.

In NPC file just do:
Code:
local config = {
[41000] = {choiceid = 0x00, text = "text to send"},
[41001] = {choiceid = 0x01, text = "text to send"}
}

local window = ModalWindow(0xFF, "NPC", "msg")

for i = 1, #config do
if getPlayerStorageValue(cid, config[i]) == 1 then
window:addChoice(config[i].choiceid, config[i].text
end

Easiest way to implement new choices by storage.
i dont like the choiceid in the table itself, i want them generated automatically.
i already showed you what should table look like xD
when script is ready then updating the table should, be so easy that even nonscripter can understand it.
In your case, there is like 3 difference tables what should be filled and some ID's what might as well not be there because they follow a pattern.

EDIT: AH crap, doublepost xD
 
Last edited by a moderator:
In NPC file just do:
Code:
local config = {
[41000] = {choiceid = 0x00, text = "text to send"},
[41001] = {choiceid = 0x01, text = "text to send"}
}

local window = ModalWindow(0xFF, "NPC", "msg")

for i = 1, #config do
if getPlayerStorageValue(cid, config[i]) == 1 then
window:addChoice(config[i].choiceid, config[i].text)
end

Easiest way to implement new choices by storage.
in libs.lua / global.lua
Code:
function num2hex(num)
  local hexstr = '0123456789abcdef'
  local s = ''
  while num > 0 do
    local mod = math.fmod(num, 16)
    s = string.sub(hexstr, mod+1, mod+1) .. s
    num = math.floor(num / 16)
  end
  if s == '' then s = '0' end
  return
end
Then you can do:
Code:
local config = {
[41000] = "text to send",
[41001] = "text to send"
}

local window = ModalWindow(0xFF, "NPC", "msg")

for i, text in pairs(config) do
if getPlayerStorageValue(cid, config[i]) == 1 then
window:addChoice(i-41000, text)
end

Dunno if the HEX returned in num2hex is well formated for this, but easy change
 
Skill point system (like zbizus') where you are able to reset the points. (remove skills chosen)
Using conditions. ;)
 
Back
Top