Count is going wrong
#1

I have created an drug system, If you buy seeds you get 10 seeds - Going good,

When you place the seeds your seeds counter raising - Not good...

http://www.upload.ee/image/5539435/sa-mp-011.png

(I've tryed alot of times to fix this in the picture)

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]--;
        
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;

Reply
#2

Don't create the seed objects with the same variable at seed quantity
Reply
#3

Код:
Player[playerid][Seeds] = CreateObject(3409, Weedx[playerid], Weedy[playerid], Weedz[playerid] - 1.3, 0.0, 0.0, Weeda[playerid] + 90);
CreateObject returns the object id, it could be 1000, it could be 500, it could be anything. You must use a separate variable to store the object id.
Reply
#4

Can you guys some examples, Because i tried somting with new Weedplants[MAX_PLAYERS], it worked, But you can only create one weedplant, Not more..
Reply
#5

Try new WeedPlants[MAX_PLAYERS][10];
Reply
#6

Quote:
Originally Posted by Marcuse
Посмотреть сообщение
Try new WeedPlants[MAX_PLAYERS][10];
Can you give me an example,

i got this now..


PHP код:
new Float:Weedx[MAX_PLAYERS], Float:Weedy[MAX_PLAYERS], Float:Weedz[MAX_PLAYERS], FloatWeeda[MAX_PLAYERS];
new 
WeedPlants[MAX_PLAYERS][10];
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]--;
        
GetPlayerFacingAngle(playeridWeeda[playerid]);
        
GetPlayerPos(playeridWeedx[playerid], Weedy[playerid], Weedz[playerid]);
        
WeedPlants[playerid][0] = CreateObject(3409Weedx[playerid], Weedy[playerid], Weedz[playerid] - 1.30.00.0Weeda[playerid] + 90);
        
SavePlayerData(playerid);
    }
    return 
1;
}
command(takeweedplayeridparams[])
{
    
GetObjectPos(WeedPlants[playerid][0],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;
}
forward WeedTimer(playerid);
public 
WeedTimer(playerid)
{
    
Player[playerid][TakeWeed] += 1;
    
SendClientMessage(playeridGREEN"Your weed has finished growing!");
    
SendClientMessage(playeridGREEN"Type /takeweed to take it.");
    return 
1;
}
forward Takingweed(playerid);
public 
Takingweed(playerid)
{
    
DestroyObject(WeedPlants[playerid][0]);
    
SendClientMessage(playeridWHITE"You've taken some weed!");
    
Player[playerid][TakeWeed] --;
    
Player[playerid][Weed] += 5;
    
TogglePlayerControllable(playeridtrue);
    
ClearAnimations(playerid);
    
SavePlayerData(playerid);
    return 
1;

But it still sees as one weed plant
Reply
#7

Damn, stop guessing, and start reading to learn about Arrays.

Jesus... The reason it only puts out one, is that /plantseeds ONLY DOES ONE.

Код:
WeedPlants[playerid][0] = CreateObject(3409, Weedx[playerid], Weedy[playerid], Weedz[playerid] - 1.3, 0.0, 0.0, Weeda[playerid] + 90);
The count isn't going wrong, the error is in you thinking that this code, will do more than what it does.
Reply
#8

You have to check if slot 0 is occupied if so then continue to slot 1 and continue like that
Reply
#9

Quote:
Originally Posted by Marcuse
Посмотреть сообщение
You have to check if slot 0 is occupied if so then continue to slot 1 and continue like that
Can you give me a script example please?
Reply
#10

PHP код:
//This will allow you to change the max weed plants easier if your community is crying because they can only plant 10.
#define MAX_WEED_PLANTS 10
new WeedPlants[MAX_PLAYERS][MAX_WEED_PLANTS];
for(new 
plant 0plant MAX_WEED_PLANTS plant++)
{
    if(
WeedPlants[playerid][plant] == INVALID_OBJECT_ID)return plant;
        
//will return the next free slot

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)