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

[CreatureScripts] Conflicting Scripts

STiX

Intermediate OT User
Joined
Aug 22, 2007
Messages
445
Reaction score
135
Location
Western Australia
Well here's what my files look like (most irrelevant information removed). There seems to be some sort of confliction in my advancement scripts...

Creaturescripts.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<creaturescripts>
	<event type="login" name="PlayerLogin" script="login.lua"/>
	<event type="login" name="FirstItems" script="firstitems.lua"/>
	<event type="death" name="PlayerDeath" script="playerdeath.lua"/>
	<event type="advance" name="advance_ani" script="advance_ani.lua"/> 
	<event type="advance" name="level100" script="level100.lua"/>
	<event type="advance" name="level200" script="level200.lua"/>
	<event type="advance" name="level300" script="level300.lua"/> 
	<event type="preparedeath" name="Rook" script="Rook.lua"/> 
	<event type="look" name="playerLook" script="look.lua"/>
</creaturescripts>
login.lua
Code:
function onLogin(cid)
registerCreatureEvent(cid, "PlayerDeath")
registerCreatureEvent(cid, "advance_ani")
registerCreatureEvent(cid, "Rook")
registerCreatureEvent(cid, "level100")
registerCreatureEvent(cid, "level200")
registerCreatureEvent(cid, "level300")
registerCreatureEvent(cid, "playerLook")
	if getPlayerStorageValue(cid, 30004) == -1 then
		doPlayerSendTextMessage(cid,22,"Greetings, "..getPlayerName(cid).."!")
		setPlayerStorageValue(cid, 30004, 1)
	else
		doPlayerSendTextMessage(cid,22,"Welcome back, "..getPlayerName(cid).."!")
	end
	return TRUE
end
level100.lua (the other level200 and level300 scripts are practically the same)
Code:
function onAdvance(cid, skill, oldlevel, newlevel)
	if newlevel == 100 then
		doBroadcastMessage(getPlayerName(cid).." has just advanced to LVL 100.\nCongratulations!", 21)
	end
	return TRUE
end
advance_ani.lua
Code:
local config = {
    [0] = { "Fist", 29}, -- 28 = variable[2]  -- Animation effect
    [1] = { "Club", 29}, -- 28 = variable[2]  -- Animation effect
    [2] = { "Sword", 29}, -- 28 = variable[2]  -- Animation effect
    [3] = { "Axe", 29}, -- 28 = variable[2]  -- Animation effect
    [4] = { "Distance", 29}, -- 28 = variable[2]  -- Animation effect
    [5] = { "Shield", 30}, -- 28 = variable[2]  -- Animation effect
    [6] = { "Fishing", 30}, -- 28 = variable[2]  -- Animation effect
    [7] = { "Magic", 28}, -- 28 = variable[2]  -- Animation effect
    [8] = { "Level", 28} -- 28 = variable[2]  -- Animation effect
}
function onAdvance(cid, skill, oldlevel, newlevel)
local pos = getPlayerPosition(cid)
local positions = {
        {x=pos.x+1,y=pos.y-1,z=pos.z},
        {x=pos.x-1,y=pos.y-1,z=pos.z},
        {x=pos.x+1,y=pos.y+1,z=pos.z},
        {x=pos.x-1,y=pos.y+1,z=pos.z},
        {x=pos.x+1,y=pos.y,z=pos.z},
        {x=pos.x-1,y=pos.y,z=pos.z},
        {x=pos.x,y=pos.y+1,z=pos.z},
        {x=pos.x,y=pos.y-1,z=pos.z}}
        
    for type, variable in pairs(config) do
        if skill == type then
            --doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have raised your "..variable[1].." skill from "..oldlevel.." to "..newlevel..".")
            for i = 1, table.maxn(positions) do
                    doSendMagicEffect(positions[i],variable[2])
            end
        end
    end    
return TRUE
end

The problem is, advance_ani won't work at the same time as the level100, 200 and 300 scripts. I have to comment them out like this:
Code:
function onLogin(cid)
registerCreatureEvent(cid, "PlayerDeath")
registerCreatureEvent(cid, "advance_ani")
registerCreatureEvent(cid, "Rook")
-- registerCreatureEvent(cid, "level100")
-- registerCreatureEvent(cid, "level200")
-- registerCreatureEvent(cid, "level300")
registerCreatureEvent(cid, "playerLook")
	if getPlayerStorageValue(cid, 30004) == -1 then
		doPlayerSendTextMessage(cid,22,"Greetings, "..getPlayerName(cid).."!")
		setPlayerStorageValue(cid, 30004, 1)
	else
		doPlayerSendTextMessage(cid,22,"Welcome back, "..getPlayerName(cid).."!")
	end
	return TRUE
end
The scripts work 100% fine by themselves, but I can't have more than 1 running. I also don't wish to combine them into one single file.
So yer, this is buggin me.
 
Then merge them? There's no need to have several files for the same thing ^.-

PHP:
local val = math.floor(newLevel / 100)
if(val > 0 and val > getPlayerStorageValue(cid, 3400)) then
	doBroadcastMessage(getPlayerName(cid).." has just advanced to LVL " .. (val * 100) .. ".\nCongratulations!", 21)
	setPlayerStorageValue(cid, 3400, val)
end

If you reach from level 99 to 103 it will say you advanced to lvl 100 not 103 (i did in purpose)... It work for all level 100, meaning 200, 300, 400 etc but if you die from 400 to 399 or w/e and lvl up again to 400 it wont bc again!

but if u want it to bc even when u downgrade remove the storage part...

here is full code (all merged)
PHP:
local config = {
    [0] = { "Fist", 29}, -- 28 = variable[2]  -- Animation effect
    [1] = { "Club", 29}, -- 28 = variable[2]  -- Animation effect
    [2] = { "Sword", 29}, -- 28 = variable[2]  -- Animation effect
    [3] = { "Axe", 29}, -- 28 = variable[2]  -- Animation effect
    [4] = { "Distance", 29}, -- 28 = variable[2]  -- Animation effect
    [5] = { "Shield", 30}, -- 28 = variable[2]  -- Animation effect
    [6] = { "Fishing", 30}, -- 28 = variable[2]  -- Animation effect
    [7] = { "Magic", 28}, -- 28 = variable[2]  -- Animation effect
    [8] = { "Level", 28} -- 28 = variable[2]  -- Animation effect
}
function onAdvance(cid, skill, oldlevel, newlevel)
local pos = getPlayerPosition(cid)
local positions = {
        {x=pos.x+1,y=pos.y-1,z=pos.z},
        {x=pos.x-1,y=pos.y-1,z=pos.z},
        {x=pos.x+1,y=pos.y+1,z=pos.z},
        {x=pos.x-1,y=pos.y+1,z=pos.z},
        {x=pos.x+1,y=pos.y,z=pos.z},
        {x=pos.x-1,y=pos.y,z=pos.z},
        {x=pos.x,y=pos.y+1,z=pos.z},
        {x=pos.x,y=pos.y-1,z=pos.z}}
        
    for type, variable in pairs(config) do
        if skill == type then
            --doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have raised your "..variable[1].." skill from "..oldlevel.." to "..newlevel..".")
            for i = 1, table.maxn(positions) do
                    doSendMagicEffect(positions[i],variable[2])
            end
        end
    end    

    local val = math.floor(newlevel / 100)
    if(val > 0 and val > getPlayerStorageValue(cid, 3400)) then
    	doBroadcastMessage(getPlayerName(cid).." has just advanced to LVL " .. (val * 100) .. ".\nCongratulations!", 21)
	    setPlayerStorageValue(cid, 3400, val)
    end

    return TRUE
end
 
Last edited:
Thanks Colandus, I knew it would be you who'd answer this.
I'll test it when I get home, but I'd also like to know whats causing this so I can perhaps patch it if its an OTServ bug + I'll be making a LOT more advance scripts later and its going to be a pain in the ass to merge 'em all.

I'm more than likely going to get confused later down the track, but I guess I can always count on you.

Thank-you!

[Edit]
It's not broadcasting like it should be.
Code:
[08/02/2009 15:26:11] Lua Script Error: [CreatureScript Interface] 
[08/02/2009 15:26:11] data/creaturescripts/scripts/advancement.lua:onAdvance

[08/02/2009 15:26:11] data/creaturescripts/scripts/advancement.lua:33: attempt to perform arithmetic on global 'newLevel' (a nil value)
[08/02/2009 15:26:11] stack traceback:
[08/02/2009 15:26:11] 	data/creaturescripts/scripts/advancement.lua:33: in function <data/creaturescripts/scripts/advancement.lua:12>
 
Last edited:
Back
Top Bottom