[Tutorial] Simple Auto-Repair
#1

NOTE TO ALL: I ain't no MASTER Scripter but I ain't no beginner either. I know what I put in my scripts, and if you don't like the tutorials I make and you just came to critisize rather than to correct or alert of mis-input , Please, Leave now.

Hey! I decided to make a small tutorial on how to make a very, very, very, very simple auto repair code.

Its not a filterscript but to be incorperated in your gamemode/own FS whatever...
All you do at the top of the script add:
pawn Код:
forward Rep(); //You can change Rep to anything you like
What this is, it is a forward to create a public function.

Now at the end of your script add
pawn Код:
public Rep() //Change "Rep" to whatever you named at forward. This is important
{
    for(new i = 0; i < MAX_PLAYERS; i++)
        if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i)) RepairVehicle(GetPlayerVehicleID(i));
}
Corrected by NeTuddMeg
This is what is called when this public function happens.

Now how does this function activate? A timer!
Under OnGameModeInit() add:
pawn Код:
SetTimer("Rep",1000,true); //Change "Rep" to whatever you named at forward. This is important.
This is the timer that calls our function!
It is a 1sec timer. It's in milliseconds you can change time to whatever you please.

Thats it! When you're done it should look something like this.
pawn Код:
#include <a_samp>
forward Rep(playerid,vehicleid);
public OnGameModeInit()
{
       SetTimer("Rep",1000,true);
}
public Rep(playerid,vehicleid)
{
    vehicleid = GetPlayerVehicleID(playerid);
    RepairVehicle(vehicleid);
}
I just had this snippet in my GM so I decided to share it. It is simpler than downloading a mega complexed Auto-Repair FS. It works 100%

I hope this helps! +Rep if this was useful and not a repost of someone else's tutorial.. :S
(I'm sorry if this is a repost. I didn't decide to look because I made this on my own so...)
(Simpler way Pending.........)
Reply
#2

Nice one... This is much better than pressing 2... Anyways this is so easy to make... Well, anyways nice
Reply
#3

vehicleid parameter is not needed and you haven't explained it well about the function and native. Please learn how to script first then make a tutorial.
Reply
#4

hmm.. WTF!

Код:
#include <a_samp>
forward Rep();
public OnGameModeInit()
{
       SetTimer("Rep",1000,true);
}
public Rep()
{
    for(new i = 0; i < MAX_PLAYERS; i++) 
        if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i)) RepairVehicle(GetPlayerVehicleID(i);
}
Reply
#5

Quote:
Originally Posted by ObelesMarc
Посмотреть сообщение
Nice one... This is much better than pressing 2... Anyways this is so easy to make... Well, anyways nice
Thanks so much.

Quote:
Originally Posted by T0pAz
Посмотреть сообщение
vehicleid parameter is not needed and you haven't explained it well about the function and native. Please learn how to script first then make a tutorial.
Explain what really is the problem here because I use the script, everyone that joins my server has the same outcome so I don't see what is the problem with this script.

Quote:
Originally Posted by NeTuddMeg
Посмотреть сообщение
hmm.. WTF!

pawn Код:
#include <a_samp>
forward Rep();
public OnGameModeInit()
{
       SetTimer("Rep",1000,true);
}
public Rep()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
        if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i)) RepairVehicle(GetPlayerVehicleID(i));
}
I see.. This is so that the Timer doesn't loop if anyone isn't connected.. Thanks for the correct. I'll edit the tutorial.
Reply
#6

This is not very good but it work.
It's beter if you use the callback OnVehicleDamageUpdate this is the best way because if you use a timer that may slow down your serveur.

Otherwise good job
Reply
#7

Quote:
Originally Posted by mehdi-jumper
Посмотреть сообщение
This is not very good but it work.
It's beter if you use the callback OnVehicleDamageUpdate this is the best way because if you use a timer that may slow down your serveur.

Otherwise good job
Which (recording to the documentation) doesn't exist.
Reply
#8

Quote:
Originally Posted by Jagofr
Посмотреть сообщение
pawn Код:
#include <a_samp>
forward Rep(playerid,vehicleid);
public OnGameModeInit()
{
       SetTimer("Rep",1000,true);
}
public Rep(playerid,vehicleid)
{
    vehicleid = GetPlayerVehicleID(playerid);
    RepairVehicle(vehicleid);
}
.... It works 100%
No it doesn't! Your code is invalid.
Quote:
Originally Posted by CookieJar
Посмотреть сообщение
Which (recording to the documentation) doesn't exist.
It's OnVehicleDamageStatusUpdate.
Reply
#9

Quote:

t's OnVehicleDamageStatusUpdate.

Yes it is !
Reply
#10

Ill do my research guys.. Thanks for the tips..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)