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

Speed

marcos16

Falkhonn
Joined
May 4, 2012
Messages
224
Reaction score
1
My server is made for low speed.
I'm using a speed of script, but I'm having a lot of problems with it.
I wonder if you have any way to modify the source, that certainly would be less error.

Following is the script that I am using:

Code:
local info = {
[{10, 49}] = {speed = 250},
[{50, 100}] = {speed = 290},
[{101, 149}] = {speed = 340},
[{150, 249}] = {speed = 360},
[{250, 300}] = {speed = 380},
[{301, 4000}] = {speed = 400}
}

function onLogin(cid, skill, oldLevel, newLevel)
    for level, x in pairs(info) do
         if skill == 8 and newLevel >= level[1] and newLevel <= level[2] then
            doChangeSpeed(cid, -getCreatureBaseSpeed(cid))
        doChangeSpeed(cid, x.speed)
            doCreatureSetStorage(cid, 30029, x.speed)
        end
    end
return 1
end
 
I've seen you post like 4 threads regarding this issue.
I'm going to re-write your script so that we know where this 'error' is occurring.
I'm literally stumped since you never explain why it error's, when it error's, how it error's, or what the error's are.


Code:
doChangeSpeed(cid, delta)
Delta is not a value to change the speed to.
Delta tells you that the number will be changed according to your value.
Also using this method, the minimum speed a character can have is 10, so decreasing the character speed to absolute zero (heh) is impossible.

Character speed is 400.
doChangeSpeed(cid, 40) -- This means the character speed will increase by 40.
Character speed is now 440.

So what my script it going to do is take whatever their current speed is, and lower/raise it to the correct value.

Now one thing you need to realise when you use a login script, this only changes their speed when they login.
If they power level from 1-50 in a day, they will be quite fast, until they log out. Then everything will be fine again.
Making an onAdvance script to lower the speed of these power levels is an extra script that is required due to this issue.

So enough explanation, here's my untested scripts.
And again note: this is not the best way to do this, it is 'simply made', so that we can find where your issue is.
Also, your onLogin script has too many parameters that aren't used for onLogin events and is most likely where your confusion is.


data/creaturescripts/scripts/login.lua [somewhere near the bottom with the other registered events]
Code:
registerCreatureEvent(cid, "speed_change")
registerCreatureEvent(cid, "speed_change_advance")
data/creaturescripts/creaturescripts.xml
Code:
<event type="login" name="speed_change" script="speed_change.lua"/>
<event type="advance" name="speed_change_advance" script="speed_change_advance.lua"/>
data/creaturescripts/scripts/speed_change.lua
Code:
function onLogin(cid)
    
     local current_speed = getCreatureBaseSpeed(cid)
    
     -- if players level is below 10, don't change speed
     if getPlayerLevel(cid) < 10 then
         return true
    
     elseif getPlayerLevel(cid) <= 49 then
         if getCreatureBaseSpeed(cid) < 250 then
             doChangeSpeed(cid, (250 - current_speed))
         elseif getCreatureBaseSpeed(cid) > 250 then
             doChangeSpeed(cid, -(current_speed - 250))
         end
    
     elseif getPlayerLevel(cid) <= 100 then
         if getCreatureBaseSpeed(cid) < 290 then
             doChangeSpeed(cid, (290 - current_speed))
         elseif getCreatureBaseSpeed(cid) > 290 then
             doChangeSpeed(cid, -(current_speed - 290))
         end
    
     elseif getPlayerLevel(cid) <= 149 then
         if getCreatureBaseSpeed(cid) < 340 then
             doChangeSpeed(cid, (340 - current_speed))
         elseif getCreatureBaseSpeed(cid) > 340 then
             doChangeSpeed(cid, -(current_speed - 340))
         end
    
     elseif getPlayerLevel(cid) <= 249 then
         if getCreatureBaseSpeed(cid) < 360 then
             doChangeSpeed(cid, (360 - current_speed))
         elseif getCreatureBaseSpeed(cid) > 360 then
             doChangeSpeed(cid, -(current_speed - 360))
         end
    
     elseif getPlayerLevel(cid) <= 300 then
         if getCreatureBaseSpeed(cid) < 380 then
             doChangeSpeed(cid, (380 - current_speed))
         elseif getCreatureBaseSpeed(cid) > 380 then
             doChangeSpeed(cid, -(current_speed - 380))
         end
    
     -- if player level is over 300, change to 400.
     else
         if getCreatureBaseSpeed(cid) < 400 then
             doChangeSpeed(cid, (400 - current_speed))
         elseif getCreatureBaseSpeed(cid) > 400 then
             doChangeSpeed(cid, -(current_speed - 400))
         end
    
     end
    
     return true
end
data/creaturescripts/scripts/speed_change_advance.lua
Code:
function onAdvance(cid, skill, oldlevel, newlevel)
     if skill == 8 then
         local speed_change = (newlevel - oldlevel) * 2
         doChangeSpeed(cid, -speed_change)
         if oldlevel < 50 and newlevel >= 50 then
             doChangeSpeed(cid, 40)
         elseif oldlevel < 101 and newlevel >= 101 then
             doChangeSpeed(cid, 50)
         elseif oldlevel < 150 and newlevel >= 150 or oldlevel < 250 and newlevel >= 250 or oldlevel < 301 and newlevel >= 301 then
             doChangeSpeed(cid, 20)
         end
     end
     return true
end

Please post any errors you receive.

Cheers!

Xikini
 
Last edited by a moderator:
The character is adding speed at each level received, and not as it is in the script ... when you get x level stay with x speed.
Level 200 is with 1358 speed [ adding the speed level 8 to 200 ]

What can it be?
 
Because I'm an idiot. :P
I've edited the above to be correct.
Please re-copy speed_change.lua and speed_change_advance.lua

I've fully tested it on 0.3.7
 
what about some tables?
I knew someone would come along and say this.
Read what I wrote in this thread.
And again note: this is not the best way to do this, it is 'simply made', so that we can find where your issue is.
Or read this thread. Or this thread.
He's clearly having trouble somewhere along the line.
Making it more complex is not going to benefit him, and it's just going to frustrate him until he ditches his server.
Simple and basic is sometimes the best route to go.
 
The error continues , now I put the character level 10 and I will add 1 to 1 level instead of moving forward is regressing speed
 
Your last post was "marcos16,Today at 10:19 PM" from my time-zone.
Can we get a teamviewer session going at 8:00am?
I don't understand how it's not working.. as I said previously I did fully test it on my system prior to posting. :/

-- edit at 7:52 am

I am home now if you want to do the teamviewer.
Send me a pm with your details within the next 2 hours and I'll be able to help you directly, otherwise, well, good luck with your source edit.

-- Edit went teamviewer with marcos16, was unable to figure out the issue. I assume it's some sort of distinction between 0.3.7 and 0.4 sources having the same function, but having two different functions at the same time.

What boggles my mind is the onLogin script not working as intended.

Character has 460 as their current speed.
Log in -> removes 388 speed.. and the player now has 72 speed.

How it can start as a whole number ending with a 0.. the script only has whole numbers ending with a 0.. and ends up taking away a number that literally cannot even exist within the parameters given.. literally mind fucked me

I don't know what to do/try at this point.
 
Last edited by a moderator:
Back
Top