[HELP] Spike
#1

I need help with "IsPlayerInRangeOfPoint"

When i im close to a spike, then i can delete it...


pawn Code:
#include <a_samp>

new Spike[MAX_PLAYERS];

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mspike", cmdtext, true, 10) == 0)
    {
        PlaceSpike(playerid); //Places a spike
        SendClientMessage(playerid, 0xFF0000FF, "Spike Placed");
        return 1;
    }
   
    if (strcmp("/rspike", cmdtext, true, 10) == 0)
    {
        if(!IsPlayerInRangeOfPoint(playerid, 1.0, 0, 0, 0)) return SendClientMessage(playerid, 0xFF0000FF, "You is not close to ant spikes");
        {
            RemoveSpike(playerid); //Remove the spike he is close to.
            SendClientMessage(playerid, 0xFF0000FF, "Spike Removed");
            return 1;
        }
    }
   
    if (strcmp("/rallspike", cmdtext, true, 10) == 0)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            RemoveSpike(i); //Removes all spikes
            SendClientMessage(playerid, 0xFF0000FF, "All spikes have been removed");
            return 1;
        }
    }
    return 0;
}

stock PlaceSpike(playerid)
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    Spike[playerid] = CreateObject(1593, X, Y, Z, 0.0, 0.0, 0.0);
    PlayerPlaySound(playerid, 1137, X, Y, Z);
}

stock RemoveSpike(playerid)
{
    Spike[playerid] = DestroyObject(Spike[playerid]);
}
Reply
#2

You'll have to store the position of spike, and then place the stored variables under /rspike in
IsPlayerInRangeOfPoint(playerid, 1.0, X, Y, Z)
Btw Actually you're making a :
if () return firststatement();
{ just a block of code... }
It's kind of equal to
if ()
else { } but better put the else anyway if this syntax hasn't been intended as this.
Reply
#3

Bad mistake, here it is:
Replace your rsike command with this one.
pawn Code:
if(strcmp("/rspike", cmdtext, true, 7) == 0)
{
    if(!IsPlayerInRangeOfPoint(playerid, 1.0, 0, 0, 0)) return SendClientMessage(playerid, 0xFF0000FF, "You is not close to ant spikes");
    RemoveSpike(playerid); //Remove the spike he is close to.
    SendClientMessage(playerid, 0xFF0000FF, "Spike Removed");
    return 1;
}
Reply
#4

Quote:
Originally Posted by EliranPesahov
View Post
Bad mistake, here it is:
Replace your rsike command with this one.
pawn Code:
if(strcmp("/rspike", cmdtext, true, 7) == 0)
{
    if(!IsPlayerInRangeOfPoint(playerid, 1.0, 0, 0, 0)) return SendClientMessage(playerid, 0xFF0000FF, "You is not close to ant spikes");
    RemoveSpike(playerid); //Remove the spike he is close to.
    SendClientMessage(playerid, 0xFF0000FF, "Spike Removed");
    return 1;
}
Nope.. making a block of code isn't a problem, not knowing it may be is. And still you can remove spike only while being in center of map....
Reply
#5

lol, WTF... I haven't noticed that! you DIDN'T configure that x, y, z ...
pawn Code:
if(!IsPlayerInRangeOfPoint(playerid, 1.0, 0, 0, 0)) return SendClientMessage(playerid, 0xFF0000FF, "You is not close to ant spikes");
0, 0, 0 ...
Reply
#6

Quote:
Originally Posted by RSX
View Post
You'll have to store the position of spike, and then place the stored variables under /rspike in
IsPlayerInRangeOfPoint(playerid, 1.0, X, Y, Z)
Btw Actually you're making a :
if () return firststatement();
{ just a block of code... }
It's kind of equal to
if ()
else { } but better put the else anyway if this syntax hasn't been intended as this.
Do you have an example?
Reply
#7

pawn Code:
#include <a_samp>
enum SPIKE_DATA{
    Float:X,Float:Y,Float:Z,ID};
new Spike[MAX_PLAYERS][SPIKE_DATA];

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mspike", cmdtext, true, 10) == 0)
    {
        PlaceSpike(playerid); //Places a spike
        SendClientMessage(playerid, 0xFF0000FF, "Spike Placed");
        return 1;
    }
   
    if (strcmp("/rspike", cmdtext, true, 10) == 0)
    {
        if(!IsPlayerInRangeOfPoint(playerid, 1.0, Spike[playerid][X], Spike[playerid][Y], Spike[playerid][Z])) return SendClientMessage(playerid, 0xFF0000FF, "You is not close to ant spikes");
        else {
            RemoveSpike(playerid); //Remove the spike he is close to.
            SendClientMessage(playerid, 0xFF0000FF, "Spike Removed");
            return 1;
        }
    }
   
    if (strcmp("/rallspike", cmdtext, true, 10) == 0)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            RemoveSpike(i); //Removes all spikes
            SendClientMessage(playerid, 0xFF0000FF, "All spikes have been removed");
            return 1;
        }
    }
    return 0;
}

stock PlaceSpike(playerid)
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    Spike[playerid][ID] = CreateObject(1593, X, Y, Z, 0.0, 0.0, 0.0);
    Spike[playerid][X]=X;Spike[playerid][Y]=Y;Spike[playerid][Z]=Z;
    PlayerPlaySound(playerid, 1137, X, Y, Z);
}

stock RemoveSpike(playerid)
{
    Spike[playerid][ID] = DestroyObject(Spike[playerid]);
}
Reply
#8

RSX that game me a lot of Warnings and a ERROR

pawn Code:
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(39) : warning 219: local variable "X" shadows a variable at a preceding level
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(39) : warning 219: local variable "Y" shadows a variable at a preceding level
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(39) : warning 219: local variable "Z" shadows a variable at a preceding level
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(40) : error 035: argument type mismatch (argument 2)
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(41) : warning 213: tag mismatch
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(41) : warning 213: tag mismatch
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(41) : warning 213: tag mismatch
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(42) : warning 213: tag mismatch
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(42) : warning 213: tag mismatch
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(42) : warning 213: tag mismatch
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(43) : warning 213: tag mismatch
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(43) : warning 213: tag mismatch
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(43) : warning 213: tag mismatch
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(39) : warning 203: symbol is never used: "Z"
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(39) : warning 203: symbol is never used: "Y"
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\Spike.pwn(39) : warning 203: symbol is never used: "X"
Reply
#9

It was an example actually, but OK, I'll code it for you :
PasteBin
Reply
#10

Quote:
Originally Posted by RSX
View Post
It was an example actually, but OK, I'll code it for you :
PasteBin
Thank You, Ill appriciate this
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)