Automatich sprunk - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Automatich sprunk (
/showthread.php?tid=277926)
Automatich sprunk -
wouter0100 - 19.08.2011
Hey,
I have already posted a 'help' thread thats done.
But it dont work now.
i hope somebody can find the 'mistake' (I hope.)
its a include, and you need to set AutomatichSprunk in Onkeystatechange.
Code:
pawn Код:
#include <a_samp>
#if (!defined MAX_SPRUNK)
#error Please define MAX_SPRUNK before including the AutomatichSprunk include.
#endif
#if (!defined SPRUNK_PAY)
#error Please define SPRUNK_PAY before including the AutomatichSprunk include.
#endif
#if (!defined SPRUNK_TEXT)
#error Please define SPRUNK_TEXT before including the AutomatichSprunk include.
#endif
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
#define COLOR_GREY 0xAFAFAFAA
new Sprunk = 0,
Float: X[MAX_SPRUNK],
Float: Y[MAX_SPRUNK],
Float: Z[MAX_SPRUNK],
TookSprunk[MAX_PLAYERS];
stock n_CreateObject(modelid, Float: oX, Float: oY, Float: oZ, Float: orX, Float: orY, Float: orZ, Float: DrawDistance)
{
new id;
id = CreateObject(modelid, oX, oY, oZ, orX, orY, orZ, DrawDistance);
if(modelid == 1546)
{
Sprunk++;
X[Sprunk] = oX;
Y[Sprunk] = oY;
Z[Sprunk] = oZ;
}
return id;
}
stock AutomatichSprunk(playerid, newkeys, oldkeys)
{
if (PRESSED(KEY_SECONDARY_ATTACK))
{
if(IsAtCandySprunk(playerid))
{
if(TookSprunk[playerid] == 0)
{
new Float:health;
GetPlayerHealth(playerid, health);
if(health != 0)
{
GivePlayerMoney(playerid, ( GetPlayerMoney(playerid) - SPRUNK_PAY ) );
new string[60];
format(string, sizeof(string), SPRUNK_TEXT, SPRUNK_PAY);
SendClientMessage(playerid, COLOR_GREY, string);
TookSprunk[playerid] = 1;
SetTimerEx("Heal",3750,false, "i", playerid);
}
}
}
}
return 1;
}
stock Heal(playerid)
{
new Float:Health;
GetPlayerHealth(playerid, Health);
SetPlayerHealth(playerid, (Health + 15));
TookSprunk[playerid] = 0;
}
stock IsAtCandySprunk(playerid)
{
for(new i=0; i < Sprunk; i++){
if(IsPlayerInRangeOfPoint(playerid, 2, X[i], Y[i], Z[i])) return 1;
}
return 0;
}
#define CreateObject n_CreateObject
(No errors)
Thanks,
Wouter0100
Re: Automatich sprunk -
Bakr - 19.08.2011
Your problem persists right here:
pawn Код:
Sprunk++;
X[Sprunk] = oX;
Y[Sprunk] = oY;
Z[Sprunk] = oZ;
// .....
for(new i=0; i < Sprunk; i++){
if(IsPlayerInRangeOfPoint(playerid, 2, X[i], Y[i], Z[i])) return 1;
}
It's a simple missed mistake. You increase the index, then insert the data into the arrays. So you're really inserting the data into index of 1 of the array. Then, in your loop, you check for values only less than Sprunk, which would be only 0. So you'll never get to access the data that you actually need to inside the array.
To fix it, simply increment the index AFTER you insert the data into the array:
pawn Код:
X[Sprunk] = oX;
Y[Sprunk] = oY;
Z[Sprunk] = oZ;
Sprunk++;
Re: Automatich sprunk -
wouter0100 - 20.08.2011
Thanks,
but now, when i press enter (ore F) then nothing happens?
I have this now:
http://pastebin.com/KneM32Lq