TalkAction /adm to turn GOD, / player to turn PLAYER

.Smile

New Member
Joined
Jan 27, 2019
Messages
14
Reaction score
5
Hello everyone, I am currently a beginner in programming and I am developing a Server, and one of the difficulties I had was to have to alternate between 2 Characters one PLAYER and the other GOD to test some things.

It is a very simple script, and in the future I intend to improve it.

What does the command do?
/adm
- turns your character into GOD and kick him
/player - turns your character into PLAYER and kick him


REMEMBER THAT: It is not everyone who can use this command, you must have your account god access, so you can have this command on an Online Server with other players without them can use.

\data\talkactions\talkactions.xml
XML:
    <talkaction words="/player" script="player.lua" />   
    <talkaction words="/adm" script="adm.lua" />
\data\talkactions\scripts\adm.lua
Lua:
function onSay(player, words, param)
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local position = player:getPosition()
    player:setGroup(Group(3))
    position:sendMagicEffect(14)
    player:remove()
    return false
end
\data\talkactions\scripts\player.lua
Lua:
function onSay(player, words, param)
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local position = player:getPosition()
    player:setGroup(Group(1))
    position:sendMagicEffect(13)
    player:remove()
    return false
end
 
Last edited by a moderator:

Klonera

Once upon a time.
Joined
Jul 16, 2016
Messages
350
Reaction score
31
Location
Sweden
Hello everyone, I am currently a beginner in programming and I am developing a Server, and one of the difficulties I had was to have to alternate between 2 Characters one PLAYER and the other GOD to test some things.

It is a very simple script, and in the future I intend to improve it.

What does the command do?
/adm
- turns your character into GOD and kick him
/player - turns your character into PLAYER and kick him


REMEMBER THAT: It is not everyone who can use this command, you must have your account god access, so you can have this command on an Online Server with other players without them can use.

\data\talkactions
talkactions.xml

Code:
    <talkaction words="/player" script="player.lua" />   
    <talkaction words="/adm" script="adm.lua" />
\data\talkactions\scripts
adm.lua
Code:
function onSay(player, words, param)
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local position = player:getPosition()
    player:setGroup(Group(3))
    position:sendMagicEffect(14)
    player:remove()
    return false
end
\data\talkactions\scripts
player.lua
Code:
function onSay(player, words, param)
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local position = player:getPosition()
    player:setGroup(Group(1))
    position:sendMagicEffect(13)
    player:remove()
    return false
end
So if i want this to be gm/cm then i change this?
ACCOUNT_TYPE_GOD then
player:setGroup(Group(3))
 
OP
.Smile

.Smile

New Member
Joined
Jan 27, 2019
Messages
14
Reaction score
5
Nice release! Advanced script! Good work!
...Thank you.

So if i want this to be gm/cm then i change this?
ACCOUNT_TYPE_GOD then
player:setGroup(Group(3))

ACCOUNT_TYPE_GOD
then - Only accounts with Access 5 can run this command being player or adm, so ordinary players can not run.

\data\XML
group.xml
you can see the groups.

Group(3) - Group ID
 

Klonera

Once upon a time.
Joined
Jul 16, 2016
Messages
350
Reaction score
31
Location
Sweden
...Thank you.



ACCOUNT_TYPE_GOD then - Only accounts with Access 5 can run this command being player or adm, so ordinary players can not run.

\data\XML
group.xml
you can see the groups.


Group(3) - Group ID
This does not work, tried it out with the normal documents you've made awell.
Getting no errors in console but it does not work
 
OP
.Smile

.Smile

New Member
Joined
Jan 27, 2019
Messages
14
Reaction score
5
This does not work, tried it out with the normal documents you've made awell.
Getting no errors in console but it does not work
Did you give GOD Access to your account in the database?
 

LazyBear

So lazy
Joined
Nov 27, 2018
Messages
48
Reaction score
35
I'd suggest you make a newer version which combines all three promotions as a tutor, gamemaster (or CM, GOD) and back to a player in one single script. Would be way better than having two scripts.
 

Danat

Excellent OT User
Joined
Jun 6, 2008
Messages
47
Reaction score
12
Great Idea!
So i made one based on this, with all groups inside same talkaction: for talkactions.xml
Code:
    <talkaction words="/changegroup" separator=" " script="changegroup.lua" />
Note: you can change words here, doesnt have to be "changegroup", ex "cg" or others.
Also, made two variants, first works on self, (player, with god account, using it gets its own group changed)
Example: /changegroup gm
changegroup.lua:
Code:
local effect = CONST_ME_HOLYDAMAGE

function onSay(player, words, param)
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end


    if param == "admin" then
        player:setGroup(Group(6))
        player:getPosition():sendMagicEffect(effect)
        player:remove()
    elseif param == "communitymanager" or param == "cm" then
        player:setGroup(Group(5))
        player:getPosition():sendMagicEffect(effect)
        player:remove()
    elseif param == "gamemaster" or param == "gm" then
        player:setGroup(Group(4))
        player:getPosition():sendMagicEffect(effect)
        player:remove()
    elseif param == "seniortutor" then
        player:setGroup(Group(3))
        player:getPosition():sendMagicEffect(effect)
        player:remove()
    elseif param == "tutor" then
        player:setGroup(Group(2))
        player:getPosition():sendMagicEffect(effect)
        player:remove()
    elseif param == "player" then
        player:setGroup(Group(1))
        player:getPosition():sendMagicEffect(effect)
        player:remove()
    else
        player:sendCancelMessage("A group with that name does not exist.")
    end
    return false
end
The second, uses the param to get a player based on name: example: /changegroup myplayer,admin
Warning: Any player with god account can use this to make any player admin or other groups above player.
Code:
local effect = CONST_ME_HOLYDAMAGE

function onSay(player, words, param)
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local split = param:split(",")
    if split[2] == nil then
        player:sendCancelMessage("Insufficient parameters.")
        return false
    end

    local target = Player(split[1])
    if target == nil then
        player:sendCancelMessage("A player with that name is not online.")
        return false
    end

    
    if split[2] == "admin" then
        target:setGroup(Group(6))
        target:getPosition():sendMagicEffect(effect)
        target:remove()
    elseif split[2] == "communitymanager" or split[2] == "cm" then
        target:setGroup(Group(5))
        target:getPosition():sendMagicEffect(effect)
        target:remove()
    elseif split[2] == "gamemaster" or split[2] == "gm" then
        target:setGroup(Group(4))
        target:getPosition():sendMagicEffect(effect)
        target:remove()
    elseif split[2] == "seniortutor" then
        target:setGroup(Group(3))
        target:getPosition():sendMagicEffect(effect)
        target:remove()
    elseif split[2] == "tutor" then
        target:setGroup(Group(2))
        target:getPosition():sendMagicEffect(effect)
        target:remove()
    elseif split[2] == "player" then
        target:setGroup(Group(1))
        target:getPosition():sendMagicEffect(effect)
        target:remove()
    else
        player:sendCancelMessage("A group with that name does not exist.")
    end
    return false
end
There, thanks again for the idea, its great to be able to switch to player to test and play.
 
OP
.Smile

.Smile

New Member
Joined
Jan 27, 2019
Messages
14
Reaction score
5
@Danat How nice that you liked it and thank you for doing that other Script, I intended to do something like this, I'll study the way you did and apply it in other codes, thank you.
 

Stigma

Veteran OT User
Joined
Feb 14, 2015
Messages
4,391
Reaction score
1,971
Why not update the account type as well?
Most commands don't even check for specific group types, they check for account types.
Changing group itself won't do anything so it's pointless to have a command in which the result most people expect is actually still locked behind a specific account type which is needed for the commands people expect to use from something like this.
Lua:
function Player.updateAccountType(self, accountType)
    local accid = self:getAccountId()
    self:remove()
    db.query("UPDATE `accounts` SET `type` = ".. accountType .." WHERE `id` = ".. accid)
end
 

Steve Albert

Banned User
Joined
Dec 9, 2018
Messages
267
Reaction score
100
Great Idea!
So i made one based on this, with all groups inside same talkaction: for talkactions.xml
Code:
    <talkaction words="/changegroup" separator=" " script="changegroup.lua" />
Note: you can change words here, doesnt have to be "changegroup", ex "cg" or others.
Also, made two variants, first works on self, (player, with god account, using it gets its own group changed)
Example: /changegroup gm
changegroup.lua:
Code:
local effect = CONST_ME_HOLYDAMAGE

function onSay(player, words, param)
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end


    if param == "admin" then
        player:setGroup(Group(6))
        player:getPosition():sendMagicEffect(effect)
        player:remove()
    elseif param == "communitymanager" or param == "cm" then
        player:setGroup(Group(5))
        player:getPosition():sendMagicEffect(effect)
        player:remove()
    elseif param == "gamemaster" or param == "gm" then
        player:setGroup(Group(4))
        player:getPosition():sendMagicEffect(effect)
        player:remove()
    elseif param == "seniortutor" then
        player:setGroup(Group(3))
        player:getPosition():sendMagicEffect(effect)
        player:remove()
    elseif param == "tutor" then
        player:setGroup(Group(2))
        player:getPosition():sendMagicEffect(effect)
        player:remove()
    elseif param == "player" then
        player:setGroup(Group(1))
        player:getPosition():sendMagicEffect(effect)
        player:remove()
    else
        player:sendCancelMessage("A group with that name does not exist.")
    end
    return false
end
The second, uses the param to get a player based on name: example: /changegroup myplayer,admin
Warning: Any player with god account can use this to make any player admin or other groups above player.
Code:
local effect = CONST_ME_HOLYDAMAGE

function onSay(player, words, param)
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local split = param:split(",")
    if split[2] == nil then
        player:sendCancelMessage("Insufficient parameters.")
        return false
    end

    local target = Player(split[1])
    if target == nil then
        player:sendCancelMessage("A player with that name is not online.")
        return false
    end

  
    if split[2] == "admin" then
        target:setGroup(Group(6))
        target:getPosition():sendMagicEffect(effect)
        target:remove()
    elseif split[2] == "communitymanager" or split[2] == "cm" then
        target:setGroup(Group(5))
        target:getPosition():sendMagicEffect(effect)
        target:remove()
    elseif split[2] == "gamemaster" or split[2] == "gm" then
        target:setGroup(Group(4))
        target:getPosition():sendMagicEffect(effect)
        target:remove()
    elseif split[2] == "seniortutor" then
        target:setGroup(Group(3))
        target:getPosition():sendMagicEffect(effect)
        target:remove()
    elseif split[2] == "tutor" then
        target:setGroup(Group(2))
        target:getPosition():sendMagicEffect(effect)
        target:remove()
    elseif split[2] == "player" then
        target:setGroup(Group(1))
        target:getPosition():sendMagicEffect(effect)
        target:remove()
    else
        player:sendCancelMessage("A group with that name does not exist.")
    end
    return false
end
There, thanks again for the idea, its great to be able to switch to player to test and play.
Well done! I just made it a little smaller for you.
Lua:
local effect = CONST_ME_HOLYDAMAGE

local groups = {
    ['admin'] = 6,
    ['cm'] = 5,
    ['gm'] = 4,
    ['seniortutor'] = 3,
    ['tutor'] = 2,
    ['player'] = 1
}

function onSay(player, words, param)
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local split = param:split(",")
    if not split[2] then
        player:sendCancelMessage("Insufficient parameters.")
        return false
    end

    local target = Player(split[1])
    if not target then
        player:sendCancelMessage("A player with that name is not online.")
        return false
    end

    local gid = groups[split[2]:lower()]
    if gid then
        target:setGroup(Group(gid))
        target:getPosition():sendMagicEffect(effect)
        target:remove()
    else
        player:sendCancelMessage("A group with the name "..slpit[2].." does not exist.")
    end
    return false
end
 
Top