• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[Solved] Need help fixing /i for TFS 0.3.6

RazorBlade

Retired Snek
Joined
Nov 7, 2009
Messages
2,015
Solutions
3
Reaction score
629
Location
Canada
Since nowadays, commands are talkactions, they're editable. In the latest TFS, the /i command automatically makes 100 of an item, or 100 charges on the item. Part of the script shows
Code:
	local amount = 100
	if(t[2]) then
		amount = t[2]
	end
So to change the amount, it just needs to be changed here. However, if you make an item that has charges, you still have to do, for example, /i stone skin amulet, 5 in order to give it 5 charges. There's no function to find the charges of an item, which is ridiculous. Is there any way to make it so if I do /i stone skin amulet or /i for anything else that has charges, it'll give it the correct number of charges automatically? I just need a function to check charges and I can do the rest... Any ideas? ::confused:
 
Last edited:
damn, sorry, didnt read whole this post, I answered basing on the one in main topic

I'm not sure how, but it is possible to get that number somehow(monster drops are correct)
I don't know sources good enough to find it, but I can try
 
luascript.cpp
Code:
	//getCharges(itemid)
	lua_register(m_luaState, "getCharges", LuaScriptInterface::luaGetCharges);
and
Code:
int32_t LuaScriptInterface::luaGetCharges(lua_State* L)
{
	//getCharges(itemid)
	lua_pushnumber(L, Item::items[popNumber(L)].charges);
	return 1;
}

luascript.h
Code:
		static int32_t luaGetCharges(lua_State* L);
 
Last edited:
luascript.cpp
Code:
	//getCharges(itemid)
	lua_register(m_luaState, "getCharges", LuaScriptInterface::luaGetCharges);
and
Code:
int32_t LuaScriptInterface::luaGetCharges(lua_State* L)
{
	//getCharges(itemid)
	lua_pushnumber(L, items[popNumber(L)].charges);
	return 1;
}

luascript.h
Code:
		static int32_t luaGetCharges(lua_State* L);

I was hoping for something that doesn't require me to do any compiling since I don't really know how. Isn't there anything already in the server? Cause you'd think a getCharges function would be normal... There's getItemName, getItemAttack, getItemFreakingEverything and yet not charges... D:
 
>>690976
  1. Find your distribution here
  2. Download the entire folder (Download GNU Tarball) and extract the archive somewhere
  3. Get this
  4. Open ./dev-cpp/TheForgottenServer.dev (from your extracted files) in DevCpp and do what I said in >>690401
  5. Hit Execute->Compile (Ctrl+F9)
  6. Now copy ./dev-cpp/TheForgottenServer.exe to your otserver folder and use it to run TFS
 
Why do you want to edit sources if you mustn't?
data/talkactions/scripts/createitem.lua
(look at lines 25-28 :P)
Code:
function onSay(cid, words, param, channel)
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
		return true
	end

	local t = string.explode(param, ",")
	local ret = RETURNVALUE_NOERROR
	local pos = getCreaturePosition(cid)

	local id = tonumber(t[1])
	if(not id) then
		id = getItemIdByName(t[1], false)
		if(not id) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Item wich such name does not exists.")
			return true
		end
	end

	local amount = 100
	if(t[2]) then
		amount = t[2]
	end
	
	local charges = getItemInfo(id).charges
	if(charges > 0) then
		amount = charges
	end

	local item = doCreateItemEx(id, amount)
	if(t[3] and getBooleanFromString(t[3])) then
		if(t[4] and getBooleanFromString(t[4])) then
			pos = getCreatureLookPosition(cid)
		end

		ret = doTileAddItemEx(pos, item)
	else
		ret = doPlayerAddItemEx(cid, item, true)
	end

	if(ret ~= RETURNVALUE_NOERROR) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Couldn't add item: " .. t[1])
		return true
	end

	doDecayItem(item)
	if(not isPlayerGhost(cid)) then
		doSendMagicEffect(pos, CONST_ME_MAGIC_RED)
	end

	return true
end
 
I already looked at that Hermes, if you read the whole post. That only changes the default number of items or charges on an item. It doesn't set the correct number of charges automatically. That's what I want. I didn't see that function for charges anywhere in the functions list. That's why I came looking here. By the way, Cykotitan, there was an error while compiling what you gave me. Didn't work. I put the new function with the other functions that looked like it.
 
Code:
In static member function `static int32_t LuaScriptInterface::luaGetCharges(lua_State*)': \10029 
C:\Users\xxxxx\Desktop\0.3.6pl1\luascript.cpp `items' was not declared in this scope 
 C:\Users\xxxxx\Desktop\0.3.6pl1\dev-cpp\Makefile.win [Build Error]  [obj//luascript.o] Error 1

This is the error I got trying to compile it...
 
Code:
In static member function `static int32_t LuaScriptInterface::luaGetCharges(lua_State*)': \10029 
C:\Users\xxxxx\Desktop\0.3.6pl1\luascript.cpp `items' was not declared in this scope 
 C:\Users\xxxxx\Desktop\0.3.6pl1\dev-cpp\Makefile.win [Build Error]  [obj//luascript.o] Error 1

This is the error I got trying to compile it...
edited.
 
@RazorBlade
Btw. are you blind? You wanted to make script set charges AUTOMATICALLY to default ones when making item. And so my script worked. It was taking item charges from items.xml (if item had charges) and set as default, instead of "100".

Code:
local charges = getItemInfo(id).charges
if(charges > 0) then
	amount = charges
end
 
Last edited:
Default isn't 100 without charges though. It makes 100 gold coins, it makes 100 apples, etc. It also makes things like the amulet of loss with 100 uses. So that's why I wanted to make my own custom script. That function that Cyko helped with will also come in handy for other things. And no, I'm not blind, I just have mono.
 

Similar threads

Back
Top