You can alternatively use if (new i = strlen(text); text[i] != EOS; i--) for the loop. Your code is better than Lokii's.
|
Word Scrambler
The code is a bit messy and needs to be tweaked. I hope someone else can improve it. https://github.com/AliLogic/word-scr.../scrambler.pwn |
Two things:
You don't need that much code to scramble a word.Take a look at shuffle array function written by SyS somewhere in the forum. Don't make a loop's iteration relay on a random variable's value. |
stock Float:GeoDistance(Float:lat1, Float:lon1, Float:lat2, Float:lon2)
{
const Float:R = 6371.0087714; // Earth radius
new Float:sin1 = floatsin((lat1 - lat2) /2 );
new Float:sin2 = floatsin((lon1 - lon2) /2 );
return 2 * R * asin(floatsqroot(sin1 * sin1 + sin2 * sin2 * floatcos(lat1) * floatcos(lat2))) * (3.14 / 180);
}
new Float:lat1 = 52.5243700 * (3.14 / 180);
new Float:lon1 = 13.4105300 * (3.14 / 180);
new Float:lat2 = 50.4546600 * (3.14 / 180);
new Float:lon2 = 30.5238000 * (3.14 / 180);
printf("Latitude 1: %f | Longtitude 1: %f\n\
Latitude 2: %f | Longtitude 2: %f\n\
Distance: %f", lat1, lon1, lat2, lon2, GeoDistance(lat1, lon1, lat2, lon2));
#include <a_samp>
Float:GetSpeed(playerid)
{
new Float:x, Float:y, Float:z;
GetVehicleVelocity(GetPlayerVehicleID(playerid), x, y, z);
return floatabs(floatsqroot(floatpower(x, 2) + floatpower(y, 2)))*180.5;
}
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
new Float:hp, Float:dmg;
dmg = GetSpeed(playerid);
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(IsPlayerNPC(i) || GetPlayerVehicleID(i) != vehicleid) continue;
GetPlayerHealth(i, hp);
SetPlayerHealth(i, hp-(dmg/3));
}
return 1;
}
If a server would like to release at a specific time, then they can convert seconds to mins by adding *3600 at the end their number (multiply by an hour). This will be good if a server is having a opening beta release and they want their server to open/start at that exact time, will the server is already running but not fully loaded. Place the function on public OnGamemodeInit() For example: public OnGameModeInit() { printf("Starting hang..."); hang(1*3600, false); // hang the server for 3600 seconds = 1 hour } Output: log.txt Starting hang... /* 3600 seconds later */ ---------------------------------- Bare Script ---------------------------------- Number of vehicle models: 0
hang(count, bool:hangDebug) { new hangTick[2]; hangTick[0] = GetTickCount(); new hangTime = 0; for(;;) { new hangStamp = tickcount(); while(tickcount() - hangStamp < 1000) {} if(hangTime > count) break; hangTick[1] = GetTickCount(); hangTime++; if(hangDebug) printf("hanged for %ims", hangTick[1]-hangTick[0]); } if(hangDebug) printf("hang stopped at %i seconds", hangTime); }
hang(4, false);
hanged for 998ms hanged for 1999ms hanged for 2999ms hanged for 3999ms hang stopped at 4 seconds
It will freeze the server and prevent other code running. That's a veryyyyyyy bad idea.
|
public OnPlayerText(playerid, text[]) { if (strfind(text, "I need a taxi") != -1) { new string[80], name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); new Float:X, Float:Y, Float:Z, Float:Angle; format(string, sizeof(string), "Hey %s taxi is in your way!", name); SendChat(string); GetPlayerPos(playerid, X, Y, Z); GetPlayerFacingAngle(playerid, Angle); Createvehicle// here } return 1; }
public OnPlayerText(playerid, text[]) { if (strfind(text, "fuck you") != -1) { new string[80], name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); SendCommand("/kick %i", playerid); format(string, sizeof(string), "Hey %s Fuck off!", name); // you can set a timer so the player can see the message SendChat(string); } return 1; }
serverHang Hangs/pauses your server for what ever reason you would want it to.
param 1 = seconds param 2 = bool How it can be used: Код:
If a server would like to release at a specific time, then they can convert seconds to mins by adding *3600 at the end their number (multiply by an hour). This will be good if a server is having a opening beta release and they want their server to open/start at that exact time, will the server is already running but not fully loaded. Place the function on public OnGamemodeInit() ... |
#include <a_samp>
#include <sscanf2>
#include <zcmd>
CMD:halloween(playerid, params[])
{
new option;
if(sscanf(params, "d", option))
{
SendClientMessage(playerid, 0x8CAA63FF, "SYNTAX: {FFFFFF}/halloween 1 : Wizard Hat - 2 : Devil Mask");
return SendClientMessage(playerid, 0x8CAA63FF, "DESCRIPTION: {FFFFFF}Used to attach either a hat or a mask on your head");
}
switch(option)
{
case 1:
{
if(IsPlayerAttachedObjectSlotUsed(playerid, 8))
{
RemovePlayerAttachedObject(playerid, 8);
return SendClientMessage(playerid, 0x33CCFFFF, "INFO: {FFFFFF}You've just removed your Halloween hat successfully.");
}
SetPlayerAttachedObject(playerid, 8, 19528, 2, 0.125, -0.015, 0.01, 0.0, 0.0, -32.5, 0.9, 0.84, 1.01, 0, 0);
EditAttachedObject(playerid, 8);
SendClientMessage(playerid, 0x33CCFFFF, "INFO: {FFFFFF}You've just put on your Halloween hat! You can remove it by retyping the command.");
}
case 2:
{
if(IsPlayerAttachedObjectSlotUsed(playerid, 9))
{
RemovePlayerAttachedObject(playerid, 9);
return SendClientMessage(playerid, 0x33CCFFFF, "INFO: {FFFFFF}You've just removed your Halloween mask successfully.");
}
SetPlayerAttachedObject(playerid, 9, 11704, 2, 0.05, 0.1, 0.0, -5.099, 85.6, -179.4, 0.396, 0.739, 0.422, 0, 0);
// Resized the original object which was too big by default
EditAttachedObject(playerid, 9);
SendClientMessage(playerid, 0x33CCFFFF, "INFO: {FFFFFF}You've just put on your Halloween mask! You can remove it by retyping the command.");
}
}
return 1;
}
#include <a_samp>
static Text:aim_hit_td;
static aim_show[MAX_PLAYERS] = {false,...};
static const nweps[] =
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
34, 35, 39, 41, 42, 43
};
public OnFilterScriptInit()
{
aim_hit_td = TextDrawCreate(336.400512, 176.088546, "x");
TextDrawLetterSize(aim_hit_td, 0.263998, 0.629333);
TextDrawTextSize(aim_hit_td, -8.000000, 0.000000);
TextDrawAlignment(aim_hit_td, 1);
TextDrawColor(aim_hit_td, -16776961);
TextDrawSetShadow(aim_hit_td, 0);
TextDrawBackgroundColor(aim_hit_td, 255);
TextDrawFont(aim_hit_td, 1);
TextDrawSetProportional(aim_hit_td, 1);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
aim_show[playerid] = false;
return 1;
}
public OnFilterScriptExit()
{
TextDrawDestroy(aim_hit_td);
return 1;
}
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
for(new i = 0; i < sizeof(nweps); i++)
{
if(weaponid == nweps[i]) return 0;
}
if(issuerid != 0xFFFF && !IsPlayerNPC(issuerid) && !aim_show[issuerid])
{
TextDrawShowForPlayer(issuerid, aim_hit_td);
SetTimerEx("HideTD", 200, false, "i", issuerid);
aim_show[issuerid] = true;
}
return 0;
}
forward HideTD(playerid);
public HideTD(playerid)
{
TextDrawHideForPlayer(playerid, aim_hit_td);
aim_show[playerid] = false;
return 1;
}
#include <a_samp>
static timer;
static Text:time;
public OnFilterScriptInit()
{
time = TextDrawCreate(552.900207, 32.800006, "00:00");
TextDrawLetterSize(time, 0.410333, 2.321777);
TextDrawAlignment(time, 1);
TextDrawColor(time, 255);
TextDrawSetShadow(time, 0);
TextDrawSetOutline(time, 1);
TextDrawBackgroundColor(time, -2139062017);
TextDrawFont(time, 0);
TextDrawSetProportional(time, 1);
timer = SetTimer("Update_Time", 1000, true);
return 1;
}
public OnFilterScriptExit()
{
TextDrawDestroy(time);
KillTimer(timer);
return 1;
}
public OnPlayerConnect(playerid)
{
TextDrawShowForPlayer(playerid, time);
return 1;
}
forward Update_Time();
public Update_Time()
{
new str[6], h, m;
gettime(h, m);
format(str, sizeof(str), "%02d:%02d", h, m);
TextDrawSetString(time, str);
return 1;
}
Time script [image]...[/image] PHP Code:
|
Originally Posted by Wikipedia
Snippet is a programming term for a small region of re-usable source code, machine code, or text. Ordinarily, these are formally defined operative units to incorporate into larger programming modules.
[...] |