What's new

[8.60+] NPC Miles - Crafting system

Status
Not open for further replies.

Skibi184

Active User
Joined
Jan 16, 2014
Messages
96
Reaction score
1
NPC Miles daje mo?liwo?? tworzenia sobie item?w potrzebnych do eq, po przez co? w stylu task. Czyli wybierasz np. Demon armor, po czym NPC daje ci taki dialog - "You don't have all you need to craft Demon Armor. You need 100 x Red Pieces of Cloth which can be looted from Hero and 50 x Demon Dust which can be looted from Demon. The cost of crafting is 1 cystal coin." Gdy ju? zbierzesz potrzebne itemy podchodzisz zn?w do NPC i piszesz zn?w nazwe tego itemu, po czym NPC zabiera ci itemy kt?re zebra?e? i daje ci item kt?ry chcesz kt?ry w tym przypadku jest Demon Armor.

Dodawanie item?w jest bardzo proste, dodajesz do tablicy:
Code:
[[COLOR="#800000"]3888[/COLOR]] = { Name = "[COLOR="#8B4513"]Demon Armor[/COLOR]", Item = [COLOR="#800000"]3888[/COLOR], ItemToBring = "[COLOR="#2F4F4F"]Red Piece of Cloth[/COLOR]", AmountToBring = [COLOR="#008080"]100[/COLOR], LootedIn = "[COLOR="#000080"]Hero[/COLOR]", ItemToBring2 = "[COLOR="#4B0082"]Demon Dust[/COLOR]", AmountToBring2 = [COLOR="#696969"]50[/COLOR], LootedIn2 = "[COLOR="#B22222"]Demon[/COLOR]", Cost = [COLOR="#A52A2A"]1[/COLOR] }

Code:
[COLOR="#800000"]Item ID[/COLOR]
[COLOR="#8B4513"]Nazwa itemu[/COLOR]

[COLOR="#2F4F4F"]Jaki item trzeba przynie??[/COLOR]
[COLOR="#008080"]Ile trzeba przynie??[/COLOR]
[COLOR="#000080"]Sk?d wzi???[/COLOR]

[COLOR="#4B0082"]Jaki drugi item trzeba przynie??[/COLOR]
[COLOR="#696969"]Ile trzeba przynie??[/COLOR]
[COLOR="#B22222"]Sk?d wzi???[/COLOR]

[COLOR="#A52A2A"]Cena w CC[/COLOR]

Nie mam jak przetestowa? skrypt wi?c nie mam poj?cia czy dzia?a. Je?li co? jest nie tak to prosz? tu pisa?, spr?buje pom?c.

Autorem skryptu jestem ja, zabraniam wstawiania na inne fora bez mojej zgody.

Stw?rz plik xml o nazwie Miles
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Miles" script="Miles.lua">
    <health now="100" max="100"/>
    <look type="289" head="115" body="131" legs="106" feet="131" addons="2"/>
</npc>

A p??niej lua o nazwie Miles
Code:
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 Possible {
	[3888] = { Name = "Demon Armor", Item = 3888, ItemToBring = "Red Piece of Cloth", AmountToBring = 100, LootedIn = "Hero", ItemToBring2 = "Demon Dust", AmountToBring2 = 50, LootedIn2 = "Demon", Cost = 1 }
}

local Craft = Possible[itemid]

NpcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|, name the item that you would like me to craft for you.")

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(msgcontains(msg, Craft.Name)) then
		talkState[talkUser] = 1 
		npcHandler:say("Are you sure you would like to craft " ...Craft.Name... "?", cid)
	elseif(msgcontains(msg, "yes")) then
		if(talkState[talkUser] == 1) then
			if(doPlayerRemoveItem(cid, Craft.ItemToBring, Craft.AmountToBring) and doPlayerRemoveItem(cid, Craft.ItemToBring2, Craft.AmountToBring2) and doPlayerRemoveItem(cid, 3043, 1)) then 
				npcHandler:say("Oh great! You brought all of the items needed to craft " ...Craft.Name... "!", cid)
				npcHandler:say("Here is your " ...Craft.Name... ".", cid)
				doPlayerAddItem(cid, Craft.Item, 1)
			else 
				npcHandler:say("You don't have all you need to craft " ...Craft.Name... ". You need " ...Craft.AmountToBring... "x" ...Craft.ItemToBring... "which can be looted from" ...Craft.LootedIn... "and " ...Craft.AmountToBring2... "x" ...Craft.ItemToBring2... "which can be looted from" ...Craft.LootedIn2... ". The cost of crafting is 1 crystal coin.", cid)
			end
			talkState[talkUser] = 0  
			end
		end
	elseif(msgcontains(msg, "bye")) then
		npcHandler:say("Goodbye |PLAYERNAME|!", cid)
	else npcHandler:say("How rude...", cid)
	return true
end

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

Dantez

Moim sekretem jest ciasto
Joined
May 22, 2008
Messages
1,206
Reaction score
202
Odp: [8.60+] NPC Miles - Crafting system

local Craft = Possible[itemid]
> nil, itemid nie jest nigdzie zadeklarowane

if(msgcontains(msg, Craft.Name)) then
> always false, zwi?zane z poprzednim

npcHandler:say("Are you sure you would like to craft " ...Craft.Name... "?", cid)
> Jakie? nowe ??czenie string?w?

doPlayerRemoveItem(cid, 3043, 1)
> A to co za item?

npcHandler:say("Oh great! You brought all of the items needed to craft " ...Craft.Name... "!", cid)
npcHandler:say("Here is your " ...Craft.Name... ".", cid)
> Znowu ??czenie string?w

doPlayerAddItem(cid, Craft.Item, 1
> attempt to index local 'Craft' (a nil value)

I dalej kilka takich samych b??d?w, nie musia?em nawet tego testowa?.

Kilka rad:
1) Napisz porz?dn? tablic?, gdzie wymagane przedmioty to r?wnie? tablica w postaci: {{itemid, count}, {itemid, cout}}
2) Popraw b??dy z ??czeniem string?w, s? to "..", nie "..."
3) Zmienn? "Craft" b?dziesz m?g? dopiero zdefiniowa? po tym, jak gracz wypowie nazw? przedmiotu
4) Daruj sobie "which can be looted" i popraw stringi, ?eby si? nie styka?y (which can be looted fromNazwa)
 

danio4don

Advanced User
Joined
Oct 6, 2011
Messages
233
Reaction score
6
Age
28
Odp: [8.60+] NPC Miles - Crafting system

poprawy nie b?dzie ?
 

Sh4dy

Advanced User
Joined
Dec 8, 2011
Messages
176
Reaction score
10
Odp: [8.60+] NPC Miles - Crafting system

Taki NPC moim zdaniem nie potrzebny.
 
Status
Not open for further replies.
Top