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

Lua Help fixing script :|

Dankoo

Active Member
Joined
Sep 4, 2010
Messages
1,007
Reaction score
27
I've got this script:

LUA:
function getLoot(monstername)
local loocik = {}
local loot = db.getResult("SELECT * FROM `monsters_loot` WHERE `monster_name`='" .. monstername .. "';")
    if loot:getID() ~= -1 then
        while(true) do
        table.insert(loocik, {loot:getDataInt("item_id"), loot:getDataInt("item_count"), loot:getDataInt("drop_percent"), loot:getDataInt("in_container")})
            if not(loot:next())then
                break
            end
        end
        loot:free()
    else
        print("No loot in database for: "..monstername.."!")
    end
    return loocik
end
function addLoot(x)
pos = x["pos"]
    for i=0,255 do
    pos.stackpos = 255-i
    gpos = getThingfromPos(pos)
        if isCorpse(gpos.uid) == 1 then
        corp = 255-i
        end
    end
pos.stackpos = corp
corpse = getThingfromPos(pos)
local container = 0
    for i=1,#x.loot do
        if x.loot[i][3] >= math.random(1,100) then
            if x.loot[i][4] == 0 or container == nil then
                local la = doAddContainerItem(corpse.uid, x.loot[i][1], math.random(1, x.loot[i][2]))
                if isContainer(la) then 
                container = la 
                end
            elseif x.loot[i][4] == 1 and container ~= nil then
                doAddContainerItem(container, x.loot[i][1], math.random(1, x.loot[i][2]))
            end
        end
    end
end
 
function onKill(cid, target)
    if isMonster(target) then
    local pos = getCreaturePosition(target)
    local monsterloot = getLoot(getCreatureName(target))
    x = {
    ["pos"] = pos,
    ["loot"] = monsterloot
    }
    addEvent(addLoot, 1, x)
    end
    return TRUE
end

It's kinda old (2009), don't know if it works on 0.4...

[22:35:18.386] [Error - CreatureScript Interface]
[22:35:18.386] In a timer event called from:
[22:35:18.386] data/creaturescripts/scripts/lootsystem.lua onKill
[22:35:18.386] Description:
[22:35:18.386] (luaGetThing) Thing not found
 
Code:
    for i=0,255 do
    pos.stackpos = 255-i
    gpos = getThingfromPos(pos)
        if isCorpse(gpos.uid) == 1 then
        corp = 255-i
        end
    end
Code:
	for i = 1, 255 do
		pos.stackpos = i
		local g = getThingfromPos(pos).uid
		if g ~= 0 and isCorpse(g) then
			corp = i
			break
		end
	end
this script is bad
 
Thanks for reply Cyk

this script is bad

Bad in what way? laggy and stuff?

PS:

[11:18:15.262] [Error - CreatureScript Interface]
[11:18:15.262] In a timer event called from:
[11:18:15.262] data/creaturescripts/scripts/lootsystem.lua:onKill
[11:18:15.262] Description:
[11:18:15.262] (luaDoAddContainerItem) Container not found

PS: Items with "container = 0" works

Hmm, actually it doesn't shows the tracked items in loot messages :s
Thats bad =/
============================ OK... LET'S DO IT LOL ===============================
Cyk...

Look, I've made an track item system already, by editing sources [best way in my opinion]. (It's almost working, have NOTHING to do with the script above)

It sets an randomized number to attribute "trackid". The problem, as you might seen already, is that it's stored in BLOB, and there's no way to make an query that reads BLOB.

So, for it to work properly I would have to change two things in the code:

First - Instead going random, set an SERIAL number/letters
Second - Instead storing "trackid" in items attributes, set it at an SQL column named "trackid" [or anywhere I could see these IDs with an SQL query]

The code:

items.cpp
[cpp] trackid = 0;
trackidRndMin = -1;
trackidRndMax = -1;[/cpp]
[cpp] else if(tmpStrValue == "trackid")
{
if(readXMLInteger(itemAttributesNode, "value", intValue))
it.trackid = intValue;
if(readXMLInteger(itemAttributesNode, "random_min", intValue))
it.trackidRndMin = intValue;
if(readXMLInteger(itemAttributesNode, "random_max", intValue))
it.trackidRndMax = intValue;
} [/cpp]
items.h
[cpp]int32_t trackid, trackidRndMin, trackidRndMax;[/cpp]

item.cpp
[cpp] if(it.trackidRndMin > -1 && it.trackidRndMax > it.trackidRndMin)
setAttribute("trackid", it.trackidRndMin + rand() % (it.trackidRndMax+1 - it.trackidRndMin));[/cpp]

items.xml:
XML:
	<item id="2195" name="boots of haste">
		<attribute key="weight" value="750" />
		<attribute key="slotType" value="feet" />
		<attribute key="speed" value="40" />
		<attribute key="trackid" chance="100" random_min="1" random_max="100" />
		<attribute key="showattributes" value="1" />
	</item>

This way there's 100% chance that boots of haste will receive an trackid number, and this number goes from 1 to 100
 
Last edited:
It sets an randomized number to attribute "trackid". The problem, as you might seen already, is that it's stored in BLOB, and there's no way to make an query that reads BLOB.

Code:
SELECT `player_id`,`pid`,`sid`,CONVERT( `attributes` USING latin1 ) FROM `player_items` WHERE CONVERT( `attributes` USING latin1 ) LIKE '%description%'

Yes you can =).
 
Code:
SELECT `player_id`,`pid`,`sid`,CONVERT( `attributes` USING latin1 ) FROM `player_items` WHERE CONVERT( `attributes` USING latin1 ) LIKE '%description%'

Yes you can =).

Nah, actually it returns me "trackid" only

Just the name of the attribute, not its value, y'know?

Here:

2qsujk3.jpg
 
You could just use the special description? That shows the letters/numbers

It's an ugly and quick way to do it =/

But the items loses their original descriptions, and it's just ugly to see that on the item. It should be a number stored in a column called "trackid", that would be ideal.
 
How? What ways?

Just want it to work y'know

And be able to do an globalevent that check for same trackid and delet both, this part I can do, if I manage to make an "readable" system for an SQL query
 
That's why it would be executed along with global save '-'

I will do a custom global save script, that do like /closeserver, then save players, houses and stuff, and delete items with same trackid, then close server, and it will be opened again by the restarter

y'know?
 
It is dumb to use mysql loot system. Just scan the corpse items (loot) and add serial id to the ones you want to.
You can use itemscan of Jano's autoloot script.
 
Nah, actually it returns me "trackid" only

Just the name of the attribute, not its value, y'know?

Here:

2qsujk3.jpg

SQL:
SELECT * , SUBSTRING( CONVERT( attributes
USING latin1 ) 
FROM 38 ) AS  'track'
FROM player_items
WHERE CONVERT( attributes
USING latin1 ) LIKE  '%trackid%'
LIMIT 0 , 30

EDIT: This query returns the trackid only if the item has one attribute (trackid), if item has more than one attribute (like actionid, uniqueid) it'll return maybe trackid and part of another attribute OR it'll return another attribute and part of trackid
 
Back
Top