SA-MP Forums Archive
Count is going wrong - 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)
+--- Thread: Count is going wrong (/showthread.php?tid=600157)



Count is going wrong - lulo356 - 04.02.2016

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;




Re: Count is going wrong - StreetRP - 04.02.2016

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


Re: Count is going wrong - Yashas - 04.02.2016

Код:
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.


Re: Count is going wrong - lulo356 - 04.02.2016

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..


Re: Count is going wrong - Marcuse - 04.02.2016

Try new WeedPlants[MAX_PLAYERS][10];


Re: Count is going wrong - lulo356 - 04.02.2016

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


Re: Count is going wrong - Sew_Sumi - 04.02.2016

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.


Re: Count is going wrong - Marcuse - 04.02.2016

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


Re: Count is going wrong - lulo356 - 04.02.2016

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?


Re: Count is going wrong - GangstaSunny - 05.02.2016

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