An Admin command ...
#1

I have added a script to my gamemode to make time synced but i want to make an admin command to change time ...
pawn Код:
//
// Keeps the in game time synced to the server's time and
// draws the current time on the player's hud using a textdraw/
// (1 minute game-time = 1 second real world time)
//
//  Kye 2009

#include <a_samp>
#pragma tabsize 0

//--------------------------------------------------

// Setup global variables
new ServerMinutes, ServerHours, Text:TimeDisplay, TimeString[32];

public OnFilterScriptInit()
{
    TimeDisplay = TextDrawCreate(605.0, 25.0, "00:00");
    TextDrawUseBox(TimeDisplay, 0);
    TextDrawFont(TimeDisplay, 3);
    TextDrawSetShadow(TimeDisplay, 0); // no shadow
    TextDrawSetOutline(TimeDisplay, 2); // thickness 1
    TextDrawBackgroundColor(TimeDisplay, 0x000000FF);
    TextDrawColor(TimeDisplay, 0xFFFFFFFF);
    TextDrawAlignment(TimeDisplay, 3);
    TextDrawLetterSize(TimeDisplay, 0.5, 1.5);

    // Start a timer that runs every second
    SetTimer("ProcessGameTime", 1000, 1);
}

forward ProcessGameTime();
public ProcessGameTime()
{
    // Increment the minute counter
    ServerMinutes++;

    // One hour has passed
    if(ServerMinutes == 60)
    {
        // Reset the minutes to 0
        ServerMinutes = 0;
        // Increase the hours
        ServerHours++;

        // One day has passed
        if(ServerHours == 24)
            ServerHours = 0;
    }

    // Format the text to be shown on the textdraw
    format(TimeString,32,"%02d:%02d", ServerHours, ServerMinutes);
    TextDrawSetString(TimeDisplay, TimeString);

    // Update the time for every player
    for (new playerid; playerid < MAX_PLAYERS; playerid++)
    {
        // Check if the player is connected
        if (IsPlayerConnected(playerid))
        {
            // Update the time for this player
            SetPlayerTime(playerid, ServerHours, ServerMinutes);
        }
    }
}

public OnPlayerSpawn(playerid)
{
    TextDrawShowForPlayer(playerid, TimeDisplay);
   
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    TextDrawHideForPlayer(playerid, TimeDisplay);

    return 1;
}

// This callback gets called when a player disconnects from the server
public OnPlayerDisconnect(playerid, reason)
{
    TextDrawHideForPlayer(playerid, TimeDisplay);

    return 1;
}
Reply
#2

This agian...
The part to ask for a script is missing.
Ask in the stickied thread in the Server Support section, or SEARCH for a filterscript.
And if you want to make one yourself, a little info: the function for it is
pawn Код:
SetWorldTimer(hour);
Howto create that cmd:
Check whether he is admin.
check whether he is typing the correct params.
Then set the time.
Send a client message to all.
Reply
#3

Then make it.

IsPlayerAdmin + sscanf + SetWorldTime.
Reply
#4

pawn Код:
CMD:settime(playerid,params[])
{
    if(!IsPlayerAdmin(playerid)) return 0;
    new hour, minute;
    if(sscanf(params,"ii",hour,minute)) return SendClientMessage(playerid, 0xFFFFFFFF, "Useage: /settime [hour] [minute]")
    format(TimeString,32,"%02d:%02d", hour, minute);
    TextDrawSetString(TimeDisplay, TimeString);

    for (new playerid; playerid < MAX_PLAYERS; playerid++)
    {
        if (IsPlayerConnected(playerid))
        {
            SetPlayerTime(playerid, hour, minute);
        }
    }
    return 1;
}
EDIT: Oh, were we not gonna help this guy politely?
Reply
#5

Thanks, i think this will work
Reply
#6

Quote:
Originally Posted by Aerotactics
Посмотреть сообщение
EDIT: Oh, were we not gonna help this guy politely?
Quote:

but i want to make an admin command to change time ...

He didn't ask for help. It was just a simple statement: he wanted to make an admin command.
And I don't understand, for which reason you made that code. Concearning his first post, I don't think he needs it.
Reply
#7

Aerotactics, It doesn't work !!!!!!!
Reply
#8

What does not work? Explain more?
You get errors/warnings? If yes, show them.
Reply
#9

Error :
Quote:

C:\Users\SiMohamed\Desktop\SAMP Scripts\Xtremies Server\Xtremies Server\gamemodes\Xtremies.pwn(15030) : error 001: expected token: ";", but found "-identifier-"
C:\Users\SiMohamed\Desktop\SAMP Scripts\Xtremies Server\Xtremies Server\gamemodes\Xtremies.pwn(15033) : warning 219: local variable "playerid" shadows a variable at a preceding level
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.

Reply
#10

pawn Код:
CMD:settime(playerid,params[])
{
    if(!IsPlayerAdmin(playerid)) return 0;
    new hour, minute;
    if(sscanf(params,"ii",hour,minute)) return SendClientMessage(playerid, 0xFFFFFFFF, "Useage: /settime [hour] [minute]");
    format(TimeString,32,"%02d:%02d", hour, minute);
    TextDrawSetString(TimeDisplay, TimeString);

    for (new playerid; playerid < MAX_PLAYERS; playerid++)
    {
        if (IsPlayerConnected(playerid))
        {
            SetPlayerTime(playerid, hour, minute);
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)