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

Optymalizacja skryptu

Julek12

New Member
Joined
Feb 19, 2008
Messages
160
Reaction score
0
Location
Universe -> Milky Way -> Solar System -> Earth ->
Mam taki skrypt
PHP:
function onStepIn(cid, item, position, fromPosition)
    local config = {
    ice = {x=134, y=199, z=5}
    fire = {x=68, y=151, z=5}
    energy = {x=72, y=197, z=5}
    earth = {x=140, y=158, z=5}
    message_type = MESSAGE_EVENT_ORANGE
    }

    if getPlayerLookDir(cid) == 0 then
        newdir = 2
    elseif getPlayerLookDir(cid) == 1 then
        newdir = 3
    elseif getPlayerLookDir(cid) == 2 then
        newdir = 0
    else
        newdir = 1
    end

    if (item.actionid > 34000 and item.actionid < 34020) then
        if getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 6 and getPlayerLevel(cid) >= 30 and isPremium(cid) == TRUE then
            doTeleportThing(cid,config.ice)
            doSendMagicEffect(config.ice,10)
            setPlayerStorageValue(cid, item.actionid - 34000, 1)
        else
            doPlayerSendTextMessage(cid, config.message_type, "Only Premium Druids of level 30 or higher are able to enter this portal")
            doMoveCreature(cid, newdir)
        end
    elseif (item.actionid > 34100 and item.actionid < 34120) then
        if getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 6 and getPlayerLevel(cid) >= 30 and isPremium(cid) == TRUE then
            doTeleportThing(cid,config.earth)
            doSendMagicEffect(config.earth,10)
            setPlayerStorageValue(cid, item.actionid - 34100, 1)
        else
            doPlayerSendTextMessage(cid, config.message_type, "Only Premium Druids of level 30 or higher are able to enter this portal")
            doMoveCreature(cid, newdir)
        end
    elseif (item.actionid > 34200 and item.actionid < 34220) then
        if getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 5 and getPlayerLevel(cid) >= 30 and isPremium(cid) == TRUE then
            doTeleportThing(cid,config.fire)
            doSendMagicEffect(config.fire,10)
            setPlayerStorageValue(cid, item.actionid - 34200, 1)
        else
            doPlayerSendTextMessage(cid, config.message_type, "Only Premium Sorcers of level 30 or higher are able to enter this portal")
            doMoveCreature(cid, newdir)
        end
    elseif (item.actionid > 34300 and item.actionid < 34320) then
        if getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 5 and getPlayerLevel(cid) >= 30 and isPremium(cid) == TRUE then
            doTeleportThing(cid,config.energy)
            doSendMagicEffect(config.energy,10)
            setPlayerStorageValue(cid, item.actionid - 34300, 1)
        else
            doPlayerSendTextMessage(cid, config.message_type, "Only Premium Sorcers of level 30 or higher are able to enter this portal")
            doMoveCreature(cid, newdir)
        end
    end
end
I tutaj mam pytanie czy ten skrypt dało by się zapisać jakoś krócej? Bo czytałem, że im krótszy tym lepiej. Nie proszę o gotowy kod, ale o podpowiedź jak to zrobić.

I drugi problem
Jak widzicie są tu zastosowane Storage Value są one po to, żeby wiedzieć z jakiego miasta się teleportowaliśmy i, żeby jak wejdziemy w teleport powrotny to, żeby nas teleportowało do tego samego miasta. Czy ma ktoś pomysł jak to zrobić? Jeśli źle wytłumaczyłem to proszę powiedzieć to poprawię.
 
PHP:
local config = {
storage =  76447,
trainPosition = {x = 313, y = 300, z = 7}
}

function onStepIn(cid, item, position, fromPosition)
local getStorageValue = getPlayerStorageValue(cid, config.storage)
    if item.id ~= 0 and item.uid ~= 20020 then
        setPlayerStorageValue(cid, config.storage, (item.uid - 20000))
        doTeleportThing(cid, config.trainPosition, FALSE)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_ENERGYAREA)
    else
		if getStorageValue <= 0 then
			getStorageValue = 1
		end
        doTeleportThing(cid, getTownTemplePosition(getStorageValue), FALSE)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_ENERGYAREA)
    end
return TRUE
end

Mój skrypt do przenoszenia na trainy z różnych miast. Możesz go przerobić na własne potrzeby, mam nadzieję, że czegoś się dzięki niemu nauczysz ;)
 
Back
Top