Making a new command

Viper20184
Posts: 10
Joined: Thu Apr 23, 2015 11:56 am

Making a new command

Post by Viper20184 » Tue May 05, 2015 5:07 pm

So, I am probably way off here. I saw another thread with how to reset dynamis timer by using the setplayervar command.. but I do not want to make this global but i do want to let people reset their timers. I tried changing the reset timer in the config file and rebuilt the server files but people were telling me their timers were still normal so I would rather make a command to let them reset. I tried to use the setplayervar as a base ... looked through other commands to try and get a feel... but im not sure where I went wrong (probably everywhere). So after reading through code, editing out things i didnt think needed to be in there, this is what I have:

Code: Select all

---------------------------------------------------------------------------------------------------
-- func: dynareset
-- desc: Resets Dynamis timer for user
---------------------------------------------------------------------------------------------------

cmdprops =
{
    permission = 0,
    parameters = "ssi"
};

function onTrigger(player)


        player:setVar(dynaWaitxDay, 0);
Basically I want the person to be able to use @dynareset and be able to go back in. Any advice? I had an end at the very end.. but both ways it did not work. sometimes it would shoot an error and others it would crash the game server.

User avatar
kjLotus
Special Guest
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Making a new command

Post by kjLotus » Tue May 05, 2015 6:13 pm

setVar expects a string as the first parameter (you need quotes to declare a string)

Code: Select all

player:setVar("dynaWaitxDay", 0);
while you're at it, the command itself has no parameters, so parameters in cmdprops should just be ""

User avatar
TeoTwawki
Developer
Posts: 527
Joined: Mon Jul 15, 2013 9:50 pm

Re: Making a new command

Post by TeoTwawki » Tue May 05, 2015 7:31 pm

I actually did this awhile back because I got sick of forgetting the exact string for the var name to use with @setplayervar...I was always getting capitalization on that damn "X" wrong.

Code: Select all

---------------------------------------------------------------------------------------------------
-- func: @dynareset <player name>
-- auth: TeoTwawki
-- desc: Resets dynamis wait timer for target player or self
---------------------------------------------------------------------------------------------------

cmdprops =
{
    permission = 1,
    parameters = "s"
};

function onTrigger(player, target)
    if (target == nil) then
        player:setVar("dynaWaitxDay", 0);
        player:PrintToPlayer("Done.");
    else
        local targ = GetPlayerByName( target );
        if (targ ~= nil) then
            targ:setVar("dynaWaitxDay", 0);
            targ:PrintToPlayer("Your Dynamis Timer has been reset.");
            player:PrintToPlayer("Done.");
        else
            player:PrintToPlayer(string.format("Player named '%s' not found!", target));
        end
    end
end
As you can see mine was intended mainly to target others.
Hi, I run The Demiurge server.


Image
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding
PLS USE [ code ] CODE TAGS [ /code ] WHEN POSTING CODE
DO NOT PRIVATE MESSAGE ME ABOUT BUGS

Viper20184
Posts: 10
Joined: Thu Apr 23, 2015 11:56 am

Re: Making a new command

Post by Viper20184 » Tue May 05, 2015 8:44 pm

Cool thanks for the info guys. Ill give that a try now

Desufire
Posts: 162
Joined: Sun Feb 22, 2015 2:58 am

Re: Making a new command

Post by Desufire » Thu Jun 25, 2015 8:35 pm

Gonna necro this topic because I need help with making a new command, so this fits lol.

Trying to create a command similar to @return. I need it to reload the player into the current zone they're in though. I'm wanting to use this as a @stuck command for players who get, well, stuck.

So far what I have is a modified @return script though that only targets the player. Everything else I try either crashes my client or returns errors.

Code: Select all

cmdprops =
{
    permission = 1,
    parameters = "s"
};

function onTrigger(player)
    local ZoneID = 0;
	player:getName();
    ZoneID = player:getPreviousZone();
    if (ZoneID == nil or ZoneID == 0) then
        player:PrintToPlayer( "Previous Zone was a Mog House or there was a problem fetching the ID.");
    else
        player:setPos( 0, 0, 0, 0, ZoneID );
    end
end

Skrakle
Posts: 2
Joined: Sat Feb 21, 2015 4:20 pm
Location: Canada

Re: Making a new command

Post by Skrakle » Fri Jun 26, 2015 2:11 am

Here's a lua command i made last year, it teleported the player to their previous zone, i just tested it with current build.

Code: Select all

---------------------------------------------------------------------------------------------------
-- func: unstuck
-- auth: Vivitaru
-- desc: Teleports a player to their previous zone
---------------------------------------------------------------------------------------------------

cmdprops =
{
    permission = 0,
    parameters = ""
};



function onTrigger(player)
	local nextwait=player:getVar("unstuck_wait");
	
	if (os.time(now)>nextwait) then
		if (player:getPreviousZone()==player:getZone():getID()) then
			player:warp();
		else
			player:setPos(0,0,0,0,player:getPreviousZone());
			player:setVar("unstuck_wait", os.time(now)+3600);
		end
	else
		local mins=math.floor((nextwait-os.time(now))/60)+1;
		player:PrintToPlayer("*** You must wait "..mins.." more minutes before unstuck reuse.");
		return;			
	end

end

Desufire
Posts: 162
Joined: Sun Feb 22, 2015 2:58 am

Re: Making a new command

Post by Desufire » Fri Jun 26, 2015 6:53 pm

I didn't think about adding a wait time to the return command. That will work for now but I would really like a command that would just reload the player into the current zone.

Thanks Shrakle.

User avatar
kjLotus
Special Guest
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Making a new command

Post by kjLotus » Fri Jun 26, 2015 7:06 pm

Desufire wrote:I didn't think about adding a wait time to the return command. That will work for now but I would really like a command that would just reload the player into the current zone.

Thanks Shrakle.
player:setPos(0,0,0,0,player:getZoneID());

literally that's all you need

Desufire
Posts: 162
Joined: Sun Feb 22, 2015 2:58 am

Re: Making a new command

Post by Desufire » Sat Jun 27, 2015 12:23 am

kjLotus wrote:
Desufire wrote:I didn't think about adding a wait time to the return command. That will work for now but I would really like a command that would just reload the player into the current zone.

Thanks Shrakle.
player:setPos(0,0,0,0,player:getZoneID());

literally that's all you need
Seriously? I was making it harder than it needed to be? /sigh

User avatar
kjLotus
Special Guest
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Making a new command

Post by kjLotus » Sat Jun 27, 2015 1:23 am

Desufire wrote:
kjLotus wrote:
Desufire wrote:I didn't think about adding a wait time to the return command. That will work for now but I would really like a command that would just reload the player into the current zone.

Thanks Shrakle.
player:setPos(0,0,0,0,player:getZoneID());

literally that's all you need
Seriously? I was making it harder than it needed to be? /sigh
yep.. common mistake actually, overcomplicating!

Post Reply