TalkAction Command "/attr" in lua-script talkaction, you can add more functions.

Joined
Apr 17, 2008
Messages
1,922
Best answers
0
Reaction score
181
Location
Venezuela
Since you have just read, this is the command "/attr" but in lua, you can edit, add more functions, etc..

Lua:
local itemFuncs =
{
	["attackspeed"] = setItemAttackSpeed,
	["name"] = setItemName,
	["plural"] = setItemPluralName,
	["attack"] = setItemAttack,
	["extraattack"] = setItemExtraAttack,
	["defense"] = setItemDefense,
	["armor"] = setItemArmor,
	["extradefense"] = setItemExtraDefense,
	["hitchance"] = setItemHitChance,
	["range"] = setItemShootRange,
	["actionid"] = doSetItemActionId,
	["action"] = doSetItemActionId,
	["aid"] = doSetItemActionId,
	["description"] = doSetItemSpecialDescription,
	["desc"] = doSetItemSpecialDescription,
	["protection"] = doSetItemProtection,
	["charges"] = doChangeTypeItem,
	["count"] = doChangeTypeItem
}

local creatureFuncs =
{
	["health"] = doCreatureAddHealth,
	["maxhealth"]= setCreatureMaxHealth,
	["mana"] = doCreatureAddMana,
	["maxmana"] = setCreatureMaxMana,
	["speed"] = doChangeSpeed,
	["droploot"] = doCreatureSetDropLoot,
	["cannotmove"] = doCreatureSetNoMove,
	["skull"] = doCreatureSetSkullType,
	["redskull"] = doPlayerSetRedSkullTicks
}

local playerFuncs =
{
	["fyi"] = doPlayerPopupFYI,
	["tutorial"] = doPlayerSendTutorial,
	["guildrank"] = doPlayerSetGuildRank,
	["guildnick"] = doPlayerSetGuildNick,
	["group"] = doPlayerSetGroupId,
	["vocation"] = doPlayerSetVocation,
	["promotion"] = setPlayerPromotionLevel,
	["stamina"] = doPlayerAddStamina,
	["town"] = doPlayerSetTown,
	["balance"] = doPlayerDepositMoney
}
	

function onSay(cid, words, param, channel)
	if(param == "") then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
		return TRUE
	end

	local pos = {x=getCreaturePosition(cid).x, y=getCreaturePosition(cid).y, z=getCreaturePosition(cid).z, stackpos=1}
	if getCreatureLookDirection(cid) == SOUTH then
		pos = {x=getCreaturePosition(cid).x, y=getCreaturePosition(cid).y+1, z=getCreaturePosition(cid).z, stackpos=255}
	elseif getCreatureLookDirection(cid) == NORTH then
		pos = {x=getCreaturePosition(cid).x, y=getCreaturePosition(cid).y-1, z=getCreaturePosition(cid).z, stackpos=255}
	elseif getCreatureLookDirection(cid) == EAST then
		pos = {x=getCreaturePosition(cid).x+1, y=getCreaturePosition(cid).y, z=getCreaturePosition(cid).z, stackpos=255}
	elseif getCreatureLookDirection(cid) == WEST then
		pos = {x=getCreaturePosition(cid).x-1, y=getCreaturePosition(cid).y, z=getCreaturePosition(cid).z, stackpos=255}
	end

	local t = string.explode(param, ",")
		

	local getThing = getThingFromPos(pos)

	if itemFuncs[t[1]] then
		if getThing.itemid > 0 then
			if itemFuncs[t[1]](getThing.uid, t[2]) then
				doSendMagicEffect(pos, CONST_ME_MAGIC_GREEN)
				return TRUE
			else
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you can not add attribute to this item.")
				return TRUE
			end
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Item not found.")
			return TRUE
		end
	elseif creatureFuncs[t[1]] then
		if isCreature(getThing.uid) then
			if creatureFuncs[t[1]](getThing.uid, t[2]) then
				doSendMagicEffect(pos, CONST_ME_MAGIC_GREEN)
				return TRUE
			else
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you can not add attribute to this creature.")
				return TRUE
			end
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Creature not found.")
			return TRUE
		end
	elseif playerFuncs[t[1]] then
		if isPlayer(getThing.uid) then
			if playerFuncs[t[1]](getThing.uid, t[2]) then
				doSendMagicEffect(pos, CONST_ME_MAGIC_GREEN)
				return TRUE
			else
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you can not add attribute to this player.")
				return TRUE
			end
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player not found.")
			return TRUE
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Unknow attribute.")
		return TRUE
	end
	return TRUE
end
Advantages:
  • You can edit, adding/removing functions.
  • If you write bad a function, it will not give error in the console, just "Unknow attribute."

Disadvantages
  • Some attributes cannot be added(depotid, uniqueid to an item, duration, destination, etc..)

Bugs
  • If you write more than 4 in skull, it crashes the client.
  • Same thing with other functions

Please post here the bugs.
 
Last edited:

elf

Sing, sing blue silver
Joined
Dec 11, 2007
Messages
3,665
Best answers
1
Reaction score
116
Location
Cracow, Poland
THANKS, mayebe I'll include it in 0.3.5!

Btw. You can also call 'executeTalkaction' :d
 

Slain

TrueHavoc.com
Joined
Nov 27, 2008
Messages
2,241
Best answers
0
Reaction score
29
i dont understand, so if i want to raise attack to 40 i would say /attr attack 40 because its not working
 

jerryb1988

Member
Joined
Mar 10, 2008
Messages
79
Best answers
0
Reaction score
5
Awesome. I wanted more than just the built in /attr commands in TFS and here it is =)

Edit

Rep+
 

Aids

New Member
Joined
Jun 8, 2009
Messages
21
Best answers
0
Reaction score
0
I'm Actually a bit confused, I'm not sure how to load it as a command/talkaction :/
 
Last edited:

Sync

Ø,ø
Joined
May 26, 2009
Messages
1,876
Best answers
0
Reaction score
19
Location
Canada
@up ??

Code:
/attr attackspeed,500
Anyways, Very nice script dude Nice.
 

nashein

New Member
Joined
Dec 20, 2008
Messages
24
Best answers
0
Reaction score
0
Where i must add this script ??

data\talkactions\scripts\name_script.lua
and i must add or change line with "/attr" ?
 

Evan

A splendid one to behold
Premium User
Joined
May 6, 2009
Messages
7,017
Best answers
1
Reaction score
942
Location
United States
Would be nice if it had duration change.
 

7675081

New Member
Joined
Jan 20, 2009
Messages
6
Best answers
0
Reaction score
0
i have a question... in a ot im gm but i cant do that action :S its only for gods???? D: i read : "You cannot execute this action"
 
OP
Darkhaos
Joined
Apr 17, 2008
Messages
1,922
Best answers
0
Reaction score
181
Location
Venezuela
Depend of the acces that you set in actions.xml

An example:
Lua:
	<talkaction log="yes" access="5" words="YOUR_WORDS" event="script" value="SCRIPT_NAME.lua"/>
 

AGS

DeathSouls Owner
Joined
Oct 29, 2007
Messages
400
Best answers
0
Reaction score
8
Location
Mexico
Good job!
Maybe an extra parameter, to choose a slot,and apply the attributes to that slot, for example
/attr attack,40,right

That would give 40 attack to the item on your right hand, so you don't have to throw it infront of you.

If you don't use the second param, then it affects the tile infront of you.

PS: I would rep you but I can't, need to spread some rep on other users :p
 
Top