SA-MP Forums Archive
Our scripting fails - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP (https://sampforum.blast.hk/forumdisplay.php?fid=3)
+--- Forum: General (https://sampforum.blast.hk/forumdisplay.php?fid=13)
+--- Thread: Our scripting fails (/showthread.php?tid=516037)



Our scripting fails - [NWA]Hannes - 29.05.2014

So I've had this room with poison for as long as I can remember, and if you're in it you will loose 1 health every second..
pawn Code:
SetTimer("PoisonCheck", 1000, true);
This under OnGameModeInit, pretty basic really.

The check was the following:
pawn Code:
forward PoisonCheck();
public PoisonCheck()
{
    foreach(new i:Player)
    {
        if(IsPlayerInArea(i, -2692.4241, -2676.4875, 657.7609, 665.1196))
        {
            new Float:Health;
            GetPlayerHealth(i, Health);
            SetPlayerHealth(i, Health-1);
        }
    }
}
Also very basic, however it is this function that screwed it up

pawn Code:
stock IsPlayerInArea(playerid, Float:min_x, Float:min_y, Float:max_x, Float:max_y)
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    if(X >= min_x && Y >= min_y && X <= max_x && Y <= max_y) return 1;
    return 0;
}
I've searched my script for a while to figure out what was wrong since I lost 1 health all the time even if I was not in the zone, when I noticed that I had the max_x coordinates in min_y and the min_y coordinates in max_x.

The correct function for my script was
pawn Code:
stock IsPlayerInArea(playerid, Float:min_x, Float:max_x, Float:min_y, Float:max_y)
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    if(X >= min_x && Y >= min_y && X <= max_x && Y <= max_y) return 1;
    return 0;
}
Since I copypasted this version from another script where it used a similar version and my poison script had been working good until I changed the function.

This resulted in taking 1 damage every second in the following zone: http://i.imgur.com/ht6xtSl.png
Instead of the very small zone in the top-left corner: http://i.imgur.com/SnkIUiT.png
Notice any difference? http://i.imgur.com/PwsJuyw.gif

After fixing this error I really felt like the beginner I was when I started scripting, and that this was a scripting fail.
Anyways, back on topic, what scripting fails have you done? Has anything made you feel like a beginner when you're a great scripter? Have you ever made a really basic error and not figured it out? Post it all!


Re: Our scripting fails - Cookland - 29.05.2014




Re: Our scripting fails - grovestreet4life - 29.05.2014

Basically, there's a fail everytime I try to script something. Sooner or later lol.


Re: Our scripting fails - BlueBaron - 29.05.2014

Quote:
Originally Posted by grovestreet4life
View Post
Basically, there's a fail everytime I try to script something. Sooner or later lol.
Kinda explains my experience also. Even the godscripters fail... Do they?


Re: Our scripting fails - grovestreet4life - 29.05.2014

Quote:
Originally Posted by bluebaron
View Post
Kinda explains my experience also. Even the godscripters fail... Do they?
Of course. Even Y_Less and others like him. Or not? lol


Re: Our scripting fails - iZN - 29.05.2014

Everybody makes a mistake, there is no one who don't makes mistake. In the past I've made many mistakes which was totally newbie related which I realized afterwards and I was like "What the hell? This was so easy!" I don't remember them though.


Re: Our scripting fails - punklord - 29.05.2014

Quote:
Originally Posted by iZN
View Post
Everybody makes a mistake, there is no one who don't makes mistake. In the past I've made many mistakes which was totally newbie related which I realized afterwards and I was like "What the hell? This was so easy!" I don't remember them though.
Indeed.


Re: Our scripting fails - Joshua1 - 05.06.2014

Quote:
Originally Posted by grovestreet4life
View Post
Basically, there's a fail everytime I try to script something. Sooner or later lol.
Agreed lmao.