AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] With the user origin (https://forums.alliedmods.net/showthread.php?t=140075)

fiendshard 10-08-2010 19:17

[HELP] With the user origin
 
Hello people, i was wondering if someone may help with this piece of code. It doesn't compile and I am not sure why. Here it is:

Code:

#include <amxmodx>

new light

public plugin_init()
{       
        register_plugin("Storm","1.0","fiend")
        register_clcmd("say /storm", "makestorm");
}

public plugin_precache()
{
        light = precache_model("sprites/lgtning.spr")
}

public makestorm(id)
{
        {
        new xy[2]
        xy[0] = random_num(0,2200)
        xy[1] = random_num(0,2200)
        set_task(0.5,"lightning",1324,xy,10,"a", 60)
        set_task(1.0,"lightning1",1325,xy,10,"a", 60)
        set_task(1.5,"lightning2",1326,xy,10,"a", 60)
        set_task(2.0,"lightning3",1327,xy,10,"a", 60)
        set_task(2.5,"lightning4",1328,xy,10,"a", 60)
        set_task(3.0,"lightning5",1329,xy,10,"a", 60)
        }
        return PLUGIN_HANDLED
}

public lightning(xy[])
{
        xy[0] = random_num(-2000,2200)
        xy[1] = random_num(-2000,2200)
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
        write_byte(0)
        write_coord(xy[0])
        write_coord(xy[1])
        write_coord(4000)
        write_coord(xy[0])
        write_coord(xy[1])
        write_coord(-2000)
        write_short(light)
        write_byte(1) // framestart
        write_byte(5) // framerate
        write_byte(2) // life
        write_byte(200) // width
        write_byte(10) // noise
        write_byte(0) // r, g, b
        write_byte(255) // r, g, b
        write_byte(0) // r, g, b
        write_byte(200) // brightness
        write_byte(200) // 
        message_end()
}

public lightning1(xy[])
{
        xy[0] = random_num(-2000,2200)
        xy[1] = random_num(-2000,2200)
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
        write_byte(0)
        write_coord(xy[0])
        write_coord(xy[1])
        write_coord(4000)
        write_coord(xy[0])
        write_coord(xy[1])
        write_coord(-2000)
        write_short(light)
        write_byte(1) // framestart
        write_byte(5) // framerate
        write_byte(2) // life
        write_byte(200) // width
        write_byte(10) // noise
        write_byte(0) // r, g, b
        write_byte(255) // r, g, b
        write_byte(0) // r, g, b
        write_byte(200) // brightness
        write_byte(200) // 
        message_end()
}

public lightning2(xy[])
{
        xy[0] = random_num(-2000,2200)
        xy[1] = random_num(-2000,2200)
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
        write_byte(0)
        write_coord(xy[0])
        write_coord(xy[1])
        write_coord(4000)
        write_coord(xy[0])
        write_coord(xy[1])
        write_coord(-2000)
        write_short(light)
        write_byte(1) // framestart
        write_byte(5) // framerate
        write_byte(2) // life
        write_byte(200) // width
        write_byte(10) // noise
        write_byte(0) // r, g, b
        write_byte(255) // r, g, b
        write_byte(0) // r, g, b
        write_byte(200) // brightness
        write_byte(200) // 
        message_end()
}

public lightning3(xy[])
{
        xy[0] = random_num(-2000,2200)
        xy[1] = random_num(-2000,2200)
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
        write_byte(0)
        write_coord(xy[0])
        write_coord(xy[1])
        write_coord(4000)
        write_coord(xy[0])
        write_coord(xy[1])
        write_coord(-2000)
        write_short(light)
        write_byte(1) // framestart
        write_byte(5) // framerate
        write_byte(2) // life
        write_byte(200) // width
        write_byte(10) // noise
        write_byte(0) // r, g, b
        write_byte(255) // r, g, b
        write_byte(0) // r, g, b
        write_byte(200) // brightness
        write_byte(200) // 
        message_end()
}

public lightning4(xy[])
{
        xy[0] = random_num(-2000,2200)
        xy[1] = random_num(-2000,2200)
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
        write_byte(0)
        write_coord(xy[0])
        write_coord(xy[1])
        write_coord(4000)
        write_coord(xy[0])
        write_coord(xy[1])
        write_coord(-2000)
        write_short(light)
        write_byte(1) // framestart
        write_byte(5) // framerate
        write_byte(2) // life
        write_byte(200) // width
        write_byte(10) // noise
        write_byte(0) // r, g, b
        write_byte(255) // r, g, b
        write_byte(0) // r, g, b
        write_byte(200) // brightness
        write_byte(200) // 
        message_end()
}

public lightning5(xy[], id)
{
        xy[0] = random_num(-2000,2200)
        xy[1] = random_num(-2000,2200)
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
        write_byte(0)
        write_coord(xy[0])
        write_coord(xy[1])
        write_coord(4000)
        write_coord(xy[0])
        write_coord(xy[1])
        write_coord(-2000)
        write_short(light)
        write_byte(1) // framestart
        write_byte(5) // framerate
        write_byte(2) // life
        write_byte(200) // width
        write_byte(10) // noise
        write_byte(0) // r, g, b
        write_byte(255) // r, g, b
        write_byte(0) // r, g, b
        write_byte(200) // brightness
        write_byte(200) // 
        message_end()
       
        if(get_user_origin(id) ==  (xy[1]))
        user_kill(id)
       
        if(get_user_origin(id) ==  (xy[0]))
        user_kill(id)

}

Problem is with last two chunks of code.

Also would like to ask if it is possible to get user origin when origin is randomized?

Other than this, how can i make action when sprite used in this code collide with player? That would solve the problem.

Thank you

Hunter-Digital 10-08-2010 22:51

Re: [HELP] With the user origin
 
Post the compiling errors because people don't have time to copy and compile your code.

Also, why are you using 5 functions to do the exact thing ?

Oh and I think I saw your problem... get_user_origin(), you need to parse an array to that, you can't compare it directly, see funcwiki for detailed info.

fysiks 10-08-2010 23:10

Re: [HELP] With the user origin
 
This xy variable does NOTHING.

PHP Code:

public makestorm(id)
{
    {
    new 
xy[2]
    
xy[0] = random_num(0,2200)
    
xy[1] = random_num(0,2200

Quote:

Originally Posted by Hunter-Digital (Post 1319628)
Oh and I think I saw your problem... get_user_origin(), you need to parse an array to that, you can't compare it directly, see funcwiki for detailed info.

Yep, that's the one.

fiendshard 10-09-2010 04:46

Re: [HELP] With the user origin
 
Quote:

Originally Posted by fysiks (Post 1319641)
This xy variable does NOTHING.

PHP Code:

public makestorm(id)
{
    {
    new 
xy[2]
    
xy[0] = random_num(0,2200)
    
xy[1] = random_num(0,2200



Yep, that's the one.

Thank you for replies guys. Here are compiling errors:

Code:

Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team

Error: Number of arguments does not match definition on line 190
Error: Number of arguments does not match definition on line 193

2 Errors.

I checked funcwiki and made suggested corrections but no luck so far

fiendshard 10-09-2010 13:16

Re: [HELP] With the user origin
 
All right, I finally realized how to make it compile without errors, but in game i get this:

L 10/09/2010 - 18:58:31: [AMXX] [0] storm.sma::lightning5 (line 24)
L 10/09/2010 - 18:58:31: Invalid player id 0
L 10/09/2010 - 18:58:31: [AMXX] Displaying debug trace (plugin "storm.amxx")
L 10/09/2010 - 18:58:31: [AMXX] Run time error 10: native error (native "get_user_origin")

Here is changed code:

Code:

#include <amxmodx>

new light

public plugin_init()
{       
        register_plugin("Storm","1.0","fiend")
        register_clcmd("say /storm", "makestorm");
}

public plugin_precache()
{
        light = precache_model("sprites/lgtning.spr")
}

public makestorm(id)
{
        {
        set_task(3.0,"lightning5",id,"",0,"a",60)
        }
        return PLUGIN_HANDLED
}

public lightning5(xy[], id)
{
        xy[0] = random_num(-2000,2200)
        xy[1] = random_num(-2000,2200)
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
        write_byte(0)
        write_coord(xy[0])
        write_coord(xy[1])
        write_coord(4000)
        write_coord(xy[0])
        write_coord(xy[1])
        write_coord(-2000)
        write_short(light)
        write_byte(1) // framestart
        write_byte(5) // framerate
        write_byte(2) // life
        write_byte(200) // width
        write_byte(10) // noise
        write_byte(0) // r, g, b
        write_byte(255) // r, g, b
        write_byte(0) // r, g, b
        write_byte(200) // brightness
        write_byte(200) // 
        message_end()
       

        new origin[3];
        get_user_origin(id, origin)
        {
                if((origin[0] = xy[0]) && (origin[1] = xy[1]))
                user_kill(id)
        }       
       

}

What i am doing wrong? it is supposed to kill player when he happens to be at xy[0] and xy[1] location on map at the moment of lightning task (lightning strike)

abdul-rehman 10-09-2010 13:40

Re: [HELP] With the user origin
 
Change this:
Code:
public lightning5(xy[], id)
to
Code:
public lightning5(id)
since xy[] is not passed by the task !!


All times are GMT -4. The time now is 10:21.

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