Near weed?
#1

I don't know how to do this, How can you make on the /takeweed that the player need to be near the weed to harvest it, I maked this but this not working

PHP код:
command(plantseedplayeridparams[])
{
    if(
Player[playerid][Seeds] == 0)
        return 
SendClientMessage(playeridRED"> You don't have any seeds!");
    {
        
SendClientMessage(playeridWHITE"You've planted one seed!");
        
SetTimerEx("WeedTimer"200000"i"playerid);
         
Player[playerid][Seeds] -= 1;
        new 
Float:WeedxFloat:WeedyFloat:WeedzFloat:Weeda;
        
GetPlayerFacingAngle(playeridWeeda);
        
GetPlayerPos(playeridWeedxWeedyWeedz);
        
Player[playerid][Seeds] = CreateObject(3409WeedxWeedyWeedz 1.30.00.0Weeda 90);
        
SavePlayerData(playerid);
    }
    return 
1;
}
command(takeweedplayeridparams[])
{
    new 
Float:WeedxFloat:WeedyFloat:WeedzFloat:Weeda;
    
GetPlayerFacingAngle(playeridWeeda);
    
GetPlayerPos(playeridWeedxWeedyWeedz);
    
    if(
Player[playerid][TakeWeed] == 0)
        return 
SendClientMessage(playeridRED"> You don't have any weed to take!");
    {
        if(
IsPlayerInRangeOfPoint(playerid2WeedxWeedyWeedz))
        {
             if(
GetPlayerWeapon(playerid) == 4)
            {
                
SetTimerEx("Takingweed"200000"i"playerid);
                
TogglePlayerControllable(playeridfalse);
                
ApplyAnimation(playerid"BOMBER","BOM_Plant_Loop",4.0,1,0,1,1,0);
            }
            else
            {
                
SendClientMessage(playeridRED"> You don't have an knife on you!");
            }
        }
        else
        {
            
SendClientMessage(playeridRED"> You are not near your weed!");
        }
    }
    return 
1;

Reply
#2

Go on these coords = 0,0,0 and it should work //Ok my bad, it should work everywhere

For one plant per player do something like this, but GLOBAL
Код HTML:
new Float:Weedx[MAX_PLAYERS], Float:Weedy[MAX_PLAYERS], Float:Weedz[MAX_PLAYERS];
For more plants
Код HTML:
#define MAX_PLANTS 5

new Float:Weedx[MAX_PLAYERS][MAX_PLANTS], Float:Weedy[MAX_PLAYERS][MAX_PLANTS], Float:Weedz[MAX_PLAYERS][MAX_PLANTS];
Reply
#3

Quote:
Originally Posted by Matess
Посмотреть сообщение
Go on these coords = 0,0,0 and it should work

For one plant per player do something like this, but GLOBAL
Код HTML:
new Float:Weedx[MAX_PLAYERS], Float:Weedy[MAX_PLAYERS], Float:Weedz[MAX_PLAYERS];
For more plants
Код HTML:
#define MAX_PLANTS 5

new Float:Weedx[MAX_PLAYERS][MAX_PLANTS], Float:Weedy[MAX_PLAYERS][MAX_PLANTS], Float:Weedz[MAX_PLAYERS][MAX_PLANTS];
Wrong. It won't work if he goes to 0,0,0 coords. Give me a few minutes while I look at your code.

Edit: Are you sure your positions are fine? The object might be underground.
Reply
#4

First define the MAX plants
PHP код:
#define         MAX_PLANTS                  300 
PHP код:
#define         MAX_PLANTS                  Your amount 
PHP код:
    for(new 0MAX_PLANTS; ++i)
    {
        if(
IsValidDynamicObject(Plants[i][pObjectSpawned]) && IsPlayerInRangeOfPoint(playerid2.5Plants[i][pPos][0], Plants[i][pPos][1], Plants[i][pPos][2]))
        {
            if(
GetPlayerVirtualWorld(playerid) == Plants[i][pVirtual] && GetPlayerInterior(playerid) == Plants[i][pInterior])
            { 
Reply
#5

Quote:
Originally Posted by Rufio
Посмотреть сообщение
Wrong. It won't work if he goes to 0,0,0 coords. Give me a few minutes while I look at your code.

Edit: Are you sure your positions are fine? The object might be underground.
The object spawns at your location, Above the ground, So yea its on teh right posistion

Quote:
Originally Posted by TopShooter
Посмотреть сообщение
First define the MAX plants
PHP код:
#define         MAX_PLANTS                  300 
PHP код:
#define         MAX_PLANTS                  Your amount 
PHP код:
    for(new 0MAX_PLANTS; ++i)
    {
        if(
IsValidDynamicObject(Plants[i][pObjectSpawned]) && IsPlayerInRangeOfPoint(playerid2.5Plants[i][pPos][0], Plants[i][pPos][1], Plants[i][pPos][2]))
        {
            if(
GetPlayerVirtualWorld(playerid) == Plants[i][pVirtual] && GetPlayerInterior(playerid) == Plants[i][pInterior])
            { 
Thanks for your help, But i would like to see some explaination, Because it doens't see the plant now that you created right? You defined somting els
Reply
#6

Quote:
Originally Posted by lulo356
Посмотреть сообщение
The object spawns at your location, Above the ground, So yea its on teh right posistion
Then I assume the issue is with taking the weed? Let me take a look again.

The issue is your variables are local and not global, make them global by deleting all of the weedx,weedy etc. and re-write them on top of your script beneath other new variables. Aside of that, you are basically saving a player's position and loading stuff back from the player's position instead of weed's position. If you didn't quite grasp what I mean, I can show you an example.
Reply
#7

Quote:
Originally Posted by Rufio
Посмотреть сообщение
Then I assume the issue is with taking the weed? Let me take a look again.

The issue is your variables are local and not global, make them global by deleting all of the weedx,weedy etc. and re-write them on top of your script beneath other new variables. Aside of that, you are basically saving a player's position and loading stuff back from the player's position instead of weed's position. If you didn't quite grasp what I mean, I can show you an example.
I would love to have an Example
Reply
#8

PHP код:
new Float:Weedx[MAX_PLAYERS], Float:Weedy[MAX_PLAYERS], Float:Weedz[MAX_PLAYERS], FloatWeeda[MAX_PLAYERS];
command(plantseedplayeridparams[])
{
    if(
Player[playerid][Seeds] == 0)
        return 
SendClientMessage(playeridRED"> You don't have any seeds!");
    {
        
SendClientMessage(playeridWHITE"You've planted one seed!");
        
SetTimerEx("WeedTimer"200000"i"playerid);
         
Player[playerid][Seeds] -= 1;
        
GetPlayerFacingAngle(playeridWeeda(playerid));
        
GetPlayerPos(playeridWeedx(playerid), Weedy(playerid), Weedz(playerid));
        
Player[playerid][Seeds] = CreateObject(3409Weedx(playerid), Weedy(playerid), Weedz(playerid) - 1.30.00.0Weeda(playerid) + 90);
        
SavePlayerData(playerid);
    }
    return 
1;
}
command(takeweedplayeridparams[])
{
    
GetObjectPos(Player[playerid][Seeds],Weedx(playerid),Weedy(playerid),Weedz(playerid));
    if(
Player[playerid][TakeWeed] == 0)
        return 
SendClientMessage(playeridRED"> You don't have any weed to take!");
    {
        if(
IsPlayerInRangeOfPoint(playerid2Weedx(playerid), Weedy(playerid), Weedz(playerid)))
        {
             if(
GetPlayerWeapon(playerid) == 4)
            {
                
SetTimerEx("Takingweed"200000"i"playerid);
                
TogglePlayerControllable(playeridfalse);
                
ApplyAnimation(playerid"BOMBER","BOM_Plant_Loop",4.0,1,0,1,1,0);
            }
            else
            {
                
SendClientMessage(playeridRED"> You don't have an knife on you!");
            }
        }
        else
        {
            
SendClientMessage(playeridRED"> You are not near your weed!");
        }
    }
    return 
1;

Please note I didn't test this code out, if you run into any problems please do let me know.
Reply
#9

I'm getting this now:

Quote:

GetPlayerFacingAngle(playerid, Weeda(playerid));

Quote:

C:\Users\Davey\Desktop\DL-RP.pwn(8706) : error 012: invalid function call, not a valid address
C:\Users\Davey\Desktop\DL-RP.pwn(8706) : warning 215: expression has no effect
C:\Users\Davey\Desktop\DL-RP.pwn(8706) : error 001: expected token: ";", but found ")"
C:\Users\Davey\Desktop\DL-RP.pwn(8706) : error 029: invalid expression, assumed zero
C:\Users\Davey\Desktop\DL-RP.pwn(8706) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


4 Errors.

Reply
#10

It is entirely my fault. Sorry, wait a minute while I edit it.

PHP код:
new Float:Weedx[MAX_PLAYERS], Float:Weedy[MAX_PLAYERS], Float:Weedz[MAX_PLAYERS], FloatWeeda[MAX_PLAYERS]; 
command(plantseedplayeridparams[]) 

    if(
Player[playerid][Seeds] == 0
        return 
SendClientMessage(playeridRED"> You don't have any seeds!"); 
    { 
        
SendClientMessage(playeridWHITE"You've planted one seed!"); 
        
SetTimerEx("WeedTimer"200000"i"playerid); 
         
Player[playerid][Seeds] -= 1
        
GetPlayerFacingAngle(playeridWeeda[playerid]); 
        
GetPlayerPos(playeridWeedx[playerid], Weedy[playerid], Weedz[playerid]); 
        
Player[playerid][Seeds] = CreateObject(3409Weedx[playerid], Weedy[playerid], Weedz[playerid] - 1.30.00.0Weeda[playerid] + 90); 
        
SavePlayerData(playerid); 
    } 
    return 
1

command(takeweedplayeridparams[]) 

    
GetObjectPos(Player[playerid][Seeds],Weedx[playerid],Weedy[playerid],Weedz[playerid]); 
    if(
Player[playerid][TakeWeed] == 0
        return 
SendClientMessage(playeridRED"> You don't have any weed to take!"); 
    { 
        if(
IsPlayerInRangeOfPoint(playerid2Weedx[playerid], Weedy[playerid], Weedz[playerid])) 
        { 
             if(
GetPlayerWeapon(playerid) == 4
            { 
                
SetTimerEx("Takingweed"200000"i"playerid); 
                
TogglePlayerControllable(playeridfalse); 
                
ApplyAnimation(playerid"BOMBER","BOM_Plant_Loop",4.0,1,0,1,1,0); 
            } 
            else 
            { 
                
SendClientMessage(playeridRED"> You don't have an knife on you!"); 
            } 
        } 
        else 
        { 
            
SendClientMessage(playeridRED"> You are not near your weed!"); 
        } 
    } 
    return 
1

Try this, it should work. Apologies for the mistake on my behalf, i have been scripting for 5 hours now. I lost a few of my brain cells :/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)