Jump to content
MakeWebGames

Hey everyone need help for some reason it’s not adding user stats into my theft have I missed something ?


Recommended Posts

Posted (edited)

    "text" => 'You successfuly stole a '.$carName.' with '.$carDamage.'% damage.'
                    ));
                    $labour = mt_rand(1, 100);
                    foreach ($cars AS $c) {
                        if ($c['C_successText']) {
                            $text = $c['C_successText'];
                        }
                    }
                    if ($labour) {
                        $text .= " And you earned ".number_format($labour)." Quarter Master";
                        $rewards[] = array(
                            'val' => number_format($labour),
                            'name' => 'Quarter Master'
                        );
                    }

Edited by athena26
  • athena26 changed the title to Hey everyone need help for some reason it’s not adding user stats into my theft have I missed something ?
Posted

While I feel it is probably a little too obvious to point out the frankly bleeding obvious, perhaps in this case it is necessary:

 "text" => 'You successfuly stole a '.$carName.' with '.$carDamage.'% damage.'

So that looks like it's setting an element on an associative array, yet you appear to address $text later on. I'd also point out the lack of trailing comma here (not perhaps 100% necessary, however potentially good practice. You could also perhaps use inline variables here, ie "... {$carName} ... {$carDamage} ..." -- both of which will be expanded correctly due to the double-quote. (n.b. ensure both variables are of course correctly escaped).

));

... Closing an array by any chance ? or nested array ? - If so, you probably want to be using the short array syntax these days. - []

$labour = mt_rand(1, 100);

Let's use random_int(1, 100); -- it's a lot better at random number generation even at some ranges, something mt_rand() is pretty poor at.

foreach ($cars AS $c) {

Yeah gods man - use lower case for keywords already!

    if ($c['C_successText']) {
        $text = $c['C_successText'];
    }
}

Let's just gloss of the use of short variable names  .. ( foreach ($cars as $car) would have been a much better choice - even on code this small ). I suspect this could be shortened to .. $text = $c['C_successText'] ?? false .. or similar but where's the code that determines the success?

if ($labour) {

Where does this come from - it's not referenced above.

$text .= " And you earned ".number_format($labour)." Quarter Master";

Okay, so we like mixing single and double quote for no real reason. Stick to single unless you have a replacement variable ( "... {$var} ..." ) - just make sure it is escaped properly!

    $rewards[] = array(
        'val' => number_format($labour),
        'name' => 'Quarter Master'
    );
}

Was $rewards initialized above ? And again, what's with the short array syntax ?

 

I have a nasty feeling this is being edited with a simple editor - maybe sublime text, maybe vscode, maybe notepad, or maybe even rped (before your time I image) - Do yourself a favor and get a copy of PhpStorm, it's free for evaluation purposes for a month iirc, (and can be rolled on forever) - it may help point out potential bugs in your code before having to ask for help or run on a production box - and no doubt upsetting a few regular players.

It would also be useful to see any error messages your system may be throwing up as well as the original file in full (credentials, if present, masked obviously). If you don't feel happy with presenting the whole file - toss us a function or a method - it makes for so much easier debugging and thus swifter turnaround of problems.

 

  • Like 1
  • Thanks 1
Posted (edited)

Im still new to this just because you have 200 years experience doesn’t mean I’m upsetting players in MWG I simply ask for help !

Edited by athena26
Posted (edited)

in the commit section where says they stole car name etc above it make a new query 

$users = $this->db->prepare('UPDATE userStats SET US_labour = US_labour + :a WHERE US_id = :id');
$users->bindParam(':a', $labour);
$users->bindParam(':id', $this->user->id);
$users->execute();

 

Edited by SwiftGameR
  • Like 1
Posted
On 8/4/2024 at 7:05 PM, athena26 said:

Im still new to this just because you have 200 years experience doesn’t mean I’m upsetting players in MWG I simply ask for help !

Sadly not 200 (I little less anyway) - and hopefully not upsetting anybody. I'm just trying to point out that providing limited code snippets without any context or useful error messages is not always the best way to ask for help. By all means - ask away - if I/we can, I'm sure help will be forthcoming.

  • Like 1
Posted

You've literally added nothing useful let's be honest a title and a tiny snippet of code you haven't given any context or anything nobody is being mean its just stating facts 🤷 

Give us abit more meat on the bone and we shall help we cant help if there's no meat on the bone so to speak.

  • Like 1
Posted
On 8/5/2024 at 7:42 PM, Inveteratus said:

Sadly not 200 (I little less anyway) - and hopefully not upsetting anybody. I'm just trying to point out that providing limited code snippets without any context or useful error messages is not always the best way to ask for help. By all means - ask away - if I/we can, I'm sure help will be forthcoming.

I think she misunderstood your answer and thought you meant pissing people off here when i read it i got the impressions everything was written fair no insults given and if you are a developer of any kind and can not take criticism then you should not be coding.  But from what i gathered when i spoke to her on discord she thought you meant mwg members it said in the post game members. 

On 8/5/2024 at 8:02 PM, aventro2 said:

Strongly agree with above, asking good questions with the right details and context is crucial to get the right help. 

Correct plus i already posted the solution to adding the stats to the user once they commit a crime..

On 8/6/2024 at 10:25 AM, big_mike said:

You've literally added nothing useful let's be honest a title and a tiny snippet of code you haven't given any context or anything nobody is being mean its just stating facts 🤷 

Give us abit more meat on the bone and we shall help we cant help if there's no meat on the bone so to speak.

As i just said i gave her the answer she just needs to put it in correct place and fix any column errors i know users stats are a module on its own so was not sure 100% on query details lol but the query alone edited if needed will do as she requesting which is to add $labour rand to users stats table once they have committed a successful steal car.

Posted
10 hours ago, SwiftGameR said:

As i just said i gave her the answer she just needs to put it in correct place and fix any column errors i know users stats are a module on its own so was not sure 100% on query details lol but the query alone edited if needed will do as she requesting which is to add $labour rand to users stats table once they have committed a successful steal car.

I get you gave her the answer but lets be honest the format in which she asked for help didnt help her cause at all.

  • Like 1
Posted
6 hours ago, big_mike said:

I get you gave her the answer but lets be honest the format in which she asked for help didnt help her cause at all.

I agree there was not enough infor for what she was asking her why i tried to throw her in deep in end with some basic knowledge of error reporting and sites to learn to code and always typing your code and from what i have seen she has been making progress and fixing things on herself 

  • Like 1
Posted
5 hours ago, SwiftGameR said:

I agree there was not enough infor for what she was asking her why i tried to throw her in deep in end with some basic knowledge of error reporting and sites to learn to code and always typing your code and from what i have seen she has been making progress and fixing things on herself 

Thats good then maybe in future with issues we might see better structure 🙂

  • Like 1
Posted
On 8/10/2024 at 8:36 PM, big_mike said:

That's good then maybe in future with issues we might see better structure 🙂

We can hope but its MWG 😉 there is always someone who causes trouble haha 😛 

  • Haha 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...