Chance!
#1

Can someone given me a tutorial for " If there someone wanna rob somthing given him Chance.. Sometimes ROBBING FAILED & sometimes Robbing Completed.
How to I can do it?
Reply
#2

you can use pseudorandom for it.
e.g. let's say you want someone to have 15% chance to be successful in *put action name here*
Код:
new chance = random(100) //Random number (from 0 to 99)
if(chance <= 14) //15% chance of success
{
   ... //Do your actions here upon success
}
else
{
   ... //Do your actions here upon failure
}
Direct SAMP wiki to figure other functions you need out yourself.
Reply
#3

I got an error..

PHP код:
CMD:breakcuff(playeridparams[])
{
     if(
PoliceTeam(GetPlayerSkin(playerid))) return SendClientMessage(playerid, -1"{ff0000}Error: {Ffffff}Only Civilian can use this comamnd.");
     new 
chance random(100)
     if(
chance <= 65)
     {
        
SendClientMessage(playerid, -1"rtr");
     }
     if(
BeginArrested[playerid] == && Civilian(GetPlayerSkin(playerid)))
     {
            
KillTimer(BeginArrestedTime[playerid]);
            
SendClientMessage(playerid, -1"{FF7000}YOU HAVE BEEN ESCAPED FROM ARRESTED!!! RUN RUN !!!!");
            
SetPlayerWantedLevel(playerid3);
            
SetPlayerColor(playeridYELLOW);
            
GameTextForPlayer(playerid"~Y~ESCAPED FROM ~G~ARRESTED ~P~ RUN BABY!!!"70005);
            
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_NONE);
            
BeginArrested[playerid] = 0;
      }else{
            
SendClientMessage(playerid, -1"{FF0000}Error: {FFFFFF}You can use this command only while be cuffed or arrested.");
      }
    return 
1;

Код:
 error 001: expected token: ";", but found "if"
Reply
#4

PHP код:
CMD:breakcuff(playeridparams[])
{
     if(
PoliceTeam(GetPlayerSkin(playerid))) return SendClientMessage(playerid, -1"{ff0000}Error: {Ffffff}Only Civilian can use this comamnd.");
     
//new chance = random(100) <- here is the error
    
new chance random(100);
     if(
chance <= 65)
     {
        
SendClientMessage(playerid, -1"rtr");
     }
     if(
BeginArrested[playerid] == && Civilian(GetPlayerSkin(playerid)))
     {
            
KillTimer(BeginArrestedTime[playerid]);
            
SendClientMessage(playerid, -1"{FF7000}YOU HAVE BEEN ESCAPED FROM ARRESTED!!! RUN RUN !!!!");
            
SetPlayerWantedLevel(playerid3);
            
SetPlayerColor(playeridYELLOW);
            
GameTextForPlayer(playerid"~Y~ESCAPED FROM ~G~ARRESTED ~P~ RUN BABY!!!"70005);
            
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_NONE);
            
BeginArrested[playerid] = 0;
      }else{
            
SendClientMessage(playerid, -1"{FF0000}Error: {FFFFFF}You can use this command only while be cuffed or arrested.");
      }
    return 
1;

Reply
#5

PHP код:
forward GetOuts1(playerid);
public 
GetOuts1(playerid)
{
            
//here code
}

forward GetOuts2(playerid);
public 
GetOuts2(playerid)
{
   
//here code

}

CMD:getouts(playeridparams[])
{
     new 
chance=random(4);
     if(
chance==1)
        {
            
//here code
            
SetTimerEx("GetOuts1"23000"i"playerid);

        }
        else
        {
            
//here code
            
SetTimerEx("GetOuts2"23000"i"playerid);

        }
     return 
1;

Reply
#6

PHP код:
switch(random(100))
{
    case 
0..50:
    {
        
// 50% chance
    
}
    case 
51..80:
    {
        
// 30% chance
    
}
    case 
81..100:
    {
        
// 20% chance
    
}

Reply
#7

Quote:
Originally Posted by kovac
Посмотреть сообщение
PHP код:
switch(random(100))
{
    case 
0..50:
    {
        
// 50% chance
    
}
    case 
51..80:
    {
        
// 30% chance
    
}
    case 
81..100:
    {
        
// 20% chance
    
}

LoL, he want random chance like 1-100 any he didnot said that he want 20% chance 10%chance lol please read the post and then reply it ok, dont reply for increasing your posts, because if you want to increase your posts you must really know scripting, which you can learn from hwe https://sampwiki.blast.hk/
if you want help then you can go for scripting help
Reply
#8

Quote:
Originally Posted by CrystalGamer
Посмотреть сообщение
LoL, he want random chance like 1-100 any he didnot said that he want 20% chance 10%chance lol please read the post and then reply it ok, dont reply for increasing your posts, because if you want to increase your posts you must really know scripting, which you can learn from hwe https://sampwiki.blast.hk/
if you want help then you can go for scripting help
Here comes the smartass. What does my code provide if not a random chance? Modifying it just a little would have given him exactly what he wants. This was just an example and it can learn him something.

What about your code? If you know scripting, can you explain me why are you creating callbacks if you're gonna use it for once? Also, you set the timer to 2,3 seconds which is totally unnecessary and would make it bad. Other than that, you when you're helping, don't be lazy and modify your code to fit his case, it can just confuse.

The final code should look like: (+ some suggestions)
PHP код:
CMD:breakcuff(playerid)
{
    if(
PoliceTeam(GetPlayerSkin(playerid))) return SendClientMessage(playerid, -1"{ff0000}Error: {Ffffff}Only Civilian can use this comamnd.");
    if(
BeginArrested[playerid] == && Civilian(GetPlayerSkin(playerid)))
    {
        switch(
random(100))
        {
            case 
0..35// 35% chance
            
{
                
KillTimer(BeginArrestedTime[playerid]);
                
//SendClientMessage(playerid, -1, "{FF7000}YOU HAVE BEEN ESCAPED FROM ARRESTED!!! RUN RUN !!!!");
                // "-1" is actually the color. You should consider using it as shown below:
                
SendClientMessage(playerid0xFF7000FF"YOU HAVE ESCAPED THE ARREST!!! RUN RUN !!!!");
                
                
SetPlayerWantedLevel(playerid3); // It's better to automatically set player color based on wanted level.
                
SetPlayerColor(playeridYELLOW); // ^^ (READ EXAMPLE 1 BELOW)
                
GameTextForPlayer(playerid"~Y~ESCAPED FROM ~G~ARREST ~P~ RUN BABY!!!"70005);
                
SetPlayerSpecialAction(playeridSPECIAL_ACTION_NONE);
                
BeginArrested[playerid] = 0;
            }
            case 
36..100SendClientMessage(playerid, -1"Failed to break cuffs.");
        }
    }
    else
        
SendClientMessage(playerid, -1"{FF0000}Error: {FFFFFF}You can use this command only while being cuffed or arrested.");
    return 
1;
}
// EXAMPLE 1: (Create a 1 or 2 second timer per player, or better - Hook SetPlayerWantedLevel function. Tutorial: https://sampforum.blast.hk/showthread.ph...1.82554947
new wantedl GetPlayerWantedLevel(playerid);
if(
wantedl == 0SetPlayerColor(playeridCOLOR_WHITE);
else if(
wantedl == 1SetPlayerColor(playeridCOLOR_YELLOW);
else if(
wantedl >= && wantedl 5SetPlayerColor(playeridCOLOR_ORANGE);
else if(
wantedl >= 5SetPlayerColor(playeridCOLOR_RED);
// And for sake of God, change the way you're checking for player team. It's extremely bad. I gave you an example in your previous threads. 
Reply
#9

Use if instead of switch for something like that.
Reply
#10

I'm trying to add message for failed to break but it's given me a error why?

PHP код:
case 36..100SendClientMessage(playerid, -1"Failed to break cuffs.");
            case 
36..100GameTextForPlayer(playerid"~B~HANDCUFFS ~R~FAILED TO BREAK"70005); 
Код HTML:
error 040: duplicate "case" label (value 36)
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)