Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- ///////////////////////////////////////////////
- /////////SETUP
- #define SRVR_MAX_SLOT 50 // current max player setting, we could use MAX_PLAYERS but its fix at 200...
- // YOU MUST SET THAT TO YOUR SERVER MAX PLAYER
- ///////////////////////////////////////////////
- #define COLOR_TXT 0xC4996DFF
- #define OFFSET 1.12 // default distance forward of the surf
- #define TIMER_SPEED 75 // Normal timer speed...
- #define TIMER_IDLE 750 // Idle timer speed...
- #define CHECK_RATE 40 // script will look for offline surefer every XX timer frame
- forward public surfing();
- forward public killstatustxt();
- new surf[SRVR_MAX_SLOT], surfer[SRVR_MAX_SLOT], surftimer, Float:surfoffset[SRVR_MAX_SLOT];
- new Float:hashpos[SRVR_MAX_SLOT], isidle[SRVR_MAX_SLOT], systemidle, checker;
- /*
- =============================================================================
- * Magic Surf by www.snoob.net
- * this script put a surf under a player and update the position of the surf *
- * every timer frame. all the surfers use the same timer. if a surfer is *
- * idle, the surf will center on the position, if the surfer is moving the *
- * surf position will be offset forward. if all the surfer are idle the *
- * timer will switch to idle speed. if the ping of a player is higher then *
- * 200 he should walk to avoid steping ahead of the surf *
- * you can find more cool script on my wiki.snoob.net
- * snoob@studio2015.ca *
- =============================================================================
- */
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print(" Magic Surf by www.snoob.net ");
- print("--------------------------------------\n");
- return 1;
- }
- public OnFilterScriptExit()
- {
- for(new b = 0; b < SRVR_MAX_SLOT; b++)
- {
- if(surfer[b]) {
- DestroyObject(surf[b]);
- surfer[b] = 0;
- }
- }
- return 1;
- }
- chkdeadsurf()
- {
- checker = 0;
- for(new b = 0; b < SRVR_MAX_SLOT; b++)
- {
- if(surfer[b] && !IsPlayerConnected(b)) {
- DestroyObject(surf[b]);
- surfer[b] = 0;
- }
- }
- return 1;
- }
- public surfing()
- {
- new a, idle, allidle;
- checker++;
- if(checker == CHECK_RATE) chkdeadsurf();
- for(new i = 0; i < SRVR_MAX_SLOT; i++)
- {
- if(IsPlayerConnected(i) && surfer[i]) {
- a++;
- new Float:playerpos[4], Float:newhashpos;
- GetPlayerPos(i,playerpos[0],playerpos[1],playerpos[2]);
- GetPlayerFacingAngle(i,playerpos[3]);
- newhashpos = (playerpos[0] * playerpos[1]) + (playerpos[2] * playerpos[3]);
- if(newhashpos == hashpos[i]) { // the player is idle
- idle++, isidle[i]++;
- if(isidle[i] == 2) { // the second time the player is idle
- SetObjectPos(surf[i],playerpos[0],playerpos[1],playerpos[2]-1.0855);
- SetObjectRot(surf[i],-90.0,0.0,playerpos[3]);
- }
- }
- else { // the player is not idle
- SetObjectPos(surf[i],playerpos[0]+surfoffset[i]*floatsin(-playerpos[3],degrees),
- playerpos[1]+surfoffset[i]*floatcos(-playerpos[3],degrees),playerpos[2]-1.0855);
- SetObjectRot(surf[i],-90.0,0.0,playerpos[3]);
- isidle[i] = 0;
- }
- hashpos[i] = newhashpos;
- }
- }
- if(a && (a == idle)) { // ALL player are idle
- allidle = 1;
- if(systemidle < 20) { // 20 first time it hapen
- systemidle++;
- }
- if(systemidle == 20) { // we switch the timer to idle speed
- KillTimer(surftimer);
- surftimer = SetTimer("surfing",TIMER_IDLE,true);
- systemidle = 21;
- }
- }
- else if((systemidle == 21) && !allidle) {
- //system is idle but a player move, we switch the timer back to normal speed
- KillTimer(surftimer);
- surftimer = SetTimer("surfing",TIMER_SPEED,true);
- systemidle = 0;
- }
- if(!a) { // no player is curently surfing we kill the timer.
- KillTimer(surftimer);
- surftimer = 0;
- for(new b = 0; b < SRVR_MAX_SLOT; b++) // and destroy any left over surf
- {
- if(surfer[b]) {
- DestroyObject(surf[b]);
- surfer[b] = 0;
- }
- }
- }
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[256], idx;
- cmd = strtok(cmdtext, idx);
- if (strcmp("/surf", cmdtext, true, 6) == 0)
- {
- if(surfer[playerid]) return SendClientMessage(playerid,COLOR_TXT,"You are already on a surf");
- SendClientMessage(playerid,COLOR_TXT,"Have fun!");
- surfoffset[playerid] = OFFSET;
- surf[playerid] = CreateObject(2405,0.0,0.0,0.0,-90.0,0.0,0.0);
- surfer[playerid] = 1;
- if(!surftimer) {
- surftimer = SetTimer("surfing",TIMER_SPEED,true);
- }
- return 1;
- }
- if (strcmp("/unsurf", cmdtext, true, 8) == 0)
- {
- DestroyObject(surf[playerid]);
- surfer[playerid] = 0;
- return 1;
- }
- if(strcmp(cmd, "/offset", true) == 0) {
- new tmp[256];
- tmp = strtok(cmdtext, idx);
- if(!surfer[playerid]) return SendClientMessage(playerid,COLOR_TXT,"You must be surfing to use /offset");
- if(!strlen(tmp)) return SendClientMessage(playerid,COLOR_TXT,"Usage: /offset [-0.9 to 0.9]");
- surfoffset[playerid] = floatstr(tmp);
- format(tmp,sizeof(tmp),"Offset set to %f",surfoffset[playerid]);
- SendClientMessage(playerid,COLOR_TXT,tmp);
- return 1;
- }
- return 0;
- }
- strtok(const string[], &index)
- {
- // more info on strtok are available on the official sa-mp wiki
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement