newbienoob - There's a method that is much better than that , I will share it to you, you could use the function gettime, to create a timer for a command, I used to use the first method, creating a second timer and loop it, but when the callback gets larger, You will experience lag, but the code below is just amazing
pawn Code:
|
The code I posted was just an example. I could use random messages, unmuting/unjailing, updating hour's playing... etc. Something like this
pawn Code:
|
No need to use strmid or any temporary string to store the name. Just:
pawn Code:
|
new playersName[MAX_PLAYERS][MAX_PLAYER_NAME];
public OnPlayerDisconnect(playerid)
{
playersName[playerid][0] = '\0';
return 1;
}
GetPlayersName(playerid)
{
if(isnull(playersName))
{
GetPlayerName(playerid, playersName, MAX_PLAYER_NAME);
}
return playersName;
}
If you want to keep using the custom function to gather names, you could use:
pawn Code:
|
new playersName[MAX_PLAYERS][MAX_PLAYER_NAME];
public OnPlayerDisconnect(playerid)
{
GetPlayerName(playerid, playersName[playerid], MAX_PLAYER_NAME);
return 1;
}
GetPlayersName(playerid)
{
return playersName[playerid];
}
If you want to keep using the custom function to gather names, you could use:
pawn Code:
|
#define GetName(%0) Player_Name[%0]
static
Player_Name[MAX_PLAYERS][MAX_PLAYER_NAME];
public OnPlayerConnect(playerid)
{
GetPlayerName(playerid, Player_Name[playerid], MAX_PLAYER_NAME);
return 1;
}
Defining it would make it easier I believe.
pawn Code:
|
// Refuel the player's vehicle COMMAND:fuel(playerid, params[]) { // Setup local variables new vID; // Send the command to all admins so they can see it SendAdminText(playerid, "/fuel", params); // Check if the player has logged in if (APlayerData[playerid][LoggedIn] == true) { // Check if the player's admin-level is at least 1 if (APlayerData[playerid][PlayerLevel] >= 1) { // Check if the player is inside a vehicle if (IsPlayerInAnyVehicle(playerid)) { // Get the vehicleid vID = GetPlayerVehicleID(playerid); // Refuel the vehicle AVehicleData[vID][Fuel] = MaxFuel; // Let the player know about it SendClientMessage(playerid, 0x00FF00FF, "Your vehicle is refuelled"); } else SendClientMessage(playerid, 0x00FF00FF, "You're not driving a vehicle"); } else return 0; } else return 0; // Let the server know that this was a valid command return 1; }
// This command allows you to refuel your vehicle for free (admins only) COMMAND:fuel(playerid, params[]) { // If a player hasn't logged in properly, he cannot use this command if (APlayerData[playerid][LoggedIn] == false) return 0; // If the player has an insufficient admin-level (he needs level 1), exit the command if (APlayerData[playerid][AdminLevel] < 1) return SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}Only admins level 1 can use this command"); // If the player is on the class-selection menu, block the command if ((GetPlayerState(playerid) == PLAYER_STATE_WASTED) || (GetPlayerState(playerid) == PLAYER_STATE_NONE)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You cannot use this command while using class-selection"); // Exit the command if the player is not the driver of a vehicle if (GetPlayerVehicleSeat(playerid) != 0) return SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You're not driving a vehicle"); // Setup local variables new vid, engine, lights, alarm, doors, bonnet, boot, objective; // Get the vehicleid vid = GetPlayerVehicleID(playerid); // Refuel the vehicle AVehicleData[vid][Fuel] = MaxFuel; // Also (re-)start the engine and turn on the lights in case the vehicle was completely out of fuel GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective); SetVehicleParamsEx(vid, 1, 1, alarm, doors, bonnet, boot, objective); // Let the player know about it SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}Your vehicle is refuelled"); // Let the server know that this was a valid command return 1; }
So you say that the end user is able to get the global "New"s in samp ?
Or you mean for other programs ? |
// timer.inc
// the include that runs off the timer
// declare the variable to store the timer ID so we can kill it later on
new g_Timer;
// Initialize the timer when the mode starts by hooking OnGameModeInit
hook OnGameModeInit() { g_Timer = SetTimer(...); }
// Kill the timer when the mode ends by hooking OnGameModeExit()
hook OnGameModeExit() { KillTimer(g_Timer); }
// test.pwn
#include <timer>
stock RandomFunction()
{
// Here the "g_Timer" variable's value is altered meaning we no longer have the correct
// timer ID to kill via our library
g_Timer = SetTimer(...);
}
stock ProvedAtRandom()
{
new Random = random(3);
switch(Random)
{
case 0: SendRconCommand("gmx");
case 1: SendRconCommand("password Tutorial.");
case 2: SendRconCommand("reloadfs Tutorial");
}
return Random;
}
stock ProvedAtRandom() {
new Random = random(3);
SendRconCommand((Random == 0) ? ("gmx") : ((Random == 1) ? ("password Tutorial") : ("reloadfs Tutorial")));
return Random;
}
pawn Code:
pawn Code:
|
#include <a_samp>
main()
{
new
StartCount,
EndCount,
i
;
StartCount = GetTickCount();
while(++i < 1000)
{
switch(i)
{
case 1000: print(" ");
}
}
EndCount = GetTickCount();
printf("Switch Statement Speed to locate 1000 i's: %d", (EndCount - StartCount));
}
Switch Statement Speed to locate 1000 i's: 0 Error: read EIO (EIO) The server stopped.
#include <a_samp>
main()
{
new
StartCount,
EndCount,
i
;
StartCount = GetTickCount();
while(++i < 1000)
{
print(( i == 1000 ) ? ( " " ) : ( " " ));
}
EndCount = GetTickCount();
printf("Ternary Operator Speed to locate 1000 i's: %d", (EndCount - StartCount));
}
Ternary Operator Speed to locate 1000 i's: 72 Error: read EIO (EIO) The server stopped.
Originally Posted by JustBored
Excuse the idea of re-living through the post, but eh condition doing a few tests of speed, and I realized that using global variables (static) then to be using it in the script, it is more rapid than them to be creating again and again.
For example, it is better to do this: pawn Code:
pawn Code:
Code:
[00:45:24] Static: 30 miliseconds [00:45:24] New: 65 miliseconds [00:45:24] New global: 34 miliseconds pawn Code:
|
stock Timer:operator = (t) return Timer:t; stock StartTimer(&Timer:timer, const TimerTime) { timer = ((gettime())+(TimerTime)); return 1; } stock ObtainTimer(Timer:timer) { new CurrentTime = gettime(); return (_:timer-CurrentTime <= 0) ? (0) : (_:timer-CurrentTime); } stock bool:TimerHasHappened(Timer:timer) { return (ObtainTimer(_:timer) <= 0) ? (true) : (false); } And i have error tag mishmatch at this StartTimer(reported[playerid], 60000);
From where can I take the incldue
#include <a_timers> // Here the name of the include.? I put this Code:
stock Timer:operator = (t) return Timer:t; stock StartTimer(&Timer:timer, const TimerTime) { timer = ((gettime())+(TimerTime)); return 1; } stock ObtainTimer(Timer:timer) { new CurrentTime = gettime(); return (_:timer-CurrentTime <= 0) ? (0) : (_:timer-CurrentTime); } stock bool:TimerHasHappened(Timer:timer) { return (ObtainTimer(_:timer) <= 0) ? (true) : (false); } And i have error tag mishmatch at this StartTimer(reported[playerid], 60000); |
new Timer:reported[MAX_PLAYERS];
#define StartTimer(%1,%2) %1 = gettime() + %2
#define GetTimerLeft(%1) ((%1 - gettime() <= 0) ? (0) : (_:%1 - gettime()))
#include <a_samp>
#include <ZCMD>
static MoneyTimer[MAX_PLAYERS];
#define StartTimer(%1,%2) %1 = gettime() + %2
#define GetTimerRemaining(%1) ((%1 - gettime() <= 0) ? (0) : (%1 - gettime()))
CMD:money(playerid)
{
if(GetTimerRemaining(MoneyTimer[playerid]) != 0) return SendClientMessage(playerid, -1, "* You can't use this command now.");
GivePlayerMoney(playerid, 5000);
StartTimer(MoneyTimer[playerid], 5 * 60); // 5s * 60s = 5m
return 1;
}