Raised This Month: $51 Target: $400
 12% 

Solved Randome cmd not working


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
maclarens
Senior Member
Join Date: Jul 2020
Location: Kz
Old 06-12-2023 , 21:22   Randome cmd not working
Reply With Quote #1

can you pls tell me why randome tank give not working , forever give 4 tanks?!


Code:
public void TankBox(int client)
{
    for (int i = 1; i < 5; i++)
    {
        sm_give(client, "z_spawn", "tank auto");
    }
 }


void sm_give(int client, char[] command, char[]="" arguments)
{
if (client)
    {
     int flags = GetCommandFlags(command);
     SetCommandFlags(command, flags & ~FCVAR_CHEAT);
     FakeClientCommand(client, "%s%s", command, arguments);
     SetCommandFlags(command, flags);
    }
}

Last edited by maclarens; 09-16-2023 at 14:08. Reason: more details
maclarens is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 06-12-2023 , 22:10   Re: Randome cmd not working
Reply With Quote #2

what do you mean, really hard to understand
__________________
Marttt is offline
maclarens
Senior Member
Join Date: Jul 2020
Location: Kz
Old 06-12-2023 , 23:25   Re: Randome cmd not working
Reply With Quote #3

Quote:
Originally Posted by Marttt View Post
what do you mean, really hard to understand
random spawning a tank from 1 to 4 but always spawning 4 only..
maclarens is offline
q1085909155
Member
Join Date: Oct 2021
Old 06-13-2023 , 00:57   Re: Randome cmd not working
Reply With Quote #4

I don't quite understand what you mean, but as far as I know, your for loop will execute sm_give four times, so it will generate four tanks.
But you can try this method, I don't know if it works or not, it may be grammatically incorrect because I haven't tried it

Code:
public void TankBox(int client)
{
    for (int i = GetRandomInt(1,4); i < 5; i++)
    {
        sm_give(client, "z_spawn", "tank auto");
    }
 }


void sm_give(int client, char[] command, char[]="" arguments)
{
if (client)
    {
     int flags = GetCommandFlags(command);
     SetCommandFlags(command, flags & ~FCVAR_CHEAT);
     FakeClientCommand(client, "%s%s", command, arguments);
     SetCommandFlags(command, flags);
    }
}
If something goes wrong, plan two

Code:
public void TankBox(int client)
{
    int i = GetRandomInt(1,4);
    for (; i < 5; i++)
    {
        sm_give(client, "z_spawn", "tank auto");
    }
 }


void sm_give(int client, char[] command, char[]="" arguments)
{
if (client)
    {
     int flags = GetCommandFlags(command);
     SetCommandFlags(command, flags & ~FCVAR_CHEAT);
     FakeClientCommand(client, "%s%s", command, arguments);
     SetCommandFlags(command, flags);
    }
}

Last edited by q1085909155; 06-13-2023 at 01:01. Reason: A symbol is missing
q1085909155 is offline
maclarens
Senior Member
Join Date: Jul 2020
Location: Kz
Old 06-13-2023 , 01:38   Re: Randome cmd not working
Reply With Quote #5

q1085909155, Its Great, mate thanks, its working , method 1 and 2! and this exacly what i need ty!solved!

Last edited by maclarens; 06-13-2023 at 01:39.
maclarens is offline
q1085909155
Member
Join Date: Oct 2021
Old 06-13-2023 , 01:39   Re: Randome cmd not working
Reply With Quote #6

Quote:
Originally Posted by maclarens View Post
q1085909155, Its Great, mate thanks, its working , metod 1 and 2! and this exacly what i need ty!solved!
You're welcome buddy, glad to help you with my limited knowledge
q1085909155 is offline
maclarens
Senior Member
Join Date: Jul 2020
Location: Kz
Old 06-13-2023 , 01:50   Re: Randome cmd not working
Reply With Quote #7

Quote:
Originally Posted by q1085909155 View Post
You're welcome buddy, glad to help you with my limited knowledge
maclarens is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:59.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode