• Welcome to Vice City Multiplayer.
 

Speedometer by Madara

Started by Madara, March 18, 2011, 05:05:14 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Madara

Hi all, here again up more code and utilities for use by their server, well this time I teach how to make the speedometer for vehicles (obio), well, begin.

To begin with we will create a numbering system, this type of system stores numbers, text or decimal numbers on a player, as this will use it to the speedometer and places it on top of our GM or where there are more of these. And is created if:

enum playerToSpeedo
{
   Speedo,
   SpeedoAct,
   Float:LastX,
   Float:LastY,
   Float:LastZ,
}


After that, you must create a new word which will be used this system along with the player that is building up the same, this will put it where it is located the other "new", but example "new gPlayers[MAX_PLAYERS][MAX_PLAYERS_NAME+1];. And it would be something if:

new Speedometer[MAX_PLAYERS][playerToSpeedo];

Now, we move into the "public OnPlayerDisconnect (playerid, reason)" and add this line to serve so that when a player leaves the server (for any reason), if he was in a car, you remove the ticket value "true", it does show you the speedometer of your vehicle. and is created is:

public OnPlayerDisconnect(playerid, reason)
{    
   if(Speedometer[playerid][Speedo] == 1) Speedometer[playerid][Speedo] = 0;
   return 1;
}


After that, we move into the "public OnPlayerEnterVehicle (playerid, vehicles, ispassenger)", there arem also the same as what we made in public before, but this time with the ticket if your speedometer is on, this is so when the player enters the vehicle, the speedometer will check if he has his kph on, and if you send your speedometer. And it would be more or less if:

public OnPlayerEnterVehicle(playerid,vehicleid,ispassenger)
{
   if(Speedometer[playerid][Speedo] == 0 && Speedometer[playerid][SpeedoAct] == 0) Speedometer[playerid][Speedo] = 1;
   return 1;
}


Likewise, we will do the same in the "public OnPlayerExitVehicle (playerid, vehicle), but this time it will remove the ticket of" true "to get your speedometer while not in the vehicle, and if you avoid mistakes. We will make it if:

public OnPlayerExitVehicle(playerid, vehicleid)
{
   if (Speedometer[playerid][Speedo] == 1) {Speedometer[playerid][Speedo] = 0; GameTextForPlayerBottom(playerid,"\x10");}
   return 1;
}


Now create the command to ask if they want their kph is displayed or not. And places it in either "public", where you put the commands, but for any confusion, we will put an example in the "public OnPlayerText (playerid, cmdtext [])":

public OnPlayerText(playerid, cmdtext[])
{
if (strcmp(cmd, "!kph", true) == 0) {
       new MSN[256]; tmp = strtok(cmdtext, idx);
if (!strlen(tmp)) {format(MSN, 256,"[Syntax] - The correct use: %s <on/off>",cmdtext); SendClientMessage(playerid, 0x04A36BFF, MSN);}
else {
     if (strcmp(tmp, "on", true) == 0) {
 if (Speedometer[playerid][SpeedoAct] == 0) SendClientMessage(playerid, 0x04A36BFF,"[Error] - You have are already KpH turned ON.");
 else {
Speedometer[playerid][SpeedoAct] = 0;
SendClientMessage(playerid, 0x04A36BFF,"KpH turned ON.");
if(IsPlayerInAnyVehicle(playerid)) Speedometer[playerid][Speedo] = 1;
}
      }
              else if (strcmp(tmp, "off", true) == 0) {
  if (Speedometer[playerid][SpeedoAct] == 1) SendClientMessage(playerid, 0x04A36BFF,"[Error] - You have are already KpH turned OFF.");
  else {
Speedometer[playerid][SpeedoAct] = 1;
SendClientMessage(playerid, 0x04A36BFF,"KpH turned OFF.");
if(IsPlayerInAnyVehicle(playerid)) {Speedometer[playerid][Speedo] = 0; GameTextForPlayerBottom(playerid,"\x10");}
}
          }
 else SendClientMessage(playerid, 0x04A36BFF,"[Syntax] - The correct use: !kph <on/off>");
    }
    return 1;
      }

      return 0;
}


PD:If you do not have tmp defined, define it as if they have the function strtok

Now, place a timer that causes the "speedo" remain active on the server, we first started putting it in the "public OnGameModeInit ()":

public OnGameModeInit()
{
SetTimer("SpeedoVehicle",500,1);
       return 1;
}


And finally we will create this function we put in the timer, this function is the process done to take out the distance traveled by a vehicle, more than anything, this function takes the positions you have with the latter having, by the way to qui system will use texts that are "LastX, LastY, LastZ" as if by the same coordinate multipilcarlas divided into 2, and added the three after having taken each of the coordinates, and will use its value to mutiplicarlos then the speed way to display the numbers:

public SpeedoVehicle()
{
new Float:x, Float:y, Float:z, Float:distance, MSN[256];
   for(new i = 0; i <= MAX_PLAYERS; i++) {
   new plrv = FindPlayerIDFromString(gPlayers[i]);

   if (Speedometer[i][Speedo] == 1 && IsPlayerConnected(i) && IsPlayerInAnyVehicle(i)) {
   GetPlayerPos(plrv, x, y, z);
   distance = floatsqroot(floatpower(floatabs(floatsub(x,Speedometer[plrv][LastX])),2)+floatpower(floatabs(floatsub(y,Speedometer[plrv][LastY])),2)+floatpower(floatabs(floatsub(z,Speedometer[plrv][LastZ])),2));
            Speedometer[plrv][LastX] = x;
            Speedometer[plrv][LastY] = y;
        Speedometer[plrv][LastZ] = z;
       format(MSN, sizeof(MSN), "~x~KpH: ~h~ %d",floatround(floatmul(distance,3.2)));
       GameTextForPlayerBottom(plrv,MSN);
   }
  }
  return 1;
}


Well, with this finish a speedometer for our server, I hope you like it and one more thing, if it has "FindPlayerIDFromString (agregenla [])", tag on your server, also the " strtok (cmdtext, idx) "but if you already have, not add it.

Credits: YO ( Madara ) + SAMP.

Greetings. :D

Scripter

#1
oo yea thnx madara u rocks  :o
u need to be post MPH bcz i think MPH is best
but we can use it thnx

sseebbyy

#2
I have errors :

C:\Program Files\Messenger\SERVER\Drift Server\gamemodes\mode.pwn(20) : error 017: undefined symbol "playerToSpeedo"
C:\Program Files\Messenger\SERVER\Drift Server\gamemodes\mode.pwn(20) : error 009: invalid array size (negative or zero)
C:\Program Files\Messenger\SERVER\Drift Server\gamemodes\mode.pwn(85) : error 042: invalid combination of class specifiers
C:\Program Files\Messenger\SERVER\Drift Server\gamemodes\mode.pwn(839) : warning 202: number of arguments does not match definition
C:\Program Files\Messenger\SERVER\Drift Server\gamemodes\mode.pwn(1006) : error 017: undefined symbol "pInfo"
C:\Program Files\Messenger\SERVER\Drift Server\gamemodes\mode.pwn(1006) : warning 215: expression has no effect
C:\Program Files\Messenger\SERVER\Drift Server\gamemodes\mode.pwn(1006) : error 001: expected token: ";", but found "]"
C:\Program Files\Messenger\SERVER\Drift Server\gamemodes\mode.pwn(1006) : error 029: invalid expression, assumed zero
C:\Program Files\Messenger\SERVER\Drift Server\gamemodes\mode.pwn(1006) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.0.3367 Copyright (c) 1997-2005, ITB CompuPhase


7 Errors.

Madara

By the way,i speak more spanish than english

BIG[H]

My Guru FORUM MUST VISITmegavcmp.freeforums.org

BIG[H] = BIG HaLL

yazeen

#5
lol he may be uploaded in that site Little bug[h] big[H] lol

Madara

#6
Quote from: BIG[H] on March 18, 2011, 09:05:30 AM
Copy Cats :P

Quotehttp://www.gtamscripting.info/index.php?topic=80.msg675#msg675

That function is done on SAMP forums, that's why I put in credits: Credits: I (Madara) + SAMP. "that releases it to function in vcmp, or not read?

sseebbyy:
Check this out as I put it, because mine does not give errors, If the error persists, then contact me at my msn [email protected].

tato

i was saying if he can help me to put the speedometer or make a FS ;D





<!-- Facebook Badge START --><a href="http://es-es.facebook.com/eduardoeslindo" target="_TOP" style="font-family: &quot;lucida grande&quot;,tahoma,verdana,arial,sans-serif; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3B5998; text-decoration: none;" title="Eduardo Estrada">Eduardo Estrada</a><br/><a href="http://es-es.facebook.com/eduardoeslindo" target="_TOP" title="Eduardo Estrada"><img src="http://badge.facebook.com/badge/697470158.6069.1979465113.png" width="120" height="272" style="b

Robd

Well, glad to see the pawn scripts picking up... sad thing is

You came up with this like 1 day before me!!!!

((and I did mine myself))

Shutup, I know I'm a noob that thinks he's awesome but because I wrote this I must realise how awesome I aren't.
but yet i continue to think im awesome so....
Hello, this is Robd from the past.
If you are seeing this I have either posted something stupid, forgotten something, started a stupid topic, or a combination of the three.

Please forgive us for this mistake.

Regards, management

DivX


tato

can u make a filterscript PLZZZ





<!-- Facebook Badge START --><a href="http://es-es.facebook.com/eduardoeslindo" target="_TOP" style="font-family: &quot;lucida grande&quot;,tahoma,verdana,arial,sans-serif; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3B5998; text-decoration: none;" title="Eduardo Estrada">Eduardo Estrada</a><br/><a href="http://es-es.facebook.com/eduardoeslindo" target="_TOP" title="Eduardo Estrada"><img src="http://badge.facebook.com/badge/697470158.6069.1979465113.png" width="120" height="272" style="b