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

Npc needed to give first weapon to knights

vonuzur

New Member
Joined
Nov 27, 2012
Messages
30
Reaction score
0
Hello everyone,

Right now I have a script that gives you a reward when you reach a certain level, although I'm not sure how to specify which weapon class a knight would get. My idea is that the character would start in a room that has an NPC in it, and a tile that they can not pass until they choose their weapon type by talking to the NPC.

So basically my request is:
I need a tile that checks for a specific storage value, teleports you away if you have it, or lets you pass if you don't.
I need an NPC that checks for this value, if you have it, the NPC will ask you which type of weapon class that you would like to use. After setting a new storage value you will then be able to pass through the tile and the NPC won't ask about weapons anymore when you speak to it.

Additionally, it would be nice if you could come back to the NPC later on and ask to switch your weapon type. (I'm thinking there would need to be a storage value for each weapon type, so you could ask the npc to change it, thus having the reward script give you a different type weapon when you level up.)

I greatly appreciate any help I receive!

Thanks,
Vonuzur
 
Hiya Stream,
I know it's not extremely difficult, but I'm having a bit of trouble figuring it out. I tried looking around and working with scripts that exist to try and incorporate my idea into it, but like I said I'm having a bit of trouble figuring it out.

I'll keep looking around but perhaps someone can help me figure this out sooner than later.
Thanks :)
 
or you could make like a jagged sword thaat when you use the sword it will transform into an axe then a club then back to a sword. this is useful and easy todo for knights first weapon, if noone else helps you to do the script u wanted.
 
Well well.. I wonder who that could be..
I helped him script roughly what he wanted. With his help, here's what we ended up with - an unnecessarily long script that actually works. Any tips on where I can shorten it would be appreciated. I'm self taught so don't be too hard on me! I also know Thais coordinates aren't right. I changed them to teleport to my location on my own server. (Stealing the fame for myself of course) :w00t:

Besides the longer keywords I made for "yes" and "no", where can I easily improve?

EDIT: Added "talkState[talkUser] = 0" on greeting to ensure players who asked for thais, then left were reset. Again, I believe there's a way to reset on player leaving or bye, but I don't know how without spending 30 minutes testing it. I'll give it a try someday when I'm ready to fully learn C and LUA (programming in general).

PHP:
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

function greetCallback(cid)
    if getPlayerStorageValue(cid, 3331) ~= 1 and getPlayerStorageValue(cid, 3332) ~= 1 and getPlayerStorageValue(cid, 3333) ~= 1  then
	talkState[talkUser] = 0
        npcHandler:setMessage(MESSAGE_GREET, "Free Weapon Message Here")
        return true
    else
	npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. Something Something {thais}. Something something something something {trade}?")
	talkState[talkUser] = 0
	return true
	end
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
        ---------------- config msg ------------------
		local intro1 = 'I can offer you a {sword}, {axe}, or {club} type weapon. Which do you want?' -- (npc) response to weapon types --
		local intro2 = 'weapon' -- (player) weapon type --
		local intro3 = 'type' -- (player) weapon type --
		local intro4 = 'weapons' -- (player) weapon type --
		local intro5 = 'types' -- (player) weapon type --
		local frase1 = 'sword'  -- (player) Player wants sword --
		local frase2 = 'axe'  -- (player) Player wants axe --
		local frase3 = 'club' -- (player) Player wants club --
		local answer1 = 'I can give you a carlin sword. Is that what you want?' -- (npc) Are you sure (sword) --
		local answer2 = 'I can give you a hatchet. Is that what you want?' -- (npc) Are you sure? (axe) --
		local answer3 = 'I can give you a mace. Is that what you want?' -- (npc) Are you sure? (club) --
		local final1 = 'yes' -- (player) yes --
		local final2 = 'no' -- (player) no --
		local final3 = 'Here is your weapon, free of charge. Have a nice day.' -- (npc) Response to yes --
		local final4 = 'No? My offer is a weapon free of charge. Just let me know what {weapon type} you want.' -- (npc) Response to no --
		local storage1 = 3331 -- Storage value for sword --
		local storage2 = 3332 -- Storage value for axe --
		local storage3 = 3333 -- Storage value for club --
		local itemid1 = 2395 -- Sword ID --
		local itemid2 = 2388 -- Axe ID --
		local itemid3 = 2398 -- Club ID --
		local sail1 = 'Do you want to travel to Thais for 100 gold?'
		local sail2 = 'You don\'t have enough money to travel!'
		local sail3 = 'You have blood on you hands. Do you still want to travel for Thais for 200 gold?.'
		local sail4 = 'Okay then.'
        ----------------------------------------------
        if (msgcontains(msg, intro2) or msgcontains(msg, intro3) or msgcontains(msg, intro4) or msgcontains(msg, intro5)) then
				selfSay(intro1, cid)
		elseif(msgcontains(msg, frase1)) and getPlayerStorageValue(cid, storage1) ~= 1 and getPlayerStorageValue(cid, storage2) ~= 1 and getPlayerStorageValue(cid, storage3) ~= 1 then
				selfSay(answer1, cid)
				talkState[talkUser] = 1
		elseif(msgcontains(msg, frase2)) and getPlayerStorageValue(cid, storage1) ~= 1 and getPlayerStorageValue(cid, storage2) ~= 1 and getPlayerStorageValue(cid, storage3) ~= 1 then
				selfSay(answer2, cid)
				talkState[talkUser] = 2
		elseif(msgcontains(msg, frase3)) and getPlayerStorageValue(cid, storage1) ~= 1 and getPlayerStorageValue(cid, storage2) ~= 1 and getPlayerStorageValue(cid, storage3) ~= 1 then
				selfSay(answer3, cid)
				talkState[talkUser] = 3
		elseif(msgcontains(msg, final1) and talkState[talkUser] == 1) then
				setPlayerStorageValue(cid, storage1, 1)
				doPlayerAddItem(cid, itemid1)
				selfSay(final3, cid)
				talkState[talkUser] = 0
		elseif(msgcontains(msg, final1) and talkState[talkUser] == 2) then
				setPlayerStorageValue(cid, storage2, 1)
				doPlayerAddItem(cid, itemid2)
				selfSay(final3, cid)
				talkState[talkUser] = 0
		elseif(msgcontains(msg, final1) and talkState[talkUser] == 3) then
				setPlayerStorageValue(cid, storage3, 1)
				doPlayerAddItem(cid, itemid3)
				selfSay(final3, cid)
				talkState[talkUser] = 0
        elseif(msgcontains(msg, final2) and talkState[talkUser] == 1) then
				selfSay(final4, cid)
                talkState[talkUser] = 0
		elseif(msgcontains(msg, final2) and talkState[talkUser] == 2) then
				selfSay(final4, cid)
                talkState[talkUser] = 0
		elseif(msgcontains(msg, final2) and talkState[talkUser] == 3) then
				selfSay(final4, cid)
                talkState[talkUser] = 0
		elseif(msgcontains(msg, 'thais')) and isPlayerPzLocked(cid) ~= 1 then
				selfSay(sail1, cid)
				talkState[talkUser] = 4
		elseif(msgcontains(msg, 'thais')) and isPlayerPzLocked(cid) then
				selfSay(sail3, cid)
				talkState[talkUser] = 5
		elseif(msgcontains(msg, final1) and talkState[talkUser] == 4) then
			if doPlayerRemoveMoney(cid, 100) == true then
				doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
				doTeleportThing(cid,{x=160, y=54, z=7})
				doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
			else
				selfSay(sail2, cid)
			end
		elseif(msgcontains(msg, final2) and talkState[talkUser] == 4) then
				selfSay(sail4, cid)
				talkState[talkUser] = 0
		elseif(msgcontains(msg, final1) and talkState[talkUser] == 5) then
			if doPlayerRemoveMoney(cid, 200) == true then
				doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
				doTeleportThing(cid,{x=160, y=54, z=7})
				doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
			end
		elseif(msgcontains(msg, final2) and talkState[talkUser] == 5) then
				selfSay(sail4, cid)
				talkState[talkUser] = 0
		end
        return TRUE
end

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

EDIT: vonuzur you don't mind if I put this script out there do you? Let me know.
 
Last edited:
Back
Top